コード例 #1
0
        private Task RunClientAsync(Channel channel, IInterarrivalTimer timer, BasicProfiler optionalProfiler)
        {
            if (payloadConfig.PayloadCase == PayloadConfig.PayloadOneofCase.BytebufParams)
            {
                GrpcPreconditions.CheckArgument(clientType == ClientType.AsyncClient, "Generic client only supports async API");
                GrpcPreconditions.CheckArgument(rpcType == RpcType.Streaming, "Generic client only supports streaming calls");
                return(RunGenericStreamingAsync(channel, timer));
            }

            GrpcPreconditions.CheckNotNull(payloadConfig.SimpleParams);
            if (clientType == ClientType.SyncClient)
            {
                GrpcPreconditions.CheckArgument(rpcType == RpcType.Unary, "Sync client can only be used for Unary calls in C#");
                // create a dedicated thread for the synchronous client
                return(Task.Factory.StartNew(() => RunUnary(channel, timer, optionalProfiler), TaskCreationOptions.LongRunning));
            }
            else if (clientType == ClientType.AsyncClient)
            {
                switch (rpcType)
                {
                case RpcType.Unary:
                    return(RunUnaryAsync(channel, timer));

                case RpcType.Streaming:
                    return(RunStreamingPingPongAsync(channel, timer));
                }
            }
            throw new ArgumentException("Unsupported configuration.");
        }
コード例 #2
0
        private static BasicProfiler GetNextProfiler()
        {
            BasicProfiler result = null;

            profilers.TryTake(out result);
            return(result);
        }
コード例 #3
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();
            }
        }
コード例 #4
0
ファイル: PerformanceTest.cs プロジェクト: rakelkar/grpc-1
        public void UnaryCallPerformance()
        {
            var profiler = new BasicProfiler();

            Profilers.SetForCurrentThread(profiler);

            helper.UnaryHandler = new UnaryServerMethod <string, string>(async(request, context) =>
            {
                return(request);
            });

            var callDetails = helper.CreateUnaryCall();

            for (int i = 0; i < 3000; i++)
            {
                Calls.BlockingUnaryCall(callDetails, "ABC");
            }

            profiler.Reset();

            for (int i = 0; i < 3000; i++)
            {
                Calls.BlockingUnaryCall(callDetails, "ABC");
            }
            profiler.Dump("latency_trace_csharp.txt");
        }
コード例 #5
0
 internal static void AddProfiler(BasicProfiler profiler)
 {
     GrpcPreconditions.CheckNotNull(profiler);
     profilers.Add(profiler);
 }