Пример #1
0
        private async Task RunStreamingPingPongAsync(Channel channel, IInterarrivalTimer timer)
        {
            var client    = new BenchmarkService.BenchmarkServiceClient(channel);
            var request   = CreateSimpleRequest();
            var stopwatch = new Stopwatch();

            using (var call = client.StreamingCall())
            {
                while (!stoppedCts.Token.IsCancellationRequested)
                {
                    stopwatch.Restart();
                    await call.RequestStream.WriteAsync(request);

                    await call.ResponseStream.MoveNext();

                    stopwatch.Stop();

                    // spec requires data point in nanoseconds.
                    threadLocalHistogram.Value.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);

                    await timer.WaitForNextAsync();
                }

                // finish the streaming call
                await call.RequestStream.CompleteAsync();

                Assert.IsFalse(await call.ResponseStream.MoveNext());
            }
        }
Пример #2
0
        private void RunUnary(Channel channel, IInterarrivalTimer timer, BasicProfiler optionalProfiler)
        {
            if (optionalProfiler != null)
            {
                Profilers.SetForCurrentThread(optionalProfiler);
            }

            bool profilerReset = false;

            var client    = new BenchmarkService.BenchmarkServiceClient(channel);
            var request   = CreateSimpleRequest();
            var stopwatch = new Stopwatch();

            while (!stoppedCts.Token.IsCancellationRequested)
            {
                // after the first stats reset, also reset the profiler.
                if (optionalProfiler != null && !profilerReset && statsResetCount.Count > 0)
                {
                    optionalProfiler.Reset();
                    profilerReset = true;
                }

                stopwatch.Restart();
                client.UnaryCall(request);
                stopwatch.Stop();

                // spec requires data point in nanoseconds.
                threadLocalHistogram.Value.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);

                timer.WaitForNext();
            }
        }
Пример #3
0
        private void RunUnary(GrpcChannel channel, IInterarrivalTimer timer)
        {
            var client    = new BenchmarkService.BenchmarkServiceClient(channel);
            var request   = CreateSimpleRequest();
            var stopwatch = new Stopwatch();

            while (!_stoppedCts.Token.IsCancellationRequested)
            {
                stopwatch.Restart();
                client.UnaryCall(request);
                stopwatch.Stop();

                // spec requires data point in nanoseconds.
                _threadLocalHistogram.Value !.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);

                timer.WaitForNext();
            }
        }
Пример #4
0
        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.
                histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);

                await timer.WaitForNextAsync();
            }
        }
Пример #5
0
        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();
            }
        }