Search in sources :

Example 6 with ThreadPool

use of org.eclipse.jetty.util.thread.ThreadPool in project jetty.project by eclipse.

the class InsufficientThreadsDetectionTest method testConnectorUsesServerExecutorWithNotEnoughThreads.

@Test(expected = IllegalStateException.class)
public void testConnectorUsesServerExecutorWithNotEnoughThreads() throws Exception {
    // server has 3 threads in the executor
    _server = new Server(new QueuedThreadPool(3));
    // connector will use executor from server because connectorPool is null
    ThreadPool connectorPool = null;
    // connector requires 7 threads(2 + 4 + 1)
    ServerConnector connector = new ServerConnector(_server, connectorPool, null, null, 2, 4, new HttpConnectionFactory());
    connector.setPort(0);
    _server.addConnector(connector);
    // should throw IllegalStateException because there are no required threads in server pool
    _server.start();
}
Also used : QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) Test(org.junit.Test)

Example 7 with ThreadPool

use of org.eclipse.jetty.util.thread.ThreadPool in project jetty.project by eclipse.

the class InsufficientThreadsDetectionTest method testConnectorWithDedicatedExecutor.

@Test
public void testConnectorWithDedicatedExecutor() throws Exception {
    // server has 3 threads in the executor
    _server = new Server(new QueuedThreadPool(3));
    // connector pool has 100 threads
    ThreadPool connectorPool = new QueuedThreadPool(100);
    // connector requires 7 threads(2 + 4 + 1)
    ServerConnector connector = new ServerConnector(_server, connectorPool, null, null, 2, 4, new HttpConnectionFactory());
    connector.setPort(0);
    _server.addConnector(connector);
    // should not throw exception because connector uses own executor, so its threads should not be counted
    _server.start();
}
Also used : QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) Test(org.junit.Test)

Example 8 with ThreadPool

use of org.eclipse.jetty.util.thread.ThreadPool in project zm-mailbox by Zimbra.

the class ContextPathBasedThreadPoolBalancerFilter method init.

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    suspendMs = DEFAULT_SUSPEND_MS;
    String str = StringUtils.trimToNull(filterConfig.getInitParameter(SUSPEND_INIT_PARAM));
    if (str != null) {
        suspendMs = Integer.parseInt(str);
    }
    str = StringUtils.trimToNull(filterConfig.getInitParameter(RULES_INIT_PARAM));
    parse(str);
    ZimbraLog.misc.info("Initialized with %s", str);
    ThreadPool threadPool = JettyMonitor.getThreadPool();
    if (threadPool instanceof QueuedThreadPool) {
        queuedThreadPool = (QueuedThreadPool) threadPool;
        ZimbraLog.misc.info("Thread pool was configured to max=" + queuedThreadPool.getMaxThreads());
    }
}
Also used : QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool)

Example 9 with ThreadPool

use of org.eclipse.jetty.util.thread.ThreadPool in project dropwizard by dropwizard.

the class SimpleServerFactory method build.

@Override
public Server build(Environment environment) {
    // ensures that the environment is configured before the server is built
    configure(environment);
    printBanner(environment.getName());
    final ThreadPool threadPool = createThreadPool(environment.metrics());
    final Server server = buildServer(environment.lifecycle(), threadPool);
    final Handler applicationHandler = createAppServlet(server, environment.jersey(), environment.getObjectMapper(), environment.getValidator(), environment.getApplicationContext(), environment.getJerseyServletContainer(), environment.metrics());
    final Handler adminHandler = createAdminServlet(server, environment.getAdminContext(), environment.metrics(), environment.healthChecks());
    final Connector conn = connector.build(server, environment.metrics(), environment.getName(), null);
    server.addConnector(conn);
    final ContextRoutingHandler routingHandler = new ContextRoutingHandler(ImmutableMap.of(applicationContextPath, applicationHandler, adminContextPath, adminHandler));
    final Handler gzipHandler = buildGzipHandler(routingHandler);
    server.setHandler(addStatsHandler(addRequestLog(server, gzipHandler, environment.getName())));
    return server;
}
Also used : Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) ContextRoutingHandler(io.dropwizard.jetty.ContextRoutingHandler) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) Handler(org.eclipse.jetty.server.Handler) ContextRoutingHandler(io.dropwizard.jetty.ContextRoutingHandler)

Example 10 with ThreadPool

use of org.eclipse.jetty.util.thread.ThreadPool in project dropwizard by dropwizard.

the class HttpConnectorFactoryTest method testDefaultAcceptQueueSize.

@Test
public void testDefaultAcceptQueueSize() throws Exception {
    HttpConnectorFactory http = new HttpConnectorFactory();
    http.setBindHost("127.0.0.1");
    http.setAcceptorThreads(Optional.of(1));
    http.setSelectorThreads(Optional.of(2));
    http.setSoLingerTime(Duration.seconds(30));
    Server server = new Server();
    MetricRegistry metrics = new MetricRegistry();
    ThreadPool threadPool = new QueuedThreadPool();
    ServerConnector connector = (ServerConnector) http.build(server, metrics, "test-http-connector", threadPool);
    assertThat(connector.getAcceptQueueSize()).isEqualTo(NetUtil.getTcpBacklog());
    connector.stop();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) MetricRegistry(com.codahale.metrics.MetricRegistry) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) Test(org.junit.Test)

Aggregations

ThreadPool (org.eclipse.jetty.util.thread.ThreadPool)15 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)9 Server (org.eclipse.jetty.server.Server)8 Test (org.junit.Test)6 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 Connector (org.eclipse.jetty.server.Connector)3 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)3 Handler (org.eclipse.jetty.server.Handler)2 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)2 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)2 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)1 InstrumentedConnectionFactory (com.codahale.metrics.jetty9.InstrumentedConnectionFactory)1 InstrumentedHandler (com.codahale.metrics.jetty9.InstrumentedHandler)1 InstrumentedQueuedThreadPool (com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool)1 AdminServlet (com.codahale.metrics.servlets.AdminServlet)1 HttpServer (com.sun.net.httpserver.HttpServer)1 HttpsServer (com.sun.net.httpserver.HttpsServer)1 ContextRoutingHandler (io.dropwizard.jetty.ContextRoutingHandler)1 RoutingHandler (io.dropwizard.jetty.RoutingHandler)1