blob: 4b1d745284a2d4fe672f91bada67ec33f4a10780 [file] [log] [blame]
Jan Tattermusch452ca9b2015-10-29 10:38:03 -07001#region Copyright notice and license
2
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003// Copyright 2015 gRPC authors.
Jan Tattermusch452ca9b2015-10-29 10:38:03 -07004//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005// 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 Tattermusch452ca9b2015-10-29 10:38:03 -07008//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009// http://www.apache.org/licenses/LICENSE-2.0
Jan Tattermusch452ca9b2015-10-29 10:38:03 -070010//
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011// 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 Tattermusch452ca9b2015-10-29 10:38:03 -070016
17#endregion
18
19using System;
20using System.Diagnostics;
21using System.Linq;
22using System.Threading;
23using System.Threading.Tasks;
24using Grpc.Core;
25using Grpc.Core.Internal;
26using Grpc.Core.Profiling;
27using Grpc.Core.Utils;
28using NUnit.Framework;
29
30namespace 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 Tattermusch3ac274f2015-12-11 15:27:58 -080055
56 [Test]
57 [Category("Performance")]
58 [Ignore("Prevent running on Jenkins")]
Jan Tattermusch452ca9b2015-10-29 10:38:03 -070059 public void UnaryCallPerformance()
60 {
61 var profiler = new BasicProfiler();
62 Profilers.SetForCurrentThread(profiler);
63
Jan Tattermusch2fb313c2017-08-09 09:41:25 +020064 helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) =>
Jan Tattermusch452ca9b2015-10-29 10:38:03 -070065 {
Jan Tattermusch2fb313c2017-08-09 09:41:25 +020066 return Task.FromResult(request);
Jan Tattermusch452ca9b2015-10-29 10:38:03 -070067 });
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}