Exemplo n.º 1
0
        static void TestSequentialReusingGrpcChannel()
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new Greeter.GreeterClient(channel);

            Console.WriteLine($"{DateTime.Now} - Starting {nameof(TestSequentialReusingGrpcChannel)} {TotalRequests} requests");

            var stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < TotalRequests; i++)
            {
                if (LogDetails)
                {
                    Console.WriteLine($"{DateTime.Now} - Start request {i}");
                }
                var reply = client.GetTime(new Empty());
                if (LogDetails)
                {
                    Console.WriteLine($"{DateTime.Now} - End request {i}: {reply}");
                }
            }
            stopwatch.Stop();

            Console.WriteLine($"{DateTime.Now} - {nameof(TestSequentialReusingGrpcChannel)} for {TotalRequests} requests took: {stopwatch.ElapsedMilliseconds}ms");
        }
Exemplo n.º 2
0
        static void TestConcurrent()
        {
            if (LogDetails)
            {
                Console.WriteLine($"{DateTime.Now} - Starting {nameof(TestConcurrent)} {TotalRequests} requests");
            }

            var stopwatch = Stopwatch.StartNew();

            Parallel.For(0, TotalRequests, parallelOptions, (i) =>
            {
                if (LogDetails)
                {
                    Console.WriteLine($"{DateTime.Now} - Start request {i}");
                }
                var stopwatchRequest = Stopwatch.StartNew();
                using var channel    = GrpcChannel.ForAddress("https://localhost:5001");
                var client           = new Greeter.GreeterClient(channel);
                var result           = client.GetTime(new Empty());
                stopwatchRequest.Stop();
                CaptureMetrics(stopwatchRequest);
                if (LogDetails)
                {
                    Console.WriteLine($"{DateTime.Now} - End request {i}: {result}");
                }
            });
            stopwatch.Stop();

            if (LogDetails)
            {
                Console.WriteLine($"{DateTime.Now} - {nameof(TestConcurrent)} for {TotalRequests} requests took: {stopwatch.ElapsedMilliseconds}ms");
            }

            WriteTableRow(nameof(TestConcurrent), stopwatch);
        }
Exemplo n.º 3
0
        static void Warmup()
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new Greeter.GreeterClient(channel);
            var reply  = client.GetTime(new Empty());

            Console.WriteLine("Warmup done");
        }
Exemplo n.º 4
0
        static void TestSequential()
        {
            ClearMinMax();
            if (LogDetails)
            {
                Console.WriteLine($"{DateTime.Now} - Starting {nameof(TestSequential)} {TotalRequests} requests");
            }

            var stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < TotalRequests; i++)
            {
                if (LogDetails)
                {
                    Console.WriteLine($"{DateTime.Now} - Start request {i}");
                }
                var stopwatchRequest = Stopwatch.StartNew();
                using var channel = GrpcChannel.ForAddress("https://localhost:5001");
                var client = new Greeter.GreeterClient(channel);
                var result = client.GetTime(new Empty());
                stopwatchRequest.Stop();
                CaptureMetrics(stopwatchRequest);
                if (LogDetails)
                {
                    Console.WriteLine($"{DateTime.Now} - End request {i}: {result}");
                }
            }
            stopwatch.Stop();

            if (LogDetails)
            {
                Console.WriteLine($"{DateTime.Now} - {nameof(TestSequential)} for {TotalRequests} requests took: {stopwatch.ElapsedMilliseconds}ms");
            }

            WriteTableRow(nameof(TestSequential), stopwatch);
        }