use of org.eclipse.jetty.util.thread.QueuedThreadPool in project blade by biezhi.
the class EmbedJettyServer method startup.
@Override
public void startup(int port, String contextPath, String webRoot) throws EmbedServerException {
this.port = port;
Config config = Blade.$().config();
int minThreads = config.getInt("server.jetty.min-threads", 8);
int maxThreads = config.getInt("server.jetty.max-threads", 200);
String poolName = config.get("server.jetty.pool-name", "blade-pool");
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMinThreads(minThreads);
threadPool.setMaxThreads(maxThreads);
threadPool.setName(poolName);
this.server = new org.eclipse.jetty.server.Server(threadPool);
this.webAppContext = new WebAppContext();
this.webAppContext.setContextPath(contextPath);
this.webAppContext.setResourceBase("");
int securePort = config.getInt("server.jetty.http.secure-port", 9443);
int outputBufferSize = config.getInt("server.jetty.http.output-buffersize", 32 * 1024);
int requestHeaderSize = config.getInt("server.jetty.http.request-headersize", 8 * 1024);
int responseHeaderSize = config.getInt("server.jetty.http.response-headersize", 8 * 1024);
// HTTP Configuration
HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecurePort(securePort);
http_config.setOutputBufferSize(outputBufferSize);
http_config.setRequestHeaderSize(requestHeaderSize);
http_config.setResponseHeaderSize(responseHeaderSize);
long idleTimeout = config.getLong("server.jetty.http.idle-timeout", 30000L);
String host = config.get("server.host", "0.0.0.0");
ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory(http_config));
serverConnector.setHost(host);
serverConnector.setPort(this.port);
serverConnector.setIdleTimeout(idleTimeout);
server.setConnectors(new Connector[] { serverConnector });
boolean isAsync = config.getBoolean("server.async", false);
Class<? extends Servlet> servlet = isAsync ? AsyncDispatcherServlet.class : DispatcherServlet.class;
ServletHolder servletHolder = new ServletHolder(servlet);
servletHolder.setAsyncSupported(isAsync);
servletHolder.setInitOrder(1);
webAppContext.addEventListener(new BladeInitListener());
Set<String> statics = Blade.$().bConfig().getStatics();
defaultHolder = new ServletHolder(DefaultServlet.class);
defaultHolder.setInitOrder(0);
if (StringKit.isNotBlank(classPath)) {
LOGGER.info("add classpath : {}", classPath);
defaultHolder.setInitParameter("resourceBase", classPath);
}
statics.forEach(s -> {
if (s.indexOf(".") != -1) {
webAppContext.addServlet(defaultHolder, s);
} else {
s = s.endsWith("/") ? s + '*' : s + "/*";
webAppContext.addServlet(defaultHolder, s);
}
});
webAppContext.addServlet(defaultHolder, "/favicon.ico");
webAppContext.addServlet(servletHolder, "/");
try {
this.loadServlets(webAppContext);
this.loadFilters(webAppContext);
HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[] { webAppContext, new DefaultHandler() });
server.setHandler(handlerList);
server.setStopAtShutdown(true);
server.start();
LOGGER.info("Blade Server Listen on {}:{}", host, this.port);
server.join();
} catch (Exception e) {
throw new EmbedServerException(e);
}
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project lucida by claritylab.
the class OpenEphyraServer method main.
/**
* Entry point of Ephyra. Initializes the engine and starts the web service interface.
*
* @param args command line arguments are ignored
*/
public static void main(String[] args) throws Exception {
// enable output of status and error messages
MsgPrinter.enableStatusMsgs(true);
MsgPrinter.enableErrorMsgs(true);
// set log file and enable logging
Logger.setLogfile("log/OpenEphyra");
Logger.enableLogging(true);
String addr = "localhost";
int port = 8080;
if (args.length > 1) {
addr = args[0];
port = Integer.parseInt(args[1]);
}
int NTHREADS = Integer.parseInt(System.getenv("THREADS"));
Server server = new Server();
SelectChannelConnector con1 = new SelectChannelConnector();
con1.setHost(addr);
con1.setPort(port);
con1.setThreadPool(new QueuedThreadPool(NTHREADS));
con1.setMaxIdleTime(30000);
con1.setRequestHeaderSize(8192);
server.setConnectors(new Connector[] { con1 });
server.setHandler(new OpenEphyraServer());
server.start();
server.join();
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project dropwizard by dropwizard.
the class DefaultServerFactory method buildAdminConnectors.
private List<Connector> buildAdminConnectors(MetricRegistry metricRegistry, Server server) {
// threadpool is shared between all the connectors, so it should be managed by the server instead of the
// individual connectors
final QueuedThreadPool threadPool = new QueuedThreadPool(adminMaxThreads, adminMinThreads);
threadPool.setName("dw-admin");
server.addBean(threadPool);
final List<Connector> connectors = new ArrayList<>();
for (ConnectorFactory factory : adminConnectors) {
final Connector connector = factory.build(server, metricRegistry, "admin", threadPool);
if (connector instanceof ContainerLifeCycle) {
((ContainerLifeCycle) connector).unmanage(threadPool);
}
connectors.add(connector);
}
return connectors;
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool in project druid by druid-io.
the class JettyServerModule method makeJettyServer.
static Server makeJettyServer(DruidNode node, ServerConfig config) {
final QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMinThreads(config.getNumThreads());
threadPool.setMaxThreads(config.getNumThreads());
threadPool.setDaemon(true);
final Server server = new Server(threadPool);
// Without this bean set, the default ScheduledExecutorScheduler runs as non-daemon, causing lifecycle hooks to fail
// to fire on main exit. Related bug: https://github.com/druid-io/druid/pull/1627
server.addBean(new ScheduledExecutorScheduler("JettyScheduler", true), true);
ServerConnector connector = new ServerConnector(server);
connector.setPort(node.getPort());
connector.setIdleTimeout(Ints.checkedCast(config.getMaxIdleTime().toStandardDuration().getMillis()));
// workaround suggested in -
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=435322#c66 for jetty half open connection issues during failovers
connector.setAcceptorPriorityDelta(-1);
List<ConnectionFactory> monitoredConnFactories = new ArrayList<>();
for (ConnectionFactory cf : connector.getConnectionFactories()) {
monitoredConnFactories.add(new JettyMonitoringConnectionFactory(cf, activeConnections));
}
connector.setConnectionFactories(monitoredConnFactories);
server.setConnectors(new Connector[] { connector });
return server;
}
use of org.eclipse.jetty.util.thread.QueuedThreadPool 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();
}
Aggregations