Search in sources :

Example 66 with QueuedThreadPool

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);
    }
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) org.eclipse.jetty.server(org.eclipse.jetty.server) EmbedServerException(com.blade.exception.EmbedServerException) Config(com.blade.kit.base.Config) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) BladeInitListener(com.blade.mvc.context.BladeInitListener) EmbedServerException(com.blade.exception.EmbedServerException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet)

Example 67 with QueuedThreadPool

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();
}
Also used : SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool)

Example 68 with QueuedThreadPool

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;
}
Also used : Connector(org.eclipse.jetty.server.Connector) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) ConnectorFactory(io.dropwizard.jetty.ConnectorFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ArrayList(java.util.ArrayList) ContainerLifeCycle(org.eclipse.jetty.util.component.ContainerLifeCycle)

Example 69 with QueuedThreadPool

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;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ArrayList(java.util.ArrayList)

Example 70 with QueuedThreadPool

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

QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)126 Server (org.eclipse.jetty.server.Server)65 ServerConnector (org.eclipse.jetty.server.ServerConnector)51 Test (org.junit.Test)30 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)26 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)23 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)22 HttpClient (org.eclipse.jetty.client.HttpClient)18 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)18 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)18 IOException (java.io.IOException)17 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)11 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)11 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)10 File (java.io.File)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 InputStream (java.io.InputStream)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)8