Skip to content

Commit

Permalink
chore: benchmark ThreadPool size settings
Browse files Browse the repository at this point in the history
  • Loading branch information
guitarrapc committed Sep 11, 2024
1 parent a13b19f commit c44debc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions perf/BenchmarkApp/PerformanceTest.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ async Task Main(
break;
}

// Setup threadpool
// SetThreads(config.Channels * config.Streams);

// Create a control channel
using var channelControl = config.CreateChannel();
var controlServiceClient = MagicOnionClient.Create<IPerfTestControlService>(channelControl);
Expand Down Expand Up @@ -209,6 +212,8 @@ async Task<PerformanceResult> RunScenarioAsync(ScenarioType scenario, ScenarioCo
}
}

WriteLog($"ThreadCount current: {ThreadPool.ThreadCount}");

await controlService.CreateMemoryProfilerSnapshotAsync("Before Warmup");
WriteLog($"Warming up...");
await Task.Delay(TimeSpan.FromSeconds(config.Warmup));
Expand Down Expand Up @@ -277,6 +282,18 @@ void WriteLog(string value)
Console.WriteLine($"[{DateTime.Now:s}] {value}");
}

void SetThreads(int threadCount)
{
ThreadPool.GetAvailableThreads(out var workerThread, out var ioCompletionPortThreads);
var count = Math.Min(150, Math.Max(ThreadPool.ThreadCount, threadCount)); // (ThreadPool.ThreadCount < threadCount) <= n <= 150
WriteLog($"ThreadCount before: {ThreadPool.ThreadCount}, tobe: {count}");
if (!ThreadPool.SetMinThreads(count, ioCompletionPortThreads))
{
WriteLog("Settings thread failed.");
}
WriteLog($"ThreadCount after: {ThreadPool.ThreadCount}, available workerthreads: {workerThread}");
}

IEnumerable<ScenarioType> GetRunScenarios(ScenarioType scenario)
{
return scenario switch
Expand Down

0 comments on commit c44debc

Please sign in to comment.