1 #region Copyright notice and license 2 3 // Copyright 2015 gRPC authors. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 #endregion 18 19 using System; 20 using System.Collections.Generic; 21 using System.Linq; 22 using System.Threading; 23 using System.Threading.Tasks; 24 using Grpc.Core; 25 using Grpc.Core.Utils; 26 using Grpc.Testing; 27 using NUnit.Framework; 28 29 namespace Grpc.IntegrationTesting 30 { 31 /// <summary> 32 /// Runs performance tests in-process. 33 /// </summary> 34 public class RunnerClientServerTest 35 { 36 IServerRunner serverRunner; 37 38 [OneTimeSetUp] Init()39 public void Init() 40 { 41 var serverConfig = new ServerConfig 42 { 43 ServerType = ServerType.AsyncServer 44 }; 45 serverRunner = ServerRunners.CreateStarted(serverConfig); 46 } 47 48 [OneTimeTearDown] Cleanup()49 public void Cleanup() 50 { 51 serverRunner.StopAsync().Wait(); 52 } 53 54 55 [Test] 56 [Category("Performance")] 57 [Ignore("Prevent running on Jenkins")] ClientServerRunner()58 public async Task ClientServerRunner() 59 { 60 var config = new ClientConfig 61 { 62 ServerTargets = { string.Format("{0}:{1}", "localhost", serverRunner.BoundPort) }, 63 RpcType = RpcType.Unary, 64 LoadParams = new LoadParams { ClosedLoop = new ClosedLoopParams() }, 65 PayloadConfig = new PayloadConfig 66 { 67 SimpleParams = new SimpleProtoParams 68 { 69 ReqSize = 100, 70 RespSize = 100 71 } 72 }, 73 HistogramParams = new HistogramParams 74 { 75 Resolution = 0.01, 76 MaxPossible = 60e9 77 } 78 }; 79 80 var runner = ClientRunners.CreateStarted(config); 81 82 System.Console.WriteLine("Warming up"); 83 await Task.Delay(3000); 84 runner.GetStats(true); // throw away warm-up data 85 86 System.Console.WriteLine("Benchmarking"); 87 await Task.Delay(3000); 88 var stats = runner.GetStats(true); 89 await runner.StopAsync(); 90 91 System.Console.WriteLine(stats); 92 System.Console.WriteLine("avg micros/call " + (long) (stats.Latencies.Sum / stats.Latencies.Count / 1000.0)); 93 } 94 } 95 } 96