diff --git a/perf/BenchmarkApp/PerformanceTest.Client/PerformanceTestRunningContext.cs b/perf/BenchmarkApp/PerformanceTest.Client/PerformanceTestRunningContext.cs index dcd0f1674..baa9eaf6e 100644 --- a/perf/BenchmarkApp/PerformanceTest.Client/PerformanceTestRunningContext.cs +++ b/perf/BenchmarkApp/PerformanceTest.Client/PerformanceTestRunningContext.cs @@ -5,12 +5,14 @@ public class PerformanceTestRunningContext int count; bool isRunning; Stopwatch stopwatch; - List> latencyPerConnection = []; - List locks = []; + List> latencyPerConnection; + List locks; public PerformanceTestRunningContext(int connectionCount) { stopwatch = new Stopwatch(); + latencyPerConnection = new (connectionCount); + locks = new (connectionCount); for (var i = 0; i < connectionCount; i++) { latencyPerConnection.Add([]); @@ -49,6 +51,8 @@ public void Complete() public PerformanceResult GetResult() { var latency = MeasureLatency(); + latencyPerConnection.Clear(); + locks.Clear(); return new PerformanceResult(count, count / (double)stopwatch.Elapsed.TotalSeconds, stopwatch.Elapsed, latency); Latency MeasureLatency() @@ -66,7 +70,7 @@ Latency MeasureLatency() latencyPerConnection[i].Sort(); } var latencyMean = (totalCount != 0) ? totalSum / totalCount : totalSum; - var latencyAllConnection = new List(); + var latencyAllConnection = new List(totalCount); foreach (var connections in latencyPerConnection) latencyAllConnection.AddRange(connections); var latency50p = GetPercentile(50, latencyAllConnection); var latency75p = GetPercentile(75, latencyAllConnection); diff --git a/perf/BenchmarkApp/PerformanceTest.Client/Program.cs b/perf/BenchmarkApp/PerformanceTest.Client/Program.cs index 1607b8066..574a74de1 100644 --- a/perf/BenchmarkApp/PerformanceTest.Client/Program.cs +++ b/perf/BenchmarkApp/PerformanceTest.Client/Program.cs @@ -79,7 +79,7 @@ async Task Main( } var result = await RunScenarioAsync(scenario2, config, controlServiceClient); results.Add(result); - datadog.PutClientBenchmarkMetrics(scenario.ToString(), ApplicationInformation.Current, serialization.ToString(), result); + await datadog.PutClientBenchmarkMetricsAsync(scenario.ToString(), ApplicationInformation.Current, serialization.ToString(), result); } } @@ -136,8 +136,6 @@ async Task Main( writer.WriteLine($"{s}\t{string.Join("\t", results.Select(x => x.RequestsPerSecond.ToString("0.000")))}\t{results.Average(x => x.RequestsPerSecond):0.000}"); } } - - await datadog.WaitSaveAsync(); } async Task RunScenarioAsync(ScenarioType scenario, ScenarioConfiguration config, IPerfTestControlService controlService) @@ -265,7 +263,7 @@ public static class DatadogMetricsRecorderExtensions /// /// /// - public static void PutClientBenchmarkMetrics(this DatadogMetricsRecorder recorder, string scenario, ApplicationInformation applicationInfo, string serialization, PerformanceResult result) + public static async Task PutClientBenchmarkMetricsAsync(this DatadogMetricsRecorder recorder, string scenario, ApplicationInformation applicationInfo, string serialization, PerformanceResult result) { var tags = MetricsTagCache.Get((scenario, applicationInfo, serialization), static x => [$"app:MagicOnion", $"magiconion_version:{x.applicationInfo.MagicOnionVersion}", $"grpcdotnet_version:{x.applicationInfo.GrpcNetVersion}", $"messagepack_version:{x.applicationInfo.MessagePackVersion}", $"memorypack_version:{x.applicationInfo.MemoryPackVersion}", $"process_arch:{x.applicationInfo.ProcessArchitecture}", $"process_count:{x.applicationInfo.ProcessorCount}", $"scenario:{x.scenario}", $"serialization:{x.serialization}"]); @@ -279,6 +277,9 @@ public static void PutClientBenchmarkMetrics(this DatadogMetricsRecorder recorde recorder.Record(recorder.SendAsync("benchmark.client.latency_p75", result.Latency.P75, DatadogMetricsType.Gauge, tags, "millisecond")); recorder.Record(recorder.SendAsync("benchmark.client.latency_p90", result.Latency.P90, DatadogMetricsType.Gauge, tags, "millisecond")); recorder.Record(recorder.SendAsync("benchmark.client.latency_p99", result.Latency.P99, DatadogMetricsType.Gauge, tags, "millisecond")); + + // wait until send complete + await recorder.WaitSaveAsync(); } } diff --git a/perf/BenchmarkApp/PerformanceTest.Client/StreamingHubScenario.cs b/perf/BenchmarkApp/PerformanceTest.Client/StreamingHubScenario.cs index 7b3670a18..dab7fc91e 100644 --- a/perf/BenchmarkApp/PerformanceTest.Client/StreamingHubScenario.cs +++ b/perf/BenchmarkApp/PerformanceTest.Client/StreamingHubScenario.cs @@ -6,21 +6,20 @@ public class StreamingHubScenario : IScenario, IPerfTestHubReceiver { IPerfTestHub client = default!; readonly TimeProvider timeProvider = TimeProvider.System; - long beginTimeStamp = default; public async ValueTask PrepareAsync(GrpcChannel channel) { this.client = await StreamingHubClient.ConnectAsync(channel, this); - this.beginTimeStamp = timeProvider.GetTimestamp(); } public async ValueTask RunAsync(int connectionId, PerformanceTestRunningContext ctx, CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { + var begin = timeProvider.GetTimestamp(); await client.CallMethodAsync("FooBarBaz🚀こんにちは世界", 123, 4567, 891011); ctx.Increment(); - ctx.Latency(connectionId, timeProvider.GetElapsedTime(this.beginTimeStamp)); + ctx.Latency(connectionId, timeProvider.GetElapsedTime(begin)); } } }