diff options
author | 2016-05-25 09:23:24 -0400 | |
---|---|---|
committer | 2016-05-25 19:33:56 -0400 | |
commit | 2a84f238af8a7dab55a998e5b0254dbc10914180 (patch) | |
tree | 50de2198239cdd776dd1af4228aa16edc64adb98 /src/csharp/Grpc.Core | |
parent | 5ee8e77522f673611a8cba40ac03a705382ad2b2 (diff) |
expose completionQueueCount setting
Diffstat (limited to 'src/csharp/Grpc.Core')
-rw-r--r-- | src/csharp/Grpc.Core/GrpcEnvironment.cs | 22 |
1 files changed, 21 insertions, 1 deletions
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(); @@ -144,13 +145,32 @@ namespace Grpc.Core } /// <summary> + /// Sets the number of completion queues in the gRPC thread pool that polls for internal RPC events. + /// Can be only invoke before the <c>GrpcEnviroment</c> 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. + /// </summary> + 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; + } + } + + /// <summary> /// Creates gRPC environment. /// </summary> private GrpcEnvironment() { GrpcNativeInit(); completionRegistry = new CompletionRegistry(this); - threadPool = new GrpcThreadPool(this, GetThreadPoolSizeOrDefault(), DefaultCompletionQueueCount); + + var cqCount = customCompletionQueueCount ?? DefaultCompletionQueueCount; + threadPool = new GrpcThreadPool(this, GetThreadPoolSizeOrDefault(), cqCount); threadPool.Start(); } |