Commit 5893786c authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Add 'threads' configuration group for embedded containers"

See gh-19475
parent 208f5810
...@@ -1146,7 +1146,7 @@ public class ServerProperties { ...@@ -1146,7 +1146,7 @@ public class ServerProperties {
} }
@Deprecated @Deprecated
@DeprecatedConfigurationProperty(replacement = "server.jetty.threads.maxQueueCapacity") @DeprecatedConfigurationProperty(replacement = "server.jetty.threads.max-queue-capacity")
public Integer getMaxQueueCapacity() { public Integer getMaxQueueCapacity() {
return this.getThreads().getMaxQueueCapacity(); return this.getThreads().getMaxQueueCapacity();
} }
......
...@@ -76,8 +76,8 @@ public class JettyWebServerFactoryCustomizer ...@@ -76,8 +76,8 @@ public class JettyWebServerFactoryCustomizer
public void customize(ConfigurableJettyWebServerFactory factory) { public void customize(ConfigurableJettyWebServerFactory factory) {
ServerProperties properties = this.serverProperties; ServerProperties properties = this.serverProperties;
ServerProperties.Jetty jettyProperties = properties.getJetty(); ServerProperties.Jetty jettyProperties = properties.getJetty();
ServerProperties.Jetty.Threads threadProperties = jettyProperties.getThreads();
factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders()); factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders());
ServerProperties.Jetty.Threads threadProperties = jettyProperties.getThreads();
factory.setThreadPool(determineThreadPool(jettyProperties.getThreads())); factory.setThreadPool(determineThreadPool(jettyProperties.getThreads()));
PropertyMapper propertyMapper = PropertyMapper.get(); PropertyMapper propertyMapper = PropertyMapper.get();
propertyMapper.from(threadProperties::getAcceptors).whenNonNull().to(factory::setAcceptors); propertyMapper.from(threadProperties::getAcceptors).whenNonNull().to(factory::setAcceptors);
...@@ -142,12 +142,12 @@ public class JettyWebServerFactoryCustomizer ...@@ -142,12 +142,12 @@ public class JettyWebServerFactoryCustomizer
}); });
} }
private ThreadPool determineThreadPool(ServerProperties.Jetty.Threads threadProperties) { private ThreadPool determineThreadPool(ServerProperties.Jetty.Threads properties) {
BlockingQueue<Runnable> queue = determineBlockingQueue(threadProperties.getMaxQueueCapacity()); BlockingQueue<Runnable> queue = determineBlockingQueue(properties.getMaxQueueCapacity());
int maxThreadCount = (threadProperties.getMax() > 0) ? threadProperties.getMax() : 200; int maxThreadCount = (properties.getMax() > 0) ? properties.getMax() : 200;
int minThreadCount = (threadProperties.getMin() > 0) ? threadProperties.getMin() : 8; int minThreadCount = (properties.getMin() > 0) ? properties.getMin() : 8;
int threadIdleTimeout = (threadProperties.getIdleTimeout() != null) int threadIdleTimeout = (properties.getIdleTimeout() != null) ? (int) properties.getIdleTimeout().toMillis()
? (int) threadProperties.getIdleTimeout().toMillis() : 60000; : 60000;
return new QueuedThreadPool(maxThreadCount, minThreadCount, threadIdleTimeout, queue); return new QueuedThreadPool(maxThreadCount, minThreadCount, threadIdleTimeout, queue);
} }
......
...@@ -79,12 +79,12 @@ public class TomcatWebServerFactoryCustomizer ...@@ -79,12 +79,12 @@ public class TomcatWebServerFactoryCustomizer
public void customize(ConfigurableTomcatWebServerFactory factory) { public void customize(ConfigurableTomcatWebServerFactory factory) {
ServerProperties properties = this.serverProperties; ServerProperties properties = this.serverProperties;
ServerProperties.Tomcat tomcatProperties = properties.getTomcat(); ServerProperties.Tomcat tomcatProperties = properties.getTomcat();
ServerProperties.Tomcat.Threads threadProperties = tomcatProperties.getThreads();
PropertyMapper propertyMapper = PropertyMapper.get(); PropertyMapper propertyMapper = PropertyMapper.get();
propertyMapper.from(tomcatProperties::getBasedir).whenNonNull().to(factory::setBaseDirectory); propertyMapper.from(tomcatProperties::getBasedir).whenNonNull().to(factory::setBaseDirectory);
propertyMapper.from(tomcatProperties::getBackgroundProcessorDelay).whenNonNull().as(Duration::getSeconds) propertyMapper.from(tomcatProperties::getBackgroundProcessorDelay).whenNonNull().as(Duration::getSeconds)
.as(Long::intValue).to(factory::setBackgroundProcessorDelay); .as(Long::intValue).to(factory::setBackgroundProcessorDelay);
customizeRemoteIpValve(factory); customizeRemoteIpValve(factory);
ServerProperties.Tomcat.Threads threadProperties = tomcatProperties.getThreads();
propertyMapper.from(threadProperties::getMax).when(this::isPositive) propertyMapper.from(threadProperties::getMax).when(this::isPositive)
.to((maxThreads) -> customizeMaxThreads(factory, threadProperties.getMax())); .to((maxThreads) -> customizeMaxThreads(factory, threadProperties.getMax()));
propertyMapper.from(threadProperties::getMinSpare).when(this::isPositive) propertyMapper.from(threadProperties::getMinSpare).when(this::isPositive)
......
...@@ -88,8 +88,8 @@ public class UndertowWebServerFactoryCustomizer ...@@ -88,8 +88,8 @@ public class UndertowWebServerFactoryCustomizer
private void mapUndertowProperties(ConfigurableUndertowWebServerFactory factory, FactoryOptions options) { private void mapUndertowProperties(ConfigurableUndertowWebServerFactory factory, FactoryOptions options) {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
Undertow properties = this.serverProperties.getUndertow(); Undertow properties = this.serverProperties.getUndertow();
ServerProperties.Undertow.Threads threadProperties = properties.getThreads();
map.from(properties::getBufferSize).whenNonNull().asInt(DataSize::toBytes).to(factory::setBufferSize); map.from(properties::getBufferSize).whenNonNull().asInt(DataSize::toBytes).to(factory::setBufferSize);
ServerProperties.Undertow.Threads threadProperties = properties.getThreads();
map.from(threadProperties::getIo).to(factory::setIoThreads); map.from(threadProperties::getIo).to(factory::setIoThreads);
map.from(threadProperties::getWorker).to(factory::setWorkerThreads); map.from(threadProperties::getWorker).to(factory::setWorkerThreads);
map.from(properties::getDirectBuffers).to(factory::setUseDirectBuffers); map.from(properties::getDirectBuffers).to(factory::setUseDirectBuffers);
......
...@@ -219,9 +219,6 @@ class ServerPropertiesTests { ...@@ -219,9 +219,6 @@ class ServerPropertiesTests {
@Test @Test
void testCustomizeTomcatMaxThreadsDeprecated() { void testCustomizeTomcatMaxThreadsDeprecated() {
bind("server.tomcat.maxThreads", "10"); bind("server.tomcat.maxThreads", "10");
assertThat(this.properties.getTomcat().getMaxThreads()).isEqualTo(10);
// Verify they are locked on same backing props to avoid further downstream
// deprecated testing
assertThat(this.properties.getTomcat().getThreads().getMax()).isEqualTo(10); assertThat(this.properties.getTomcat().getThreads().getMax()).isEqualTo(10);
} }
...@@ -235,9 +232,6 @@ class ServerPropertiesTests { ...@@ -235,9 +232,6 @@ class ServerPropertiesTests {
@Test @Test
void testCustomizeTomcatMinSpareThreadsDeprecated() { void testCustomizeTomcatMinSpareThreadsDeprecated() {
bind("server.tomcat.min-spare-threads", "10"); bind("server.tomcat.min-spare-threads", "10");
assertThat(this.properties.getTomcat().getMinSpareThreads()).isEqualTo(10);
// Verify they are locked on same backing props to avoid further downstream
// deprecated testing
assertThat(this.properties.getTomcat().getThreads().getMinSpare()).isEqualTo(10); assertThat(this.properties.getTomcat().getThreads().getMinSpare()).isEqualTo(10);
} }
...@@ -251,9 +245,6 @@ class ServerPropertiesTests { ...@@ -251,9 +245,6 @@ class ServerPropertiesTests {
@Test @Test
void testCustomizeJettyAcceptorsDeprecated() { void testCustomizeJettyAcceptorsDeprecated() {
bind("server.jetty.acceptors", "10"); bind("server.jetty.acceptors", "10");
assertThat(this.properties.getJetty().getAcceptors()).isEqualTo(10);
// Verify they are locked on same backing props to avoid further downstream
// deprecated testing
assertThat(this.properties.getJetty().getThreads().getAcceptors()).isEqualTo(10); assertThat(this.properties.getJetty().getThreads().getAcceptors()).isEqualTo(10);
} }
...@@ -268,8 +259,6 @@ class ServerPropertiesTests { ...@@ -268,8 +259,6 @@ class ServerPropertiesTests {
void testCustomizeJettySelectorsDeprecated() { void testCustomizeJettySelectorsDeprecated() {
bind("server.jetty.selectors", "10"); bind("server.jetty.selectors", "10");
assertThat(this.properties.getJetty().getSelectors()).isEqualTo(10); assertThat(this.properties.getJetty().getSelectors()).isEqualTo(10);
// Verify they are locked on same backing props to avoid further downstream
// deprecated testing
assertThat(this.properties.getJetty().getThreads().getSelectors()).isEqualTo(10); assertThat(this.properties.getJetty().getThreads().getSelectors()).isEqualTo(10);
} }
...@@ -283,9 +272,6 @@ class ServerPropertiesTests { ...@@ -283,9 +272,6 @@ class ServerPropertiesTests {
@Test @Test
void testCustomizeJettyMaxThreadsDeprecated() { void testCustomizeJettyMaxThreadsDeprecated() {
bind("server.jetty.maxThreads", "10"); bind("server.jetty.maxThreads", "10");
assertThat(this.properties.getJetty().getMaxThreads()).isEqualTo(10);
// Verify they are locked on same backing props to avoid further downstream
// deprecated testing
assertThat(this.properties.getJetty().getThreads().getMax()).isEqualTo(10); assertThat(this.properties.getJetty().getThreads().getMax()).isEqualTo(10);
} }
...@@ -299,9 +285,6 @@ class ServerPropertiesTests { ...@@ -299,9 +285,6 @@ class ServerPropertiesTests {
@Test @Test
void testCustomizeJettyMinThreadsDeprecated() { void testCustomizeJettyMinThreadsDeprecated() {
bind("server.jetty.minThreads", "10"); bind("server.jetty.minThreads", "10");
assertThat(this.properties.getJetty().getMinThreads()).isEqualTo(10);
// Verify they are locked on same backing props to avoid further downstream
// deprecated testing
assertThat(this.properties.getJetty().getThreads().getMin()).isEqualTo(10); assertThat(this.properties.getJetty().getThreads().getMin()).isEqualTo(10);
} }
...@@ -315,9 +298,6 @@ class ServerPropertiesTests { ...@@ -315,9 +298,6 @@ class ServerPropertiesTests {
@Test @Test
void testCustomizeJettyIdleTimeoutDeprecated() { void testCustomizeJettyIdleTimeoutDeprecated() {
bind("server.jetty.thread-idle-timeout", "10s"); bind("server.jetty.thread-idle-timeout", "10s");
assertThat(this.properties.getJetty().getThreadIdleTimeout()).isEqualTo(Duration.ofSeconds(10));
// Verify they are locked on same backing props to avoid further downstream
// deprecated testing
assertThat(this.properties.getJetty().getThreads().getIdleTimeout()).hasSeconds(10); assertThat(this.properties.getJetty().getThreads().getIdleTimeout()).hasSeconds(10);
} }
...@@ -331,9 +311,6 @@ class ServerPropertiesTests { ...@@ -331,9 +311,6 @@ class ServerPropertiesTests {
@Test @Test
void testCustomizeJettyMaxQueueCapacityDeprecated() { void testCustomizeJettyMaxQueueCapacityDeprecated() {
bind("server.jetty.max-queue-capacity", "5150"); bind("server.jetty.max-queue-capacity", "5150");
assertThat(this.properties.getJetty().getMaxQueueCapacity()).isEqualTo(5150);
// Verify they are locked on same backing props to avoid further downstream
// deprecated testing
assertThat(this.properties.getJetty().getThreads().getMaxQueueCapacity()).isEqualTo(5150); assertThat(this.properties.getJetty().getThreads().getMaxQueueCapacity()).isEqualTo(5150);
} }
...@@ -361,9 +338,6 @@ class ServerPropertiesTests { ...@@ -361,9 +338,6 @@ class ServerPropertiesTests {
@Test @Test
void testCustomizeUndertowIoThreadsDeprecated() { void testCustomizeUndertowIoThreadsDeprecated() {
bind("server.undertow.ioThreads", "4"); bind("server.undertow.ioThreads", "4");
assertThat(this.properties.getUndertow().getIoThreads()).isEqualTo(4);
// Verify they are locked on same backing props to avoid further downstream
// deprecated testing
assertThat(this.properties.getUndertow().getThreads().getIo()).isEqualTo(4); assertThat(this.properties.getUndertow().getThreads().getIo()).isEqualTo(4);
} }
...@@ -377,9 +351,6 @@ class ServerPropertiesTests { ...@@ -377,9 +351,6 @@ class ServerPropertiesTests {
@Test @Test
void testCustomizeUndertowWorkerThreadsDeprecated() { void testCustomizeUndertowWorkerThreadsDeprecated() {
bind("server.undertow.workerThreads", "10"); bind("server.undertow.workerThreads", "10");
assertThat(this.properties.getUndertow().getWorkerThreads()).isEqualTo(10);
// Verify they are locked on same backing props to avoid further downstream
// deprecated testing
assertThat(this.properties.getUndertow().getThreads().getWorker()).isEqualTo(10); assertThat(this.properties.getUndertow().getThreads().getWorker()).isEqualTo(10);
} }
......
...@@ -179,7 +179,7 @@ class JettyWebServerFactoryCustomizerTests { ...@@ -179,7 +179,7 @@ class JettyWebServerFactoryCustomizerTests {
@Test @Test
void threadPoolIdleTimeoutCanBeCustomized() { void threadPoolIdleTimeoutCanBeCustomized() {
bind("server.jetty.thread-idle-timeout=100s"); bind("server.jetty.threads.idle-timeout=100s");
JettyWebServer server = customizeAndGetServer(); JettyWebServer server = customizeAndGetServer();
QueuedThreadPool threadPool = (QueuedThreadPool) server.getServer().getThreadPool(); QueuedThreadPool threadPool = (QueuedThreadPool) server.getServer().getThreadPool();
assertThat(threadPool.getIdleTimeout()).isEqualTo(100000); assertThat(threadPool.getIdleTimeout()).isEqualTo(100000);
...@@ -187,7 +187,7 @@ class JettyWebServerFactoryCustomizerTests { ...@@ -187,7 +187,7 @@ class JettyWebServerFactoryCustomizerTests {
@Test @Test
void threadPoolWithMaxQueueCapacityEqualToZeroCreateSynchronousQueue() { void threadPoolWithMaxQueueCapacityEqualToZeroCreateSynchronousQueue() {
bind("server.jetty.max-queue-capacity=0"); bind("server.jetty.threads.max-queue-capacity=0");
JettyWebServer server = customizeAndGetServer(); JettyWebServer server = customizeAndGetServer();
ThreadPool threadPool = server.getServer().getThreadPool(); ThreadPool threadPool = server.getServer().getThreadPool();
BlockingQueue<?> queue = getQueue(threadPool); BlockingQueue<?> queue = getQueue(threadPool);
...@@ -197,8 +197,8 @@ class JettyWebServerFactoryCustomizerTests { ...@@ -197,8 +197,8 @@ class JettyWebServerFactoryCustomizerTests {
@Test @Test
void threadPoolWithMaxQueueCapacityEqualToZeroCustomizesThreadPool() { void threadPoolWithMaxQueueCapacityEqualToZeroCustomizesThreadPool() {
bind("server.jetty.max-queue-capacity=0", "server.jetty.min-threads=100", "server.jetty.max-threads=100", bind("server.jetty.threads.max-queue-capacity=0", "server.jetty.min-threads=100",
"server.jetty.thread-idle-timeout=6s"); "server.jetty.max-threads=100", "server.jetty.threads.idle-timeout=6s");
JettyWebServer server = customizeAndGetServer(); JettyWebServer server = customizeAndGetServer();
QueuedThreadPool threadPool = (QueuedThreadPool) server.getServer().getThreadPool(); QueuedThreadPool threadPool = (QueuedThreadPool) server.getServer().getThreadPool();
assertThat(threadPool.getMinThreads()).isEqualTo(100); assertThat(threadPool.getMinThreads()).isEqualTo(100);
...@@ -208,7 +208,7 @@ class JettyWebServerFactoryCustomizerTests { ...@@ -208,7 +208,7 @@ class JettyWebServerFactoryCustomizerTests {
@Test @Test
void threadPoolWithMaxQueueCapacityPositiveCreateBlockingArrayQueue() { void threadPoolWithMaxQueueCapacityPositiveCreateBlockingArrayQueue() {
bind("server.jetty.max-queue-capacity=1234"); bind("server.jetty.threads.max-queue-capacity=1234");
JettyWebServer server = customizeAndGetServer(); JettyWebServer server = customizeAndGetServer();
ThreadPool threadPool = server.getServer().getThreadPool(); ThreadPool threadPool = server.getServer().getThreadPool();
BlockingQueue<?> queue = getQueue(threadPool); BlockingQueue<?> queue = getQueue(threadPool);
...@@ -219,8 +219,8 @@ class JettyWebServerFactoryCustomizerTests { ...@@ -219,8 +219,8 @@ class JettyWebServerFactoryCustomizerTests {
@Test @Test
void threadPoolWithMaxQueueCapacityPositiveCustomizesThreadPool() { void threadPoolWithMaxQueueCapacityPositiveCustomizesThreadPool() {
bind("server.jetty.max-queue-capacity=1234", "server.jetty.min-threads=10", "server.jetty.max-threads=150", bind("server.jetty.threads.max-queue-capacity=1234", "server.jetty.min-threads=10",
"server.jetty.thread-idle-timeout=3s"); "server.jetty.max-threads=150", "server.jetty.threads.idle-timeout=3s");
JettyWebServer server = customizeAndGetServer(); JettyWebServer server = customizeAndGetServer();
QueuedThreadPool threadPool = (QueuedThreadPool) server.getServer().getThreadPool(); QueuedThreadPool threadPool = (QueuedThreadPool) server.getServer().getThreadPool();
assertThat(threadPool.getMinThreads()).isEqualTo(10); assertThat(threadPool.getMinThreads()).isEqualTo(10);
......
server.compression.enabled: true server.compression.enabled: true
server.compression.min-response-size: 1 server.compression.min-response-size: 1
server.jetty.acceptors=2 server.jetty.threads.acceptors=2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment