Skip to content

Commit 3e9bd1b

Browse files
committed
worker threads: make sure default max size is 32 fix #916
1 parent 6bb3d4c commit 3e9bd1b

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

jooby/src/main/java/org/jooby/Jooby.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3316,36 +3316,37 @@ private Config defaultConfig(final Config conf, final String cpath) {
33163316
String version = Optional.ofNullable(getClass().getPackage().getImplementationVersion())
33173317
.orElse("0.0.0");
33183318
Config defs = ConfigFactory.parseResources(Jooby.class, "jooby.conf")
3319-
.withValue("contextPath", ConfigValueFactory.fromAnyRef(cpath.equals("/") ? "" : cpath))
3320-
.withValue("application.name", ConfigValueFactory.fromAnyRef(appname))
3321-
.withValue("application.version", ConfigValueFactory.fromAnyRef(version))
3322-
.withValue("application.class", ConfigValueFactory.fromAnyRef(getClass().getName()))
3323-
.withValue("application.ns", ConfigValueFactory.fromAnyRef(ns))
3324-
.withValue("application.lang", ConfigValueFactory.fromAnyRef(lang))
3325-
.withValue("application.tz", ConfigValueFactory.fromAnyRef(tz))
3326-
.withValue("application.numberFormat", ConfigValueFactory.fromAnyRef(nf))
3327-
.withValue("server.http2.enabled", ConfigValueFactory.fromAnyRef(http2))
3328-
.withValue("runtime.processors", ConfigValueFactory.fromAnyRef(processors))
3329-
.withValue("runtime.processors-plus1", ConfigValueFactory.fromAnyRef(processors + 1))
3330-
.withValue("runtime.processors-plus2", ConfigValueFactory.fromAnyRef(processors + 2))
3331-
.withValue("runtime.processors-x2", ConfigValueFactory.fromAnyRef(processors * 2))
3332-
.withValue("runtime.processors-x4", ConfigValueFactory.fromAnyRef(processors * 4))
3333-
.withValue("runtime.processors-x8", ConfigValueFactory.fromAnyRef(processors * 8))
3334-
.withValue("runtime.concurrencyLevel", ConfigValueFactory
3335-
.fromAnyRef(Math.max(4, processors)));
3319+
.withValue("contextPath", fromAnyRef(cpath.equals("/") ? "" : cpath))
3320+
.withValue("application.name", fromAnyRef(appname))
3321+
.withValue("application.version", fromAnyRef(version))
3322+
.withValue("application.class", fromAnyRef(getClass().getName()))
3323+
.withValue("application.ns", fromAnyRef(ns))
3324+
.withValue("application.lang", fromAnyRef(lang))
3325+
.withValue("application.tz", fromAnyRef(tz))
3326+
.withValue("application.numberFormat", fromAnyRef(nf))
3327+
.withValue("server.http2.enabled", fromAnyRef(http2))
3328+
.withValue("runtime.processors", fromAnyRef(processors))
3329+
.withValue("runtime.processors-plus1", fromAnyRef(processors + 1))
3330+
.withValue("runtime.processors-plus2", fromAnyRef(processors + 2))
3331+
.withValue("runtime.processors-x2", fromAnyRef(processors * 2))
3332+
.withValue("runtime.processors-x4", fromAnyRef(processors * 4))
3333+
.withValue("runtime.processors-x8", fromAnyRef(processors * 8))
3334+
.withValue("runtime.concurrencyLevel", fromAnyRef(Math.max(4, processors)))
3335+
.withValue("server.threads.Min", fromAnyRef(Math.max(4, processors)))
3336+
.withValue("server.threads.Max", fromAnyRef(Math.max(32, processors * 8)));
33363337

33373338
if (charset != null) {
3338-
defs = defs.withValue("application.charset", ConfigValueFactory.fromAnyRef(charset.name()));
3339+
defs = defs.withValue("application.charset", fromAnyRef(charset.name()));
33393340
}
33403341
if (port != null) {
3341-
defs = defs.withValue("application.port", ConfigValueFactory.fromAnyRef(port.intValue()));
3342+
defs = defs.withValue("application.port", fromAnyRef(port.intValue()));
33423343
}
33433344
if (securePort != null) {
33443345
defs = defs.withValue("application.securePort",
3345-
ConfigValueFactory.fromAnyRef(securePort.intValue()));
3346+
fromAnyRef(securePort.intValue()));
33463347
}
33473348
if (dateFormat != null) {
3348-
defs = defs.withValue("application.dateFormat", ConfigValueFactory.fromAnyRef(dateFormat));
3349+
defs = defs.withValue("application.dateFormat", fromAnyRef(dateFormat));
33493350
}
33503351
return defs;
33513352
}

jooby/src/main/resources/org/jooby/jooby.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ server {
137137
}
138138

139139
threads {
140-
Min = ${runtime.processors}
141-
Max = ${runtime.processors-x8}
140+
# Min = Math.max(4, ${runtime.processors})
141+
# Max = Math.max(32, ${runtime.processors-x8})
142142
IdleTimeout = 60s
143143
}
144144

modules/jooby-netty/src/main/java/org/jooby/internal/netty/NettyServer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ public class NettyServer implements Server {
261261
public NettyServer(final HttpHandler dispatcher, final Config config) {
262262
this.dispatcher = dispatcher;
263263
this.conf = config;
264-
ResourceLeakDetector.setLevel(Level.DISABLED);
265264
}
266265

267266
@Override
@@ -270,7 +269,7 @@ public void start() throws Exception {
270269
bossLoop = eventLoop(bossThreads, "boss");
271270
int workerThreads = conf.getInt("netty.threads.Worker");
272271
if (workerThreads > 0) {
273-
workerLoop = eventLoop(workerThreads, "worker");
272+
workerLoop = eventLoop(Math.max(4, workerThreads), "worker");
274273
} else {
275274
workerLoop = bossLoop;
276275
}

modules/jooby-netty/src/test/java/org/jooby/internal/netty/NettyServerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public void unknownOption() throws Exception {
240240
@SuppressWarnings({"unchecked", "rawtypes" })
241241
@Test
242242
public void serverWithWorkerEventLoop() throws Exception {
243-
Config config = this.config.withValue("netty.threads.Worker", ConfigValueFactory.fromAnyRef(1));
243+
Config config = this.config.withValue("netty.threads.Worker", ConfigValueFactory.fromAnyRef(4));
244244
new MockUnit(HttpHandler.class)
245245
.expect(parentThreadFactory("nio-boss"))
246246
.expect(noepoll)
@@ -264,7 +264,7 @@ public void serverWithWorkerEventLoop() throws Exception {
264264
.expect(unit -> {
265265
NioEventLoopGroup eventLoop = unit.constructor(NioEventLoopGroup.class)
266266
.args(int.class, ThreadFactory.class)
267-
.build(1, unit.get(DefaultThreadFactory.class));
267+
.build(4, unit.get(DefaultThreadFactory.class));
268268
unit.registerMock(NioEventLoopGroup.class, eventLoop);
269269

270270
Future future = unit.mock(Future.class);
@@ -296,7 +296,7 @@ public void serverWithWorkerEventLoop() throws Exception {
296296
@SuppressWarnings({"unchecked", "rawtypes" })
297297
@Test
298298
public void eventLoopError() throws Exception {
299-
Config config = this.config.withValue("netty.threads.Worker", ConfigValueFactory.fromAnyRef(1));
299+
Config config = this.config.withValue("netty.threads.Worker", ConfigValueFactory.fromAnyRef(5));
300300
new MockUnit(HttpHandler.class)
301301
.expect(parentThreadFactory("nio-boss"))
302302
.expect(noepoll)
@@ -320,7 +320,7 @@ public void eventLoopError() throws Exception {
320320
.expect(unit -> {
321321
NioEventLoopGroup eventLoop = unit.constructor(NioEventLoopGroup.class)
322322
.args(int.class, ThreadFactory.class)
323-
.build(1, unit.get(DefaultThreadFactory.class));
323+
.build(5, unit.get(DefaultThreadFactory.class));
324324
unit.registerMock(NioEventLoopGroup.class, eventLoop);
325325

326326
Future future = unit.mock(Future.class);

0 commit comments

Comments
 (0)