Skip to content

Commit

Permalink
ARTEMIS-4514 make Jetty thread pool configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram authored and clebertsuconic committed Nov 28, 2023
1 parent fed0127 commit bba8321
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -135,6 +144,30 @@ public void setWebContentEnabled(Boolean webContentEnabled) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
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;
Expand Down Expand Up @@ -99,7 +100,7 @@ public synchronized void start() throws Exception {
}
ActiveMQWebLogger.LOGGER.startingEmbeddedWebServer();

server = new Server();
server = new Server(new QueuedThreadPool(webServerConfig.maxThreads, webServerConfig.minThreads, webServerConfig.idleThreadTimeout));
handlers = new HandlerList();

HttpConfiguration httpConfiguration = new HttpConfiguration();
Expand Down Expand Up @@ -411,4 +412,8 @@ public synchronized void stop(boolean isShutdown) throws Exception {
public List<Pair<WebAppContext, String>> getWebContextData() {
return this.webContextData;
}

public Server getWebServer() {
return server;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
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;
Expand Down Expand Up @@ -179,6 +180,28 @@ private void internalSimpleServer(boolean useCustomizer) throws Exception {
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();
Expand Down
8 changes: 8 additions & 0 deletions docs/user-manual/web-server.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit bba8321

Please sign in to comment.