Add optional executor to GrpcPlatformServerDefinition - #152
Open
RishabhB99 wants to merge 1 commit into
Open
Conversation
The gRPC network server was always built without calling ServerBuilder.executor(...), so gRPC falls back to its default unbounded cached thread pool to run RPC handlers. Services with blocking handlers (e.g. those making downstream I/O calls) therefore pin one platform thread per concurrent in-flight RPC, with no ceiling, which can exhaust native threads under load. Expose an optional Executor on GrpcPlatformServerDefinition and wire it into the NettyServerBuilder when present. When null (the default), behavior is unchanged, so this is fully backward compatible. Services on JDK 21 can now supply Executors.newVirtualThreadPerTaskExecutor() to decouple handler dispatch from platform-thread count; others can supply a bounded pool for back-pressure. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GrpcPlatformServiceContainer.initializeBuilder(...)builds the network gRPC server but never callsServerBuilder.executor(...). As a result gRPC falls back to its default unbounded cached thread pool to run RPC handlers.For services whose handlers block (e.g. making downstream I/O calls to other services), this means one platform thread is pinned per concurrent in-flight RPC, with no ceiling. Under load this leads to unbounded thread growth and eventually
OutOfMemoryError: unable to create native thread. There is currently no config key, builder field, or overridable hook for a subclass to supply its own server executor.Change
Expose an optional
ExecutoronGrpcPlatformServerDefinitionand wire it into theNettyServerBuilderwhen present:null(the default), no.executor(...)call is made and behavior is identical to today (gRPC's default executor).Executor. The caller chooses the implementation.Motivation / usage
Services on JDK 21 can now supply
Executors.newVirtualThreadPerTaskExecutor()so that blocking handler work no longer pins platform threads (virtual threads unmount during I/O), decoupling live thread count from request concurrency. Services that prefer explicit back-pressure can instead supply a boundedThreadPoolExecutor.Example (subclass overriding
getServerDefinitions()):Testing
./gradlew :platform-grpc-service-framework:compileJava :platform-grpc-service-framework:spotlessJavaCheckpasses. This module has no existing test source set, andinitializeBuilderis private; given the change is a backward-compatible optional pass-through toNettyServerBuilder.executor(...), no test harness was scaffolded. Happy to add one if maintainers prefer.🤖 Generated with Claude Code