using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using Sog; using Sog.Log; namespace MysqlHandling { class Program { static void Main(string[] args) { AppTime.InitTimeZone(); var apptime = new AppTime(); apptime.UpdateTime(); string path = "../cfg/config.json"; // windows vs调试时, 可以传入cfg路径, 必须是第一个 if (args.Length > 0) { path = args[0]; } var tmp = new Config(path); string logPath = "../log"; string logName = "testLog"; TraceLog.SetLogPathName(logPath, logName); // 关闭ServerApp中的TraceLog, 避免IO影响 TraceLog.SetLogLevel(Config.m_DBConfig.traceLogLevel); EasyLog.CreatLogFile(logPath, "perform.log"); EasyLog.WriteInfo("========================= test start ========================="); // 固定10个线程, 测试程序简单点 int threadNum = 10; int testCountPerThread = Config.m_DBConfig.testCount / threadNum; GamePlayerManager[] mgrList = new GamePlayerManager[threadNum]; Task[] taskList = new Task[threadNum]; for (int i = 0; i < threadNum; i++) { mgrList[i] = new GamePlayerManager(testCountPerThread, 1, i + 1); taskList[i] = new Task(mgrList[i].TestAll); } try { for (int i = 0; i < threadNum; i++) { taskList[i].Start(); } Task.WaitAll(taskList); long insert = 0, get = 0, update = 0, delete = 0; for (int i = 0; i < threadNum; i++) { insert += mgrList[i].m_insertMs; get += mgrList[i].m_getMs; update += mgrList[i].m_updteMs; delete += mgrList[i].m_deleteMs; } insert /= threadNum; get /= threadNum; update /= threadNum; delete /= threadNum; string db = Config.m_DBConfig.dbtype == 0 ? "mysql" : "mongo"; EasyLog.WriteInfo($"{db} thread {threadNum} avg testCount {testCountPerThread} insert {insert} get {get} update {update} delete {delete}"); } catch (Exception ex) { Console.WriteLine(ex); } } } }