Jan Tattermusch | d0c1bfa | 2015-10-22 19:14:57 -0700 | [diff] [blame] | 1 | #region Copyright notice and license |
| 2 | |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | // Copyright 2015, Google Inc. |
Jan Tattermusch | d0c1bfa | 2015-10-22 19:14:57 -0700 | [diff] [blame] | 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 | |
| 34 | using System; |
| 35 | using System.Collections.Generic; |
| 36 | using System.Linq; |
| 37 | using System.Threading; |
| 38 | using System.Threading.Tasks; |
| 39 | using Grpc.Core; |
| 40 | using Grpc.Core.Utils; |
| 41 | using Grpc.Testing; |
| 42 | using NUnit.Framework; |
| 43 | |
| 44 | namespace Grpc.IntegrationTesting |
| 45 | { |
| 46 | /// <summary> |
| 47 | /// Runs performance tests in-process. |
| 48 | /// </summary> |
| 49 | public class RunnerClientServerTest |
| 50 | { |
Jan Tattermusch | d0c1bfa | 2015-10-22 19:14:57 -0700 | [diff] [blame] | 51 | IServerRunner serverRunner; |
| 52 | |
| 53 | [TestFixtureSetUp] |
| 54 | public void Init() |
| 55 | { |
| 56 | var serverConfig = new ServerConfig |
| 57 | { |
Jan Tattermusch | 87ba294 | 2016-05-16 17:18:00 -0700 | [diff] [blame] | 58 | ServerType = ServerType.AsyncServer |
Jan Tattermusch | d0c1bfa | 2015-10-22 19:14:57 -0700 | [diff] [blame] | 59 | }; |
| 60 | serverRunner = ServerRunners.CreateStarted(serverConfig); |
| 61 | } |
| 62 | |
| 63 | [TestFixtureTearDown] |
| 64 | public void Cleanup() |
| 65 | { |
| 66 | serverRunner.StopAsync().Wait(); |
| 67 | } |
| 68 | |
Jan Tattermusch | 3ac274f | 2015-12-11 15:27:58 -0800 | [diff] [blame] | 69 | |
| 70 | [Test] |
| 71 | [Category("Performance")] |
| 72 | [Ignore("Prevent running on Jenkins")] |
Jan Tattermusch | d0c1bfa | 2015-10-22 19:14:57 -0700 | [diff] [blame] | 73 | public async Task ClientServerRunner() |
| 74 | { |
| 75 | var config = new ClientConfig |
| 76 | { |
Jan Tattermusch | 1cbb567 | 2016-02-18 14:27:28 -0800 | [diff] [blame] | 77 | ServerTargets = { string.Format("{0}:{1}", "localhost", serverRunner.BoundPort) }, |
Jan Tattermusch | 87ba294 | 2016-05-16 17:18:00 -0700 | [diff] [blame] | 78 | RpcType = RpcType.Unary, |
Jan Tattermusch | d0c1bfa | 2015-10-22 19:14:57 -0700 | [diff] [blame] | 79 | LoadParams = new LoadParams { ClosedLoop = new ClosedLoopParams() }, |
| 80 | PayloadConfig = new PayloadConfig |
| 81 | { |
| 82 | SimpleParams = new SimpleProtoParams |
| 83 | { |
Jan Tattermusch | 4214052 | 2016-03-25 17:13:24 -0700 | [diff] [blame] | 84 | ReqSize = 100, |
| 85 | RespSize = 100 |
Jan Tattermusch | d0c1bfa | 2015-10-22 19:14:57 -0700 | [diff] [blame] | 86 | } |
Jan Tattermusch | 18ce9d6 | 2015-11-18 15:41:10 -0800 | [diff] [blame] | 87 | }, |
| 88 | HistogramParams = new HistogramParams |
| 89 | { |
| 90 | Resolution = 0.01, |
| 91 | MaxPossible = 60e9 |
Jan Tattermusch | d0c1bfa | 2015-10-22 19:14:57 -0700 | [diff] [blame] | 92 | } |
| 93 | }; |
| 94 | |
| 95 | var runner = ClientRunners.CreateStarted(config); |
| 96 | |
| 97 | System.Console.WriteLine("Warming up"); |
| 98 | await Task.Delay(3000); |
| 99 | runner.GetStats(true); // throw away warm-up data |
| 100 | |
| 101 | System.Console.WriteLine("Benchmarking"); |
| 102 | await Task.Delay(3000); |
| 103 | var stats = runner.GetStats(true); |
| 104 | await runner.StopAsync(); |
| 105 | |
| 106 | System.Console.WriteLine(stats); |
Jan Tattermusch | 18ce9d6 | 2015-11-18 15:41:10 -0800 | [diff] [blame] | 107 | System.Console.WriteLine("avg micros/call " + (long) (stats.Latencies.Sum / stats.Latencies.Count / 1000.0)); |
Jan Tattermusch | d0c1bfa | 2015-10-22 19:14:57 -0700 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | } |