Skip to content

Commit f822416

Browse files
committed
Use DEFAULT_WORKER_EVENT_LOOP_GROUP for both client and server. Fixes grpc#82
+ Use only one thread for the boss eventloop group by default.
1 parent c56cec7 commit f822416

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎netty/src/main/java/io/grpc/transport/netty/NettyChannelBuilder.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ public NettyChannelBuilder sslContext(SslContext sslContext) {
102102
@Override
103103
protected ChannelEssentials buildEssentials() {
104104
final EventLoopGroup group = (userEventLoopGroup == null)
105-
? SharedResourceHolder.get(Utils.DEFAULT_CHANNEL_EVENT_LOOP_GROUP) : userEventLoopGroup;
105+
? SharedResourceHolder.get(Utils.DEFAULT_WORKER_EVENT_LOOP_GROUP) : userEventLoopGroup;
106106
ClientTransportFactory transportFactory = new NettyClientTransportFactory(
107107
serverAddress, negotiationType, group, sslContext);
108108
Runnable terminationRunnable = null;
109109
if (userEventLoopGroup == null) {
110110
terminationRunnable = new Runnable() {
111111
@Override
112112
public void run() {
113-
SharedResourceHolder.release(Utils.DEFAULT_CHANNEL_EVENT_LOOP_GROUP, group);
113+
SharedResourceHolder.release(Utils.DEFAULT_WORKER_EVENT_LOOP_GROUP, group);
114114
}
115115
};
116116
}

‎netty/src/main/java/io/grpc/transport/netty/Utils.java‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,11 @@ class Utils {
6565
public static final AsciiString TE_HEADER = new AsciiString(HttpUtil.TE.name());
6666
public static final AsciiString TE_TRAILERS = new AsciiString(HttpUtil.TE_TRAILERS);
6767

68-
public static final Resource<EventLoopGroup> DEFAULT_CHANNEL_EVENT_LOOP_GROUP =
69-
new DefaultEventLoopGroupResource("grpc-default-channel-ELG");
70-
7168
public static final Resource<EventLoopGroup> DEFAULT_BOSS_EVENT_LOOP_GROUP =
72-
new DefaultEventLoopGroupResource("grpc-default-boss-ELG");
69+
new DefaultEventLoopGroupResource(1, "grpc-default-boss-ELG");
7370

7471
public static final Resource<EventLoopGroup> DEFAULT_WORKER_EVENT_LOOP_GROUP =
75-
new DefaultEventLoopGroupResource("grpc-default-worker-ELG");
72+
new DefaultEventLoopGroupResource(0, "grpc-default-worker-ELG");
7673

7774
/**
7875
* Copies the content of the given {@link ByteBuffer} to a new {@link ByteBuf} instance.
@@ -167,14 +164,16 @@ private static Http2Headers convertMetadata(Metadata headers) {
167164

168165
private static class DefaultEventLoopGroupResource implements Resource<EventLoopGroup> {
169166
private final String name;
167+
private final int nEventLoops;
170168

171-
DefaultEventLoopGroupResource(String name) {
169+
DefaultEventLoopGroupResource(int nEventLoops, String name) {
172170
this.name = name;
171+
this.nEventLoops = nEventLoops;
173172
}
174173

175174
@Override
176175
public EventLoopGroup create() {
177-
return new NioEventLoopGroup(0, new ThreadFactoryBuilder().setNameFormat(name + "-%d")
176+
return new NioEventLoopGroup(nEventLoops, new ThreadFactoryBuilder().setNameFormat(name + "-%d")
178177
.build());
179178
}
180179

0 commit comments

Comments
 (0)