From 2a84f238af8a7dab55a998e5b0254dbc10914180 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 25 May 2016 09:23:24 -0400 Subject: expose completionQueueCount setting --- src/csharp/Grpc.Core/GrpcEnvironment.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/csharp/Grpc.Core') diff --git a/src/csharp/Grpc.Core/GrpcEnvironment.cs b/src/csharp/Grpc.Core/GrpcEnvironment.cs index 2851587567..acc7b21436 100644 --- a/src/csharp/Grpc.Core/GrpcEnvironment.cs +++ b/src/csharp/Grpc.Core/GrpcEnvironment.cs @@ -53,6 +53,7 @@ namespace Grpc.Core static GrpcEnvironment instance; static int refCount; static int? customThreadPoolSize; + static int? customCompletionQueueCount; static ILogger logger = new ConsoleLogger(); @@ -143,6 +144,23 @@ namespace Grpc.Core } } + /// + /// Sets the number of completion queues in the gRPC thread pool that polls for internal RPC events. + /// Can be only invoke before the GrpcEnviroment is started and cannot be changed afterwards. + /// Setting the number of completions queues is an advanced setting and you should only use it if you know what you are doing. + /// Most users should rely on the default value provided by gRPC library. + /// Note: this method is part of an experimental API that can change or be removed without any prior notice. + /// + public static void SetCompletionQueueCount(int completionQueueCount) + { + lock (staticLock) + { + GrpcPreconditions.CheckState(instance == null, "Can only be set before GrpcEnvironment is initialized"); + GrpcPreconditions.CheckArgument(completionQueueCount > 0, "threadCount needs to be a positive number"); + customCompletionQueueCount = completionQueueCount; + } + } + /// /// Creates gRPC environment. /// @@ -150,7 +168,9 @@ namespace Grpc.Core { GrpcNativeInit(); completionRegistry = new CompletionRegistry(this); - threadPool = new GrpcThreadPool(this, GetThreadPoolSizeOrDefault(), DefaultCompletionQueueCount); + + var cqCount = customCompletionQueueCount ?? DefaultCompletionQueueCount; + threadPool = new GrpcThreadPool(this, GetThreadPoolSizeOrDefault(), cqCount); threadPool.Start(); } -- cgit v1.2.3