ARTEMIS-4514 make Jetty thread pool configurable

This commit is contained in:
Justin Bertram 2023-11-28 12:52:30 -06:00 committed by clebertsuconic
parent fed01276ba
commit bba832139c
4 changed files with 70 additions and 1 deletions

View File

@ -95,6 +95,15 @@ public class WebServerDTO extends ComponentDTO {
@XmlAttribute
public Boolean webContentEnabled;
@XmlAttribute
public Integer maxThreads = 200;
@XmlAttribute
public Integer minThreads = Math.min(8, maxThreads);
@XmlAttribute
public Integer idleThreadTimeout = 60000;
public String getPath() {
return path;
}
@ -135,6 +144,30 @@ public class WebServerDTO extends ComponentDTO {
this.webContentEnabled = webContentEnabled;
}
public Integer getMaxThreads() {
return maxThreads;
}
public void setMaxThreads(Integer maxThreads) {
this.maxThreads = maxThreads;
}
public Integer getMinThreads() {
return minThreads;
}
public void setMinThreads(Integer minThreads) {
this.minThreads = minThreads;
}
public Integer getIdleThreadTimeout() {
return idleThreadTimeout;
}
public void setIdleThreadTimeout(Integer idleThreadTimeout) {
this.idleThreadTimeout = idleThreadTimeout;
}
public List<BindingDTO> getBindings() {
return bindings;
}

View File

@ -52,6 +52,7 @@ import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.webapp.WebAppContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -99,7 +100,7 @@ public class WebServerComponent implements ExternalComponent, WebServerComponent
}
ActiveMQWebLogger.LOGGER.startingEmbeddedWebServer();
server = new Server();
server = new Server(new QueuedThreadPool(webServerConfig.maxThreads, webServerConfig.minThreads, webServerConfig.idleThreadTimeout));
handlers = new HandlerList();
HttpConfiguration httpConfiguration = new HttpConfiguration();
@ -411,4 +412,8 @@ public class WebServerComponent implements ExternalComponent, WebServerComponent
public List<Pair<WebAppContext, String>> getWebContextData() {
return this.webContextData;
}
public Server getWebServer() {
return server;
}
}

View File

@ -89,6 +89,7 @@ import org.apache.http.impl.conn.DefaultRoutePlanner;
import org.apache.http.protocol.HttpContext;
import org.apache.http.ssl.SSLContextBuilder;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.ThreadPool;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebInfConfiguration;
import org.junit.After;
@ -179,6 +180,28 @@ public class WebServerComponentTest extends Assert {
Assert.assertFalse(webServerComponent.isStarted());
}
@Test
public void testThreadPool() throws Exception {
BindingDTO bindingDTO = new BindingDTO();
bindingDTO.uri = "http://localhost:0";
WebServerDTO webServerDTO = new WebServerDTO();
webServerDTO.setBindings(Collections.singletonList(bindingDTO));
webServerDTO.path = "webapps";
webServerDTO.webContentEnabled = true;
webServerDTO.maxThreads = 75;
webServerDTO.minThreads = 50;
WebServerComponent webServerComponent = new WebServerComponent();
Assert.assertFalse(webServerComponent.isStarted());
webServerComponent.configure(webServerDTO, "./src/test/resources/", "./src/test/resources/");
testedComponents.add(webServerComponent);
webServerComponent.start();
ThreadPool.SizedThreadPool jettyPool = (ThreadPool.SizedThreadPool) webServerComponent.getWebServer().getThreadPool();
assertEquals((long) webServerDTO.minThreads, jettyPool.getMinThreads());
assertEquals((long) webServerDTO.maxThreads, jettyPool.getMaxThreads());
webServerComponent.stop(true);
Assert.assertFalse(webServerComponent.isStarted());
}
@Test
public void testComponentStopBehavior() throws Exception {
BindingDTO bindingDTO = new BindingDTO();

View File

@ -35,6 +35,14 @@ The location to redirect the requests with the root target.
webContentEnabled::
Whether or not the content included in the web folder of the home and the instance directories is accessible.
Default is `false`.
maxThreads::
The maximum number of threads the embedded web server can create to service HTTP requests.
Default is `200`.
minThreads::
The minimum number of threads the embedded web server will hold to service HTTP requests.
Default is `8` or the value of `maxThreads` if it is lower.
idleThreadTimeout::
The time to wait before terminating an idle thread from the embedded web server. Measured in milliseconds. Default is `60000`.
=== Binding