public class GrpcEnvironment : object
Encapsulates initialization and shutdown of gRPC library.
Namespace
Grpc.CoreAssembly
Grpc.Core.dll
Properties
Logger
public static ILogger Logger { get; }
Gets application-wide logger used by gRPC.
Type | Description |
---|---|
ILogger | The logger. |
Methods
KillServersAsync()
public static Task KillServersAsync()
Requests immediate shutdown of all servers created by the current process.
Type | Description |
---|---|
Task |
SetBatchContextPoolParams(Int32, Int32)
public static void SetBatchContextPoolParams(int sharedCapacity, int threadLocalCapacity)
Sets the parameters for a pool that caches batch context instances. Reusing batch context instances
instead of creating a new one for every C core operation helps reducing the GC pressure.
Can be only invoked before the GrpcEnviroment
is started and cannot be changed afterwards.
This 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.
Type | Name | Description |
---|---|---|
Int32 | sharedCapacity | |
Int32 | threadLocalCapacity |
SetCompletionQueueCount(Int32)
public static void SetCompletionQueueCount(int completionQueueCount)
Sets the number of completion queues in the gRPC thread pool that polls for internal RPC events.
Can be only invoked 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.
Type | Name | Description |
---|---|---|
Int32 | completionQueueCount |
SetHandlerInlining(Boolean)
public static void SetHandlerInlining(bool inlineHandlers)
By default, gRPC's internal event handlers get offloaded to .NET default thread pool thread (inlineHandlers=false
).
Setting inlineHandlers
to true
will allow scheduling the event handlers directly to
GrpcThreadPool
internal threads. That can lead to significant performance gains in some situations,
but requires user to never block in async code (incorrectly written code can easily lead to deadlocks).
Inlining handlers 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.
Note: inlineHandlers=true
was the default in gRPC C# v1.4.x and earlier.
Type | Name | Description |
---|---|---|
Boolean | inlineHandlers |
SetLogger(ILogger)
public static void SetLogger(ILogger customLogger)
Sets the application-wide logger that should be used by gRPC.
Type | Name | Description |
---|---|---|
ILogger | customLogger |
SetRequestCallContextPoolParams(Int32, Int32)
public static void SetRequestCallContextPoolParams(int sharedCapacity, int threadLocalCapacity)
Sets the parameters for a pool that caches request call context instances. Reusing request call context instances
instead of creating a new one for every requested call in C core helps reducing the GC pressure.
Can be only invoked before the GrpcEnviroment
is started and cannot be changed afterwards.
This 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.
Type | Name | Description |
---|---|---|
Int32 | sharedCapacity | |
Int32 | threadLocalCapacity |
SetThreadPoolSize(Int32)
public static void SetThreadPoolSize(int threadCount)
Sets the number of threads in the gRPC thread pool that polls for internal RPC events.
Can be only invoked before the GrpcEnviroment
is started and cannot be changed afterwards.
Setting thread pool size 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.
Type | Name | Description |
---|---|---|
Int32 | threadCount |
ShutdownChannelsAsync()
public static Task ShutdownChannelsAsync()
Requests shutdown of all channels created by the current process.
Type | Description |
---|---|
Task |
Events
ShuttingDown
public static event EventHandler ShuttingDown
Occurs when GrpcEnvironment
is about the start the shutdown logic.
If GrpcEnvironment
is later initialized and shutdown, the event will be fired again (unless unregistered first).
Type | Description |
---|---|
EventHandler |