private async Task RunUnaryAsync(Channel channel, IInterarrivalTimer timer) { var client = new BenchmarkService.BenchmarkServiceClient(channel); var request = CreateSimpleRequest(); var stopwatch = new Stopwatch(); while (!stoppedCts.Token.IsCancellationRequested) { stopwatch.Restart(); await client.UnaryCallAsync(request); stopwatch.Stop(); // spec requires data point in nanoseconds. threadLocalHistogram.Value.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos); await timer.WaitForNextAsync(); } }
public static async Task Main(string[] args) { // For local measurements, use a stopwatch and make a // request from the app itself to get an approximate // measurement. if (args.Contains("--time")) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); using (var host = CreateHostBuilder(args).Start()) { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); var channel = GrpcChannel.ForAddress("http://localhost:5000"); var client = new BenchmarkService.BenchmarkServiceClient(channel); var request = new SimpleRequest { Payload = new Payload { Body = ByteString.CopyFrom(new byte[0]) }, ResponseSize = 0 }; _ = await client.UnaryCallAsync(request); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Console.WriteLine("Stopwatch startup measurement: " + ts.Milliseconds); } return; } else { var host = CreateHostBuilder(args).Build(); host.Run(); } }