blob: a579fb80406d4eccaafb78cae258e0a347c89c95 [file] [log] [blame]
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -07001#region Copyright notice and license
2
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003// Copyright 2015 gRPC authors.
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -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 Tattermuschd0c1bfa2015-10-22 19:14:57 -07008//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009// http://www.apache.org/licenses/LICENSE-2.0
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -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 Tattermuschd0c1bfa2015-10-22 19:14:57 -070016
17#endregion
18
19using System;
20using System.Collections.Generic;
21using System.Diagnostics;
22using System.IO;
23using System.Linq;
24using System.Text.RegularExpressions;
25using System.Threading.Tasks;
26
27using CommandLine;
28using CommandLine.Text;
29using Grpc.Core;
Jan Tattermusch66f85782017-02-24 19:44:16 +010030using Grpc.Core.Logging;
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070031using Grpc.Core.Utils;
32using Grpc.Testing;
33using NUnit.Framework;
34
35namespace Grpc.IntegrationTesting
36{
37 public class QpsWorker
38 {
39 private class ServerOptions
40 {
Jan Tattermusch678ec902016-08-08 12:54:16 +080041 [Option("driver_port", Default = 0)]
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070042 public int DriverPort { get; set; }
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070043 }
44
45 ServerOptions options;
46
47 private QpsWorker(ServerOptions options)
48 {
49 this.options = options;
50 }
51
52 public static void Run(string[] args)
53 {
Jan Tattermusch66f85782017-02-24 19:44:16 +010054 GrpcEnvironment.SetLogger(new ConsoleLogger());
Jan Tattermusch90cbde82016-08-08 14:33:28 +080055 var parserResult = Parser.Default.ParseArguments<ServerOptions>(args)
56 .WithNotParsed((x) => Environment.Exit(1))
57 .WithParsed(options =>
58 {
59 var workerServer = new QpsWorker(options);
60 workerServer.RunAsync().Wait();
61 });
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070062 }
63
Jan Tattermusch1cbb5672016-02-18 14:27:28 -080064 private async Task RunAsync()
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070065 {
66 string host = "0.0.0.0";
67 int port = options.DriverPort;
68
Jan Tattermusch1cbb5672016-02-18 14:27:28 -080069 var tcs = new TaskCompletionSource<object>();
70 var workerServiceImpl = new WorkerServiceImpl(() => { Task.Run(() => tcs.SetResult(null)); });
71
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070072 var server = new Server
73 {
Jan Tattermusch1cbb5672016-02-18 14:27:28 -080074 Services = { WorkerService.BindService(workerServiceImpl) },
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070075 Ports = { new ServerPort(host, options.DriverPort, ServerCredentials.Insecure )}
76 };
77 int boundPort = server.Ports.Single().BoundPort;
Jan Tattermusch01ce2362017-04-25 20:53:51 +020078 GrpcEnvironment.Logger.Info("Running qps worker server on {0}:{1}", host, boundPort);
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070079 server.Start();
Jan Tattermusch1cbb5672016-02-18 14:27:28 -080080 await tcs.Task;
81 await server.ShutdownAsync();
Jan Tattermusch01ce2362017-04-25 20:53:51 +020082
Jan Tattermusch8251fdd2017-06-01 19:26:12 +020083 GrpcEnvironment.Logger.Info("GC collection counts (after shutdown): gen0 {0}, gen1 {1}, gen2 {2}",
84 GC.CollectionCount(0), GC.CollectionCount(1), GC.CollectionCount(2));
Jan Tattermuschd0c1bfa2015-10-22 19:14:57 -070085 }
86 }
87}