Skip to content

Commit

Permalink
chore: Benchmark show thread diff
Browse files Browse the repository at this point in the history
  • Loading branch information
guitarrapc committed Oct 16, 2024
1 parent 7849341 commit a9200f8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions perf/BenchmarkApp/PerformanceTest.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async Task Main(
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing); // interval
}
}
WriteLog($"All scenario complete...");
WriteLog($"All scenario complete");


WriteLog($"Saving metrics...");
Expand Down Expand Up @@ -170,7 +170,7 @@ async Task Main(
}
}

WriteLog($"Benchmark completed!...");
WriteLog($"Benchmark completed");
}

async Task<PerformanceResult> RunScenarioAsync(ScenarioType scenario, ScenarioConfiguration config, IReadOnlyList<GrpcChannel> channels, IPerfTestControlService controlService)
Expand Down Expand Up @@ -205,8 +205,9 @@ async Task<PerformanceResult> RunScenarioAsync(ScenarioType scenario, ScenarioCo
var ctx = new PerformanceTestRunningContext(connectionCount: config.Channels);
using var cts = new CancellationTokenSource();
var cleanIndex = 0;
var threadBefore = ThreadPool.ThreadCount;

WriteLog($"Starting scenario '{scenario}'...");
WriteLog($"Starting scenario '{scenario}'");
var tasks = new List<Task>();
var scenarios = new List<IScenario>();
for (var i = 0; i < config.Channels; i++)
Expand All @@ -226,8 +227,6 @@ async Task<PerformanceResult> RunScenarioAsync(ScenarioType scenario, ScenarioCo
}
}

WriteLog($"Thread Count Current... {ThreadPool.ThreadCount}");

await controlService.CreateMemoryProfilerSnapshotAsync("Before Warmup");
WriteLog($"Warming up...");
await Task.Delay(TimeSpan.FromSeconds(config.Warmup));
Expand All @@ -239,9 +238,11 @@ async Task<PerformanceResult> RunScenarioAsync(ScenarioType scenario, ScenarioCo
cts.CancelAfter(TimeSpan.FromSeconds(config.Duration));
await Task.WhenAll(tasks);
ctx.Complete();
WriteLog("Completed.");
WriteLog("Completed");
await controlService.CreateMemoryProfilerSnapshotAsync("Completed");

var threadAfter = ThreadPool.ThreadCount;

WriteLog("Cleaning up...");
foreach (var s in scenarios.Chunk(Math.Clamp(scenarios.Count / 3, 1, scenarios.Count)))
{
Expand Down Expand Up @@ -273,7 +274,7 @@ async Task<PerformanceResult> RunScenarioAsync(ScenarioType scenario, ScenarioCo
WriteLog($"Max Memory Usage: {result.hardware.MaxMemoryUsageMB} MB");
WriteLog($"Avg Memory Usage: {result.hardware.AvgMemoryUsageMB} MB");

WriteLog($"Thread Count: {ThreadPool.ThreadCount}");
WriteLog($"Threads (diff): {threadAfter} ({(threadAfter - threadBefore):+#;-#;0})");

return result;
}
Expand Down

0 comments on commit a9200f8

Please sign in to comment.