use of org.eclipse.jetty.util.thread.QueuedThreadPool in project neo4j by neo4j.
the class JettyThreadLimitTest method shouldHaveConfigurableJettyThreadPoolSize.
@Test
public void shouldHaveConfigurableJettyThreadPoolSize() throws Exception {
Jetty9WebServer server = new Jetty9WebServer(NullLogProvider.getInstance(), Config.empty());
int numCores = 1;
// 12 is the new min max Threads value, for one core
int configuredMaxThreads = 12;
// In this configuration, 1 thread will become an acceptor...
int acceptorThreads = 1;
// ... and 1 thread will become a selector...
int selectorThreads = 1;
// ... and the rest are job threads
int jobThreads = configuredMaxThreads - acceptorThreads - selectorThreads;
server.setMaxThreads(numCores);
server.setAddress(new ListenSocketAddress("localhost", 7480));
try {
server.start();
QueuedThreadPool threadPool = (QueuedThreadPool) server.getJetty().getThreadPool();
threadPool.start();
CountDownLatch startLatch = new CountDownLatch(jobThreads);
CountDownLatch endLatch = loadThreadPool(threadPool, configuredMaxThreads + 1, startLatch);
// Wait for threadPool to create threads
startLatch.await();
int threads = threadPool.getThreads();
assertEquals("Wrong number of threads in pool", configuredMaxThreads, threads);
endLatch.countDown();
} finally {
server.stop();
}
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project spark by perwendel.
the class JettyServer method create.
/**
* Creates a Jetty server.
*
* @param maxThreads maxThreads
* @param minThreads minThreads
* @param threadTimeoutMillis threadTimeoutMillis
* @return a new jetty server instance
*/
public static Server create(int maxThreads, int minThreads, int threadTimeoutMillis) {
Server server;
if (maxThreads > 0) {
int max = (maxThreads > 0) ? maxThreads : 200;
int min = (minThreads > 0) ? minThreads : 8;
int idleTimeout = (threadTimeoutMillis > 0) ? threadTimeoutMillis : 60000;
server = new Server(new QueuedThreadPool(max, min, idleTimeout));
} else {
server = new Server();
}
return server;
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project spark by perwendel.
the class JettyServerTest method testCreateServer_whenNonDefaultMaxThreadOnly_thenUseDefaultMinThreadAndTimeout.
@Test
public void testCreateServer_whenNonDefaultMaxThreadOnly_thenUseDefaultMinThreadAndTimeout() throws Exception {
Server server = JettyServer.create(1, 0, 0);
QueuedThreadPool threadPool = (QueuedThreadPool) server.getThreadPool();
int minThreads = (int) Whitebox.getInternalState(threadPool, "_minThreads");
int maxThreads = (int) Whitebox.getInternalState(threadPool, "_maxThreads");
int idleTimeout = (int) Whitebox.getInternalState(threadPool, "_idleTimeout");
assertEquals("Server thread pool default minThreads should be 1", 1, minThreads);
assertEquals("Server thread pool default maxThreads should be the same as specified", 1, maxThreads);
assertEquals("Server thread pool default idleTimeout should be 60000", 60000, idleTimeout);
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project camel by apache.
the class WebsocketEndpointConfigurationTest method testSetServletThreadPool.
@Test
public void testSetServletThreadPool() throws Exception {
port = AvailablePortFinder.getNextAvailable(16332);
String uri = "websocket://localhost:" + port + "/bar?bufferSize=25000&maxIdleTime=3000";
WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint) context.getEndpoint(uri);
WebsocketComponent component = websocketEndpoint.getComponent();
QueuedThreadPool qtp = new QueuedThreadPool(20, 1);
component.setThreadPool(qtp);
Consumer consumer = websocketEndpoint.createConsumer(processor);
component.connect((WebsocketProducerConsumer) consumer);
assertNotNull(consumer);
assertEquals(WebsocketConsumer.class, consumer.getClass());
// just check the servlet initial parameters
ConnectorRef conector = WebsocketComponent.getConnectors().values().iterator().next();
ServletContextHandler context = (ServletContextHandler) conector.server.getHandler();
String buffersize = context.getInitParameter("bufferSize");
assertEquals("Got a wrong buffersize", "25000", buffersize);
String maxIdleTime = context.getInitParameter("maxIdleTime");
assertEquals("Got a wrong maxIdleTime", "3000", maxIdleTime);
WebSocketServletFactory factory = (WebSocketServletFactory) context.getServletContext().getAttribute(WebSocketServletFactory.class.getName());
int factoryBufferSize = factory.getPolicy().getInputBufferSize();
assertEquals("Got a wrong buffersize", 25000, factoryBufferSize);
long factoryMaxIdleTime = factory.getPolicy().getIdleTimeout();
assertEquals("Got a wrong maxIdleTime", 3000, factoryMaxIdleTime);
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project camel by apache.
the class WebsocketComponent method createServer.
protected Server createServer() throws Exception {
Server server = null;
if (minThreads == null && maxThreads == null && getThreadPool() == null) {
minThreads = 1;
// 1+selectors+acceptors
maxThreads = 1 + Runtime.getRuntime().availableProcessors() * 2;
}
// configure thread pool if min/max given
if (minThreads != null || maxThreads != null) {
if (getThreadPool() != null) {
throw new IllegalArgumentException("You cannot configure both minThreads/maxThreads and a custom threadPool on JettyHttpComponent: " + this);
}
QueuedThreadPool qtp = new QueuedThreadPool();
if (minThreads != null) {
qtp.setMinThreads(minThreads.intValue());
}
if (maxThreads != null) {
qtp.setMaxThreads(maxThreads.intValue());
}
// let the thread names indicate they are from the server
qtp.setName("CamelJettyWebSocketServer");
try {
qtp.start();
} catch (Exception e) {
throw new RuntimeCamelException("Error starting JettyWebSocketServer thread pool: " + qtp, e);
}
server = new Server(qtp);
ContextHandlerCollection collection = new ContextHandlerCollection();
server.setHandler(collection);
}
if (getThreadPool() != null) {
server = new Server(getThreadPool());
ContextHandlerCollection collection = new ContextHandlerCollection();
server.setHandler(collection);
}
return server;
}
Aggregations