Exemple #1
0
        /// <summary>
        /// Creates a started server runner.
        /// </summary>
        public static IServerRunner CreateStarted(ServerConfig config)
        {
            Logger.Debug("ServerConfig: {0}", config);
            var credentials = config.SecurityParams != null?TestCredentials.CreateSslServerCredentials() : ServerCredentials.Insecure;

            if (config.AsyncServerThreads != 0)
            {
                Logger.Warning("ServerConfig.AsyncServerThreads is not supported for C#. Ignoring the value");
            }
            if (config.CoreLimit != 0)
            {
                Logger.Warning("ServerConfig.CoreLimit is not supported for C#. Ignoring the value");
            }
            if (config.CoreList.Count > 0)
            {
                Logger.Warning("ServerConfig.CoreList is not supported for C#. Ignoring the value");
            }

            ServerServiceDefinition service = null;

            if (config.ServerType == ServerType.AsyncServer)
            {
                GrpcPreconditions.CheckArgument(config.PayloadConfig == null,
                                                "ServerConfig.PayloadConfig shouldn't be set for BenchmarkService based server.");
                service = BenchmarkService.BindService(new BenchmarkServiceImpl());
            }
            else if (config.ServerType == ServerType.AsyncGenericServer)
            {
                var genericService = new GenericServiceImpl(config.PayloadConfig.BytebufParams.RespSize);
                service = GenericService.BindHandler(genericService.StreamingCall);
            }
            else
            {
                throw new ArgumentException("Unsupported ServerType");
            }

            var channelOptions = new List <ChannelOption>(config.ChannelArgs.Select((arg) => arg.ToChannelOption()));
            var server         = new Server(channelOptions)
            {
                Services = { service },
                Ports    = { new ServerPort("[::]", config.Port, credentials) }
            };

            server.Start();
            return(new ServerRunnerImpl(server));
        }
Exemple #2
0
        /// <summary>
        /// Creates a started server runner.
        /// </summary>
        public static IServerRunner CreateStarted(ServerConfig config)
        {
            Logger.Debug("ServerConfig: {0}", config);
            var credentials = config.SecurityParams != null ? TestCredentials.CreateSslServerCredentials() : ServerCredentials.Insecure;

            if (config.AsyncServerThreads != 0)
            {
                Logger.Warning("ServerConfig.AsyncServerThreads is not supported for C#. Ignoring the value");
            }
            if (config.CoreLimit != 0)
            {
                Logger.Warning("ServerConfig.CoreLimit is not supported for C#. Ignoring the value");
            }
            if (config.CoreList.Count > 0)
            {
                Logger.Warning("ServerConfig.CoreList is not supported for C#. Ignoring the value");
            }

            ServerServiceDefinition service = null;
            if (config.ServerType == ServerType.ASYNC_SERVER)
            {
                GrpcPreconditions.CheckArgument(config.PayloadConfig == null,
                    "ServerConfig.PayloadConfig shouldn't be set for BenchmarkService based server.");    
                service = BenchmarkService.BindService(new BenchmarkServiceImpl());
            }
            else if (config.ServerType == ServerType.ASYNC_GENERIC_SERVER)
            {
                var genericService = new GenericServiceImpl(config.PayloadConfig.BytebufParams.RespSize);
                service = GenericService.BindHandler(genericService.StreamingCall);
            }
            else
            {
                throw new ArgumentException("Unsupported ServerType");
            }

            var server = new Server
            {
                Services = { service },
                Ports = { new ServerPort("[::]", config.Port, credentials) }
            };

            server.Start();
            return new ServerRunnerImpl(server);
        }
Exemple #3
0
        /// <summary>
        /// Creates a started server runner.
        /// </summary>
        public static IServerRunner CreateStarted(ServerConfig config, ILogger logger)
        {
            logger.LogInformation("ServerConfig: {0}", config);

            var hostBuilder = Host.CreateDefaultBuilder();

            if (config.AsyncServerThreads != 0)
            {
                logger.LogWarning("ServerConfig.AsyncServerThreads is not supported for C#. Ignoring the value");
            }
            if (config.CoreLimit != 0)
            {
                logger.LogWarning("ServerConfig.CoreLimit is not supported for C#. Ignoring the value");
            }
            if (config.CoreList.Count > 0)
            {
                logger.LogWarning("ServerConfig.CoreList is not supported for C#. Ignoring the value");
            }
            if (config.ChannelArgs.Count > 0)
            {
                logger.LogWarning("ServerConfig.ChannelArgs is not supported for C#. Ignoring the value");
            }

            int port = config.Port;

            if (port == 0)
            {
                // TODO(jtattermusch): add support for port autoselection
                port = 50055;
                logger.LogWarning("Grpc.AspNetCore server doesn't support autoselecting of listening port. Setting port explictly to " + port);
            }

            hostBuilder.ConfigureWebHostDefaults(webHostBuilder =>
            {
                webHostBuilder.ConfigureKestrel((context, options) =>
                {
                    options.ListenAnyIP(port, listenOptions =>
                    {
                        // TODO(jtattermusch): use TLS if config.SecurityParams != null
                        listenOptions.Protocols = HttpProtocols.Http2;
                    });
                });

                if (config.ServerType == ServerType.AsyncServer)
                {
                    GrpcPreconditions.CheckArgument(config.PayloadConfig == null,
                                                    "ServerConfig.PayloadConfig shouldn't be set for BenchmarkService based server.");
                    webHostBuilder.UseStartup <BenchmarkServiceStartup>();
                }
                else if (config.ServerType == ServerType.AsyncGenericServer)
                {
                    var genericService = new GenericServiceImpl(config.PayloadConfig.BytebufParams.RespSize);
                    // TODO(jtattermusch): use startup with given generic service
                    throw new ArgumentException("Generice service is not yet implemented.");
                }
                else
                {
                    throw new ArgumentException("Unsupported ServerType");
                }
            });

            // Don't log requests handled by the benchmarking service
            hostBuilder.ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Warning));

            var webHost = hostBuilder.Build();

            webHost.Start();
            return(new ServerRunnerImpl(webHost, logger, port));
        }