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();
}
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();
}
}
}
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;
}
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);
}
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;
}
Aggregations