core-java icon indicating copy to clipboard operation
core-java copied to clipboard

The in-process gRPC `Client` defaults to a direct executor

Open yuri-sergiichuk opened this issue 3 years ago • 0 comments

If one uses the in-process gRPC Client e.g. like this:

Client.inProcess("Server Name").build()

The client is automatically created with a direct executor which is usually a bad choice in production environments. The reason for that is our in-process client setup:

private Builder(String processServerName) {
    this(channelForTesting(processServerName));
}

private static ManagedChannel channelForTesting(String serverName) {
    ManagedChannel result = InProcessChannelBuilder
            .forName(serverName)
            .directExecutor()
            .build();
    return result;
}

Without the directExecutor() call, the default executor is going to be a shard thread pool executor which a much better choice for non-test environments.

Workaround:

One may create a client with her own InProcessChannel and configure the executor manually:

ManagedChannel channel = InProcessChannelBuilder
        .forName(SERVER_NAME)
        .executor(<Some Executor>)
        .build();
return Client
        .usingChannel(channel)
        .build();

yuri-sergiichuk avatar Jul 19 '21 10:07 yuri-sergiichuk