private static void RunMultithreaded( RamDriverTest test, int numThreads, int firstId, int countPerInterval, Action <RamDriverTest, int, object> threadAction) { Action <object> action = fid => { RamDriverTest.SetThreadContext((int)fid); for (var i = 0; i < 1; i++) { threadAction(test, countPerInterval, fid); } }; var threads = new Task[numThreads]; for (var i = 0; i < threads.Length; i++) { threads[i] = new Task(action, firstId + i * countPerInterval, TaskCreationOptions.LongRunning); } var timer = Stopwatch.StartNew(); for (var i = 0; i < threads.Length; i++) { threads[i].Start(); } for (var i = 0; i < threads.Length; i++) { try { threads[i].Wait(); } catch (Exception e) { Console.WriteLine(e); } } timer.Stop(); Console.WriteLine("Elapsed ms: {0,3}, rps: {1,3}", timer.ElapsedMilliseconds, countPerInterval * threads.Length * 1000.0 / timer.ElapsedMilliseconds); //RamDriverTest.TestServiceContainer.StorageDriver.WriteDescriptor(RamDriverTest.TestServiceContainer.StorageDriver.GetDescriptor()); //RamDriverTest.TestServiceContainer.StorageDriver.FlushDataToStore(); }
private static void PerformanceTest() { var test = new RamDriverTest(); try { test.InitializeEmbeddedServer(); // warm-up RunMultithreaded(test, 8, 1, 10, TestThreadAction); Console.WriteLine("Press ENTER to start"); Console.ReadLine(); // now go RamDriverTest.SetThreadContext(-1); var count = 100000; var numThreads = 8; for (var i = 0; i < 5; i++) { test.DeleteRange(100000000, -1); RunMultithreaded(test, numThreads, 1, count, TestThreadAction); ShowCount(test); } test.DeleteRange(1000, 1000); ShowCount(test); } finally { test.TestShutdown(); } Console.WriteLine("Press ENTER to run full GC"); Console.ReadLine(); GC.Collect(2, GCCollectionMode.Forced, true); GC.Collect(2, GCCollectionMode.Forced, true); GC.Collect(2, GCCollectionMode.Forced, true); Console.WriteLine("Press ENTER to exit"); Console.ReadLine(); }