コード例 #1
0
        private async Task RunStreamingPingPongAsync(Channel channel, IInterarrivalTimer timer)
        {
            var client    = BenchmarkService.NewClient(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.
                    histogram.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    = BenchmarkService.NewClient(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.
                histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);

                timer.WaitForNext();
            }
        }
コード例 #3
0
        public SyncUnaryClientRunner(Channel channel, int payloadSize, HistogramParams histogramParams)
        {
            this.channel     = Grpc.Core.Utils.Preconditions.CheckNotNull(channel);
            this.payloadSize = payloadSize;
            this.histogram   = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible);

            this.stoppedCts = new CancellationTokenSource();
            this.client     = BenchmarkService.NewClient(channel);
            this.runnerTask = Task.Factory.StartNew(Run, TaskCreationOptions.LongRunning);
        }
コード例 #4
0
        private void RunUnary(Channel channel, IInterarrivalTimer timer)
        {
            var client    = BenchmarkService.NewClient(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.
                histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);

                timer.WaitForNext();
            }
        }