• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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]
Init()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]
Cleanup()50         public void Cleanup()
51         {
52             channel.ShutdownAsync().Wait();
53             server.ShutdownAsync().Wait();
54         }
55 
56         [Test]
57         [Category("Performance")]
58         [Ignore("Prevent running on Jenkins")]
UnaryCallPerformance()59         public void UnaryCallPerformance()
60         {
61             var profiler = new BasicProfiler();
62             Profilers.SetForCurrentThread(profiler);
63 
64             helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) =>
65             {
66                 return Task.FromResult(request);
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 }
85