private static void RunAction(Func <string, Task> action, string title) { int count = 0; Console.WriteLine("========================="); var result = _redisClient4.FlushDBAsync().Result; Console.WriteLine($"Clear DB 0 - [{(result?"SUCCEED":"FAILED")}]!"); if (_useDelay) { Thread.Sleep(_delayCount); } var tasks = new Task[frequence]; Stopwatch sw = new Stopwatch(); sw.Start(); for (var a = 0; a < frequence; a += 1) { tasks[a] = action(a.ToString()); } Task.WaitAll(tasks); sw.Stop(); for (var a = 0; a < frequence; a += 1) { var key = a.ToString(); tasks[a] = Task.Run(() => { var result = _stackExnchangeClient.StringGet(key); if (result != key) { Interlocked.Increment(ref count); } }); } Task.WaitAll(tasks); Console.Write($"{title} (0-{frequence / 10000}W) : {sw.ElapsedMilliseconds}ms! "); Console.WriteLine($"Errors : {count} !"); if (count > 0) { Thread.Sleep(1000); for (var a = 0; a < frequence; a += 1) { var key = a.ToString(); tasks[a] = Task.Run(() => { var result = _stackExnchangeClient.StringGet(key); if (result != key) { Interlocked.Increment(ref count); } }); } Task.WaitAll(tasks); Console.WriteLine($"Rechecking Errors : {count} !"); } Console.WriteLine("=========================\r\n"); }
//#region RedisTest private static void RunSE() { if (_useDelay) { Thread.Sleep(_delayCount); } int count = 0; Console.WriteLine("========================="); var result = _redisClient4.FlushDBAsync().Result; Console.WriteLine($"Clear DB 0 - [{(result?"SUCCEED":"FAILED")}]!"); var tasks = new Task[frequence]; Stopwatch sw = new Stopwatch(); //_beforeSw?.Invoke(title); Console.WriteLine("Start Run:"); //Thread.Sleep(0); //Thread.Sleep(1000); sw.Start(); Parallel.For(0, frequence, _options, (index) => { var key = index.ToString(); tasks[index] = _stackExnchangeClient.StringSetAsync(key, key); }); int offset = 0; SpinWait wait = default; while (offset != frequence - 1) { for (int i = offset; i < frequence; i++) { if (tasks[i].IsCompleted) { offset = i; } else { break; } } wait.SpinOnce(); } sw.Stop(); //var checkTasks = new Task[frequence]; //for (var a = 0; a < frequence; a += 1) //{ // var key = a.ToString(); // checkTasks[a] = Task.Run(() => // { // var result = _stackExnchangeClient.StringGet(key); // if (result != key) // { // Interlocked.Increment(ref count); // } // }); //} //Task.WaitAll(checkTasks); //Console.WriteLine($"{title} (0-{frequence / 10000}W) : {sw.ElapsedTicks} SPAN! "); Console.WriteLine($"SE (0-{frequence / 10000}W) : {sw.ElapsedMilliseconds}ms! "); //Console.WriteLine($"Errors : {count} !"); //if (count>0) //{ // Thread.Sleep(1000); // for (var a = 0; a < frequence; a += 1) // { // var key = a.ToString(); // tasks[a] = Task.Run(() => // { // var result = _stackExnchangeClient.StringGet(key); // if (result != key) // { // Interlocked.Increment(ref count); // } // }); // } // Task.WaitAll(tasks); // Console.WriteLine($"Rechecking Errors : {count} !"); //} Console.WriteLine("=========================\r\n"); }