Skip to content

Commit 8fdb4b8

Browse files
committed
Netty Grpc Client should use the Vertx Netty threads
1 parent e1767bb commit 8fdb4b8

File tree

1 file changed

+14
-0
lines changed
  • extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/supports

1 file changed

+14
-0
lines changed

extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/supports/Channels.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import io.grpc.netty.GrpcSslContexts;
4646
import io.grpc.netty.NegotiationType;
4747
import io.grpc.netty.NettyChannelBuilder;
48+
import io.netty.channel.socket.nio.NioSocketChannel;
4849
import io.netty.handler.ssl.SslContext;
4950
import io.netty.handler.ssl.SslContextBuilder;
5051
import io.quarkus.arc.Arc;
@@ -208,6 +209,19 @@ public static Channel createChannel(String name, Set<String> perClientIntercepto
208209

209210
if (builder instanceof NettyChannelBuilder) {
210211
NettyChannelBuilder ncBuilder = (NettyChannelBuilder) builder;
212+
// just use the existing Vertx event loop group, if possible
213+
Vertx vertx = container.instance(Vertx.class).get();
214+
// only support NIO for now, since Vertx::transport is not exposed in the API
215+
if (vertx != null && vertx.isNativeTransportEnabled()) {
216+
// see https://github.com/eclipse-vertx/vert.x/pull/5292
217+
boolean reuseNettyAllocators = Boolean.getBoolean("vertx.reuseNettyAllocators");
218+
if (reuseNettyAllocators) {
219+
// let Netty Grpc to re-use the default Netty allocator as well
220+
System.setProperty("io.grpc.netty.useCustomAllocator", "false");
221+
}
222+
ncBuilder = ncBuilder.eventLoopGroup(vertx.nettyEventLoopGroup())
223+
.channelType(NioSocketChannel.class);
224+
}
211225
builder = ncBuilder
212226
// clients are intercepted using the IOThreadClientInterceptor interceptor which will decide on which
213227
// thread the messages should be processed.

0 commit comments

Comments
 (0)