public static double FuncForOptimization(double[] optVals = null) { TestConfiguration config = new TestConfiguration() { PoolQueueSize = 1000, PoolThreadCount = 32, TaskCount = 50000, ActiveTaskAvgTime = TimeSpan.Zero, PassiveTaskAvgTime = TimeSpan.FromMilliseconds(1), SpawnThreadCount = 4, SpawnPeriod = TimeSpan.Zero, SpawnFromPool = false, UseDeviance = false }; TestConfiguration config2 = new TestConfiguration() { PoolQueueSize = -1, PoolThreadCount = 2, TaskCount = 50000, ActiveTaskAvgTime = TimeSpan.FromMilliseconds(1), PassiveTaskAvgTime = TimeSpan.Zero, SpawnThreadCount = 8, SpawnPeriod = TimeSpan.Zero, SpawnFromPool = false, UseDeviance = false }; TestConfiguration config3 = new TestConfiguration() { PoolQueueSize = -1, PoolThreadCount = 2, TaskCount = 50000, ActiveTaskAvgTime = TimeSpan.FromMilliseconds(1), PassiveTaskAvgTime = TimeSpan.FromMilliseconds(1), SpawnThreadCount = 8, SpawnPeriod = TimeSpan.Zero, SpawnFromPool = false, UseDeviance = false }; if (optVals != null) { //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.OptimalStateTime = (int)optVals[0]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.OptimalStateAverageCaptureLocalFluctuationDiffCoef = optVals[1]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.OptimalStateFluctuationDiffCoef = optVals[2]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.FindBestDirectionSuggestIncreaseDiff = optVals[3]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.FindBestDirectionSuggestDecreaseDiff = optVals[4]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.IncreaseDirectionLocGoodDiff = optVals[5]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.IncreaseDirectionAvgGoodDiff = optVals[6]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.IncreaseDirectionLocDropDiff = optVals[7]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.IncreaseDirectionAvgDropDiff = optVals[8]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.DecreaseDirectionLocDropDiff = optVals[9]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.DecreaseDirectionAvgDropDiff = optVals[10]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.DecreaseDirectionLocFluctuationNearBaselineCoef = optVals[11]; //Qoollo.Turbo.Threading.ThreadPools.ServiceStuff.ExecutionThroughoutTrackerUpDownCorrection.DecreaseDirectionAvgFluctuationNearBaselineCoef = optVals[12]; } double[] measures = new double[5]; for (int measureId = 0; measureId < measures.Length; measureId++) { Stopwatch sw = Stopwatch.StartNew(); Qoollo.Turbo.Threading.ThreadPools.DynamicThreadPool.DisableCritical = true; Qoollo.Turbo.Threading.ThreadPools.DynamicThreadPool pool = new Threading.ThreadPools.DynamicThreadPool(0, 80, 2000, "name"); for (int i = 0; i < 2; i++) { RunOnDynamicThreadPoolNew(config, pool, true); RunOnDynamicThreadPoolNew(config3, pool, true); RunOnDynamicThreadPoolNew(config2, pool, true); RunOnDynamicThreadPoolNew(config3, pool, true); } pool.Dispose(true, true, false); sw.Stop(); measures[measureId] = sw.ElapsedMilliseconds / 1000; } Array.Sort(measures); double elapsed = measures.Skip(1).Take(measures.Length - 2).Average(); string printString = "ELAPSED = " + elapsed.ToString("0.00") + "s"; if (optVals != null) { printString += ", values = ["; for (int i = 0; i < optVals.Length; i++) { printString += (optVals[i].ToString() + ", "); } printString += "]"; } Console.WriteLine(printString); Console.WriteLine(); return((int)elapsed); }
public static void RunCompareTest() { TestConfiguration config = new TestConfiguration() { PoolQueueSize = 1000, PoolThreadCount = 32, TaskCount = 100000, ActiveTaskAvgTime = TimeSpan.Zero, PassiveTaskAvgTime = TimeSpan.FromMilliseconds(1), SpawnThreadCount = 4, SpawnPeriod = TimeSpan.Zero, SpawnFromPool = false, UseDeviance = false }; TestConfiguration config2 = new TestConfiguration() { PoolQueueSize = -1, PoolThreadCount = 2, TaskCount = 100000, ActiveTaskAvgTime = TimeSpan.FromMilliseconds(1), //TimeSpan.FromMilliseconds(1), PassiveTaskAvgTime = TimeSpan.Zero, SpawnThreadCount = 8, SpawnPeriod = TimeSpan.Zero, //TimeSpan.FromMilliseconds(1), SpawnFromPool = false, UseDeviance = false }; TestConfiguration config3 = new TestConfiguration() { PoolQueueSize = -1, PoolThreadCount = 2, TaskCount = 100000, ActiveTaskAvgTime = TimeSpan.FromMilliseconds(1), PassiveTaskAvgTime = TimeSpan.FromMilliseconds(1), SpawnThreadCount = 8, SpawnPeriod = TimeSpan.Zero, SpawnFromPool = false, UseDeviance = false }; //RunOnSystemThreadPool(config2); //RunOnStaticThreadPool(config2); //RunOnDynamicThreadPool(config); //Console.WriteLine(); //RunOnSystemThreadPoolNew(config); //for (int i = 0; i < 3; i++) //RunOnStaticThreadPoolNew(config2); //config2.PoolQueueSize = -1; //RunOnStaticThreadPoolNew(config2); Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < 2; i++) { RunOnSystemThreadPoolNew(config); RunOnSystemThreadPoolNew(config3); RunOnSystemThreadPoolNew(config2); RunOnSystemThreadPoolNew(config3); } sw.Stop(); Console.WriteLine("================="); Console.WriteLine("!!!!!!!!!!!!!!!!!!SYSTEM = " + sw.Elapsed.ToString()); Console.WriteLine("================="); Console.WriteLine(); //Qoollo.Turbo.Threading.ThreadPools.StaticThreadPool staticPool = new Threading.ThreadPools.StaticThreadPool(Environment.ProcessorCount, 4000, "name"); //sw = Stopwatch.StartNew(); //for (int i = 0; i < 2; i++) //{ // RunOnStaticThreadPoolNew(config, staticPool, true); // RunOnStaticThreadPoolNew(config3, staticPool, true); // RunOnStaticThreadPoolNew(config2, staticPool, true); // RunOnStaticThreadPoolNew(config3, staticPool, true); //} //staticPool.Dispose(true, true, false); //sw.Stop(); //Console.WriteLine("================="); //Console.WriteLine("!!!!!!!!!!!!!!!!!!STATIC = " + sw.Elapsed.ToString()); //Console.WriteLine("================="); //Console.WriteLine(); Qoollo.Turbo.Threading.ThreadPools.DynamicThreadPool pool = new Threading.ThreadPools.DynamicThreadPool(0, 128, 10000, "name"); sw = Stopwatch.StartNew(); for (int i = 0; i < 2; i++) { //RunOnDynamicThreadPoolNew(config, pool); //RunOnDynamicThreadPoolNew(config, pool); //RunOnDynamicThreadPoolNew(config2, pool); RunOnDynamicThreadPoolNew(config, pool, true); RunOnDynamicThreadPoolNew(config3, pool, true); RunOnDynamicThreadPoolNew(config2, pool, true); RunOnDynamicThreadPoolNew(config3, pool, true); } pool.Dispose(true, true, false); sw.Stop(); Console.WriteLine("================="); Console.WriteLine("!!!!!!!!!!!!!!!!!!DYNAMIC = " + sw.Elapsed.ToString()); Console.WriteLine("================="); Console.WriteLine(); }