Search in sources :

Example 11 with ThreadPool

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

the class HttpConnectorFactoryTest method testBuildConnector.

@Test
public void testBuildConnector() throws Exception {
    HttpConnectorFactory http = new HttpConnectorFactory();
    http.setBindHost("127.0.0.1");
    http.setAcceptorThreads(Optional.of(1));
    http.setSelectorThreads(Optional.of(2));
    http.setAcceptQueueSize(1024);
    http.setSoLingerTime(Duration.seconds(30));
    http.setBlockingTimeout(Duration.minutes(1));
    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.getPort()).isEqualTo(8080);
    assertThat(connector.getHost()).isEqualTo("127.0.0.1");
    assertThat(connector.getAcceptQueueSize()).isEqualTo(1024);
    assertThat(connector.getReuseAddress()).isTrue();
    assertThat(connector.getSoLingerTime()).isEqualTo(30);
    assertThat(connector.getIdleTimeout()).isEqualTo(30000);
    assertThat(connector.getName()).isEqualTo("test-http-connector");
    assertThat(connector.getServer()).isSameAs(server);
    assertThat(connector.getScheduler()).isInstanceOf(ScheduledExecutorScheduler.class);
    assertThat(connector.getExecutor()).isSameAs(threadPool);
    // That's gross, but unfortunately ArrayByteBufferPool doesn't have public API for configuration
    ByteBufferPool byteBufferPool = connector.getByteBufferPool();
    assertThat(byteBufferPool).isInstanceOf(ArrayByteBufferPool.class);
    assertThat(getField(ArrayByteBufferPool.class, "_min", true).get(byteBufferPool)).isEqualTo(64);
    assertThat(getField(ArrayByteBufferPool.class, "_inc", true).get(byteBufferPool)).isEqualTo(1024);
    assertThat(((Object[]) getField(ArrayByteBufferPool.class, "_direct", true).get(byteBufferPool)).length).isEqualTo(64);
    assertThat(connector.getAcceptors()).isEqualTo(1);
    assertThat(connector.getSelectorManager().getSelectorCount()).isEqualTo(2);
    Jetty93InstrumentedConnectionFactory connectionFactory = (Jetty93InstrumentedConnectionFactory) connector.getConnectionFactory("http/1.1");
    assertThat(connectionFactory).isInstanceOf(Jetty93InstrumentedConnectionFactory.class);
    assertThat(connectionFactory.getTimer()).isSameAs(metrics.timer("org.eclipse.jetty.server.HttpConnectionFactory.127.0.0.1.8080.connections"));
    HttpConnectionFactory httpConnectionFactory = (HttpConnectionFactory) connectionFactory.getConnectionFactory();
    assertThat(httpConnectionFactory.getInputBufferSize()).isEqualTo(8192);
    assertThat(httpConnectionFactory.getHttpCompliance()).isEqualByComparingTo(HttpCompliance.RFC7230);
    HttpConfiguration httpConfiguration = httpConnectionFactory.getHttpConfiguration();
    assertThat(httpConfiguration.getHeaderCacheSize()).isEqualTo(512);
    assertThat(httpConfiguration.getOutputBufferSize()).isEqualTo(32768);
    assertThat(httpConfiguration.getRequestHeaderSize()).isEqualTo(8192);
    assertThat(httpConfiguration.getResponseHeaderSize()).isEqualTo(8192);
    assertThat(httpConfiguration.getSendDateHeader()).isTrue();
    assertThat(httpConfiguration.getSendServerVersion()).isFalse();
    assertThat(httpConfiguration.getCustomizers()).hasAtLeastOneElementOfType(ForwardedRequestCustomizer.class);
    assertThat(httpConfiguration.getBlockingTimeout()).isEqualTo(60000L);
    connector.stop();
    server.stop();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) 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) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Test(org.junit.Test)

Example 12 with ThreadPool

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

the class LowResourceMonitor method monitor.

protected void monitor() {
    String reasons = null;
    String cause = "";
    int connections = 0;
    ThreadPool serverThreads = _server.getThreadPool();
    if (_monitorThreads && serverThreads.isLowOnThreads()) {
        reasons = low(reasons, "Server low on threads: " + serverThreads);
        cause += "S";
    }
    for (Connector connector : getMonitoredOrServerConnectors()) {
        connections += connector.getConnectedEndPoints().size();
        Executor executor = connector.getExecutor();
        if (executor instanceof ThreadPool && executor != serverThreads) {
            ThreadPool connectorThreads = (ThreadPool) executor;
            if (_monitorThreads && connectorThreads.isLowOnThreads()) {
                reasons = low(reasons, "Connector low on threads: " + connectorThreads);
                cause += "T";
            }
        }
    }
    if (_maxConnections > 0 && connections > _maxConnections) {
        reasons = low(reasons, "Max Connections exceeded: " + connections + ">" + _maxConnections);
        cause += "C";
    }
    long memory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
    if (_maxMemory > 0 && memory > _maxMemory) {
        reasons = low(reasons, "Max memory exceeded: " + memory + ">" + _maxMemory);
        cause += "M";
    }
    if (reasons != null) {
        // Log the reasons if there is any change in the cause
        if (!cause.equals(_cause)) {
            LOG.warn("Low Resources: {}", reasons);
            _cause = cause;
        }
        // Enter low resources state?
        if (_low.compareAndSet(false, true)) {
            _reasons = reasons;
            _lowStarted = System.currentTimeMillis();
            setLowResources();
        }
        // Too long in low resources state?
        if (_maxLowResourcesTime > 0 && (System.currentTimeMillis() - _lowStarted) > _maxLowResourcesTime)
            setLowResources();
    } else {
        if (_low.compareAndSet(true, false)) {
            LOG.info("Low Resources cleared");
            _reasons = null;
            _lowStarted = 0;
            _cause = null;
            clearLowResources();
        }
    }
}
Also used : Executor(java.util.concurrent.Executor) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) EndPoint(org.eclipse.jetty.io.EndPoint)

Example 13 with ThreadPool

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

the class EnterpriseNeoServer method createWebServer.

@Override
protected WebServer createWebServer() {
    Jetty9WebServer webServer = (Jetty9WebServer) super.createWebServer();
    webServer.setJettyCreatedCallback((jetty) -> {
        ThreadPool threadPool = jetty.getThreadPool();
        assert threadPool != null;
        try {
            ServerThreadViewSetter setter = database.getGraph().getDependencyResolver().resolveDependency(ServerThreadViewSetter.class);
            setter.set(new ServerThreadView() {

                @Override
                public int allThreads() {
                    return threadPool.getThreads();
                }

                @Override
                public int idleThreads() {
                    return threadPool.getIdleThreads();
                }
            });
        } catch (UnsatisfiedDependencyException ex) {
        // nevermind, metrics are likely not enabled
        }
    });
    return webServer;
}
Also used : ServerThreadView(org.neo4j.metrics.source.server.ServerThreadView) UnsatisfiedDependencyException(org.neo4j.kernel.impl.util.UnsatisfiedDependencyException) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) Jetty9WebServer(org.neo4j.server.web.Jetty9WebServer) ServerThreadViewSetter(org.neo4j.metrics.source.server.ServerThreadViewSetter)

Example 14 with ThreadPool

use of org.eclipse.jetty.util.thread.ThreadPool in project spring-boot by spring-projects.

the class JettyServletWebServerFactoryTests method customThreadPool.

@Test
public void customThreadPool() throws Exception {
    JettyServletWebServerFactory factory = getFactory();
    ThreadPool threadPool = mock(ThreadPool.class);
    factory.setThreadPool(threadPool);
    JettyWebServer jettyWebServer = (JettyWebServer) factory.getWebServer();
    assertThat(jettyWebServer.getServer().getThreadPool()).isSameAs(threadPool);
}
Also used : ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) Test(org.junit.Test)

Example 15 with ThreadPool

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

the class JettyStats method getStatData.

@Override
public Map<String, Object> getStatData() {
    ThreadPool pool = JettyMonitor.getThreadPool();
    if (pool == null) {
        log.debug("Thread pool has not been initialized.  Not returning stat data.");
        return null;
    }
    Map<String, Object> data = Maps.newHashMap();
    data.put(ZimbraPerf.RTS_HTTP_THREADS, pool.getThreads());
    data.put(ZimbraPerf.RTS_HTTP_IDLE_THREADS, pool.getIdleThreads());
    return data;
}
Also used : ThreadPool(org.eclipse.jetty.util.thread.ThreadPool)

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