blob: 3dd91b794851b325523ec544599fa5331a202300 [file] [log] [blame]
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -07001#region Copyright notice and license
2
3// Copyright 2015, Google Inc.
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
9//
10// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above
13// copyright notice, this list of conditions and the following disclaimer
14// in the documentation and/or other materials provided with the
15// distribution.
16// * Neither the name of Google Inc. nor the names of its
17// contributors may be used to endorse or promote products derived from
18// this software without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#endregion
33
34using System;
35using System.Collections.Generic;
36using System.Linq;
37using System.Threading;
38using System.Threading.Tasks;
39using Grpc.Core;
40using Grpc.Core.Utils;
41using Grpc.Testing;
42using NUnit.Framework;
43
44namespace Grpc.IntegrationTesting
45{
46 /// <summary>
47 /// Runs performance tests in-process.
48 /// </summary>
49 public class RunnerClientServerTest
50 {
51 const string Host = "localhost";
52 IServerRunner serverRunner;
53
54 [TestFixtureSetUp]
55 public void Init()
56 {
57 var serverConfig = new ServerConfig
58 {
59 ServerType = ServerType.ASYNC_SERVER,
Jan Tattermusch18ce9d62015-11-18 15:41:10 -080060 Host = Host,
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070061 PayloadConfig = new PayloadConfig
62 {
63 SimpleParams = new SimpleProtoParams
64 {
65 RespSize = 100
66 }
67 }
68 };
69 serverRunner = ServerRunners.CreateStarted(serverConfig);
70 }
71
72 [TestFixtureTearDown]
73 public void Cleanup()
74 {
75 serverRunner.StopAsync().Wait();
76 }
77
Jan Tattermusch3ac274f2015-12-11 15:27:58 -080078
79 [Test]
80 [Category("Performance")]
81 [Ignore("Prevent running on Jenkins")]
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070082 public async Task ClientServerRunner()
83 {
84 var config = new ClientConfig
85 {
86 ServerTargets = { string.Format("{0}:{1}", Host, serverRunner.BoundPort) },
87 RpcType = RpcType.UNARY,
88 LoadParams = new LoadParams { ClosedLoop = new ClosedLoopParams() },
89 PayloadConfig = new PayloadConfig
90 {
91 SimpleParams = new SimpleProtoParams
92 {
93 ReqSize = 100
94 }
Jan Tattermusch18ce9d62015-11-18 15:41:10 -080095 },
96 HistogramParams = new HistogramParams
97 {
98 Resolution = 0.01,
99 MaxPossible = 60e9
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -0700100 }
101 };
102
103 var runner = ClientRunners.CreateStarted(config);
104
105 System.Console.WriteLine("Warming up");
106 await Task.Delay(3000);
107 runner.GetStats(true); // throw away warm-up data
108
109 System.Console.WriteLine("Benchmarking");
110 await Task.Delay(3000);
111 var stats = runner.GetStats(true);
112 await runner.StopAsync();
113
114 System.Console.WriteLine(stats);
Jan Tattermusch18ce9d62015-11-18 15:41:10 -0800115 System.Console.WriteLine("avg micros/call " + (long) (stats.Latencies.Sum / stats.Latencies.Count / 1000.0));
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -0700116 }
117 }
118}