Jan Tattermusch | 452ca9b | 2015-10-29 10:38:03 -0700 | [diff] [blame] | 1 | #region Copyright notice and license |
| 2 | |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | // Copyright 2015 gRPC authors. |
Jan Tattermusch | 452ca9b | 2015-10-29 10:38:03 -0700 | [diff] [blame] | 4 | // |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Jan Tattermusch | 452ca9b | 2015-10-29 10:38:03 -0700 | [diff] [blame] | 8 | // |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
Jan Tattermusch | 452ca9b | 2015-10-29 10:38:03 -0700 | [diff] [blame] | 10 | // |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Jan Tattermusch | 452ca9b | 2015-10-29 10:38:03 -0700 | [diff] [blame] | 16 | |
| 17 | #endregion |
| 18 | |
| 19 | using System; |
| 20 | using System.Diagnostics; |
| 21 | using System.Linq; |
| 22 | using System.Threading; |
| 23 | using System.Threading.Tasks; |
| 24 | using Grpc.Core; |
| 25 | using Grpc.Core.Internal; |
| 26 | using Grpc.Core.Profiling; |
| 27 | using Grpc.Core.Utils; |
| 28 | using NUnit.Framework; |
| 29 | |
| 30 | namespace Grpc.Core.Tests |
| 31 | { |
| 32 | public class PerformanceTest |
| 33 | { |
| 34 | const string Host = "127.0.0.1"; |
| 35 | |
| 36 | MockServiceHelper helper; |
| 37 | Server server; |
| 38 | Channel channel; |
| 39 | |
| 40 | [SetUp] |
| 41 | public void Init() |
| 42 | { |
| 43 | helper = new MockServiceHelper(Host); |
| 44 | server = helper.GetServer(); |
| 45 | server.Start(); |
| 46 | channel = helper.GetChannel(); |
| 47 | } |
| 48 | |
| 49 | [TearDown] |
| 50 | public void Cleanup() |
| 51 | { |
| 52 | channel.ShutdownAsync().Wait(); |
| 53 | server.ShutdownAsync().Wait(); |
| 54 | } |
Jan Tattermusch | 3ac274f | 2015-12-11 15:27:58 -0800 | [diff] [blame] | 55 | |
| 56 | [Test] |
| 57 | [Category("Performance")] |
| 58 | [Ignore("Prevent running on Jenkins")] |
Jan Tattermusch | 452ca9b | 2015-10-29 10:38:03 -0700 | [diff] [blame] | 59 | public void UnaryCallPerformance() |
| 60 | { |
| 61 | var profiler = new BasicProfiler(); |
| 62 | Profilers.SetForCurrentThread(profiler); |
| 63 | |
Jan Tattermusch | 2fb313c | 2017-08-09 09:41:25 +0200 | [diff] [blame] | 64 | helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) => |
Jan Tattermusch | 452ca9b | 2015-10-29 10:38:03 -0700 | [diff] [blame] | 65 | { |
Jan Tattermusch | 2fb313c | 2017-08-09 09:41:25 +0200 | [diff] [blame] | 66 | return Task.FromResult(request); |
Jan Tattermusch | 452ca9b | 2015-10-29 10:38:03 -0700 | [diff] [blame] | 67 | }); |
| 68 | |
| 69 | var callDetails = helper.CreateUnaryCall(); |
| 70 | for(int i = 0; i < 3000; i++) |
| 71 | { |
| 72 | Calls.BlockingUnaryCall(callDetails, "ABC"); |
| 73 | } |
| 74 | |
| 75 | profiler.Reset(); |
| 76 | |
| 77 | for(int i = 0; i < 3000; i++) |
| 78 | { |
| 79 | Calls.BlockingUnaryCall(callDetails, "ABC"); |
| 80 | } |
| 81 | profiler.Dump("latency_trace_csharp.txt"); |
| 82 | } |
| 83 | } |
| 84 | } |