Search in sources :

Example 1 with ThreadPoolConfig

use of org.glassfish.grizzly.threadpool.ThreadPoolConfig in project dubbo by alibaba.

the class GrizzlyClient method doOpen.

@Override
protected void doOpen() throws Throwable {
    FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
    filterChainBuilder.add(new TransportFilter());
    filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
    filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
    TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
    ThreadPoolConfig config = builder.getWorkerThreadPoolConfig();
    config.setPoolName(CLIENT_THREAD_POOL_NAME).setQueueLimit(-1).setCorePoolSize(0).setMaxPoolSize(Integer.MAX_VALUE).setKeepAliveTime(60L, TimeUnit.SECONDS);
    builder.setTcpNoDelay(true).setKeepAlive(true).setConnectionTimeout(getTimeout()).setIOStrategy(SameThreadIOStrategy.getInstance());
    transport = builder.build();
    transport.setProcessor(filterChainBuilder.build());
    transport.start();
}
Also used : TCPNIOTransportBuilder(org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder) ThreadPoolConfig(org.glassfish.grizzly.threadpool.ThreadPoolConfig) FilterChainBuilder(org.glassfish.grizzly.filterchain.FilterChainBuilder) TransportFilter(org.glassfish.grizzly.filterchain.TransportFilter)

Example 2 with ThreadPoolConfig

use of org.glassfish.grizzly.threadpool.ThreadPoolConfig in project Payara by payara.

the class GlassfishNetworkListener method configureThreadPoolConfig.

@Override
protected ThreadPoolConfig configureThreadPoolConfig(final NetworkListener networkListener, final ThreadPool threadPool) {
    final ThreadPoolConfig config = super.configureThreadPoolConfig(networkListener, threadPool);
    config.getInitialMonitoringConfig().addProbes(new ThreadPoolMonitor(grizzlyService.getMonitoring(), name, config));
    return config;
}
Also used : ThreadPoolMonitor(com.sun.enterprise.v3.services.impl.monitor.ThreadPoolMonitor) ThreadPoolConfig(org.glassfish.grizzly.threadpool.ThreadPoolConfig)

Example 3 with ThreadPoolConfig

use of org.glassfish.grizzly.threadpool.ThreadPoolConfig in project Payara by payara.

the class GrizzlyMonitoring method updateGlobalThreadPoolStatsProvider.

/**
 * Updates the global thread pool stats provider with the most current
 * total values.
 */
public void updateGlobalThreadPoolStatsProvider() {
    final ThreadPoolStatsProvider globalThreadPoolStatsProvider = threadPoolStatsProvidersMap.get("");
    // Exit method if global stats provider not registered
    if (globalThreadPoolStatsProvider == null) {
        return;
    }
    int coreThreadTotal = 0;
    int maxThreadTotal = 0;
    // Calculate the totals for each of the metrics
    for (Map.Entry<String, ThreadPoolStatsProvider> threadPoolStatsProvider : threadPoolStatsProvidersMap.entrySet()) {
        if (!threadPoolStatsProvider.getKey().equals("")) {
            // Get the pool config so we can check the thread pool name
            ThreadPoolConfig threadPoolConfig = (ThreadPoolConfig) threadPoolStatsProvider.getValue().getStatsObject();
            if (threadPoolConfig != null) {
                // Safe to cast from long to int, as the values cannot
                // actually be higher than max int.
                coreThreadTotal += (int) (long) threadPoolStatsProvider.getValue().getCoreThreadsCount().getCount();
                maxThreadTotal += (int) (long) threadPoolStatsProvider.getValue().getMaxThreadsCount().getCount();
            }
        }
    }
    // Now that we've calculated the global core and max values, set them
    globalThreadPoolStatsProvider.setCoreThreadsEvent("", coreThreadTotal);
    globalThreadPoolStatsProvider.setMaxThreadsEvent("", maxThreadTotal);
}
Also used : ThreadPoolStatsProvider(com.sun.enterprise.v3.services.impl.monitor.stats.ThreadPoolStatsProvider) ThreadPoolConfig(org.glassfish.grizzly.threadpool.ThreadPoolConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) PluginPoint(org.glassfish.external.probe.provider.PluginPoint)

Example 4 with ThreadPoolConfig

use of org.glassfish.grizzly.threadpool.ThreadPoolConfig in project Payara by payara.

the class GenericGrizzlyListener method configureTransport.

protected void configureTransport(final NetworkListener networkListener, final Transport transportConfig, final FilterChainBuilder filterChainBuilder) {
    final String transportClassName = transportConfig.getClassname();
    if (TCPNIOTransport.class.getName().equals(transportClassName)) {
        transport = configureTCPTransport(transportConfig);
    } else if (UDPNIOTransport.class.getName().equals(transportClassName)) {
        transport = configureUDPTransport();
    } else {
        throw new GrizzlyConfigException("Unsupported transport type " + transportConfig.getName());
    }
    String selectorName = transportConfig.getSelectionKeyHandler();
    if (selectorName != null) {
        if (getSelectionKeyHandlerByName(selectorName, transportConfig) != null) {
            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.warning("Element, selection-key-handler, has been deprecated and is effectively ignored by the runtime.");
            }
        }
    }
    if (!Transport.BYTE_BUFFER_TYPE.equalsIgnoreCase(transportConfig.getByteBufferType())) {
        transport.setMemoryManager(new ByteBufferManager(true, AbstractMemoryManager.DEFAULT_MAX_BUFFER_SIZE, ByteBufferManager.DEFAULT_SMALL_BUFFER_SIZE));
    }
    final int acceptorThreads = Integer.parseInt(transportConfig.getAcceptorThreads());
    transport.setSelectorRunnersCount(acceptorThreads);
    final int readSize = Integer.parseInt(transportConfig.getSocketReadBufferSize());
    if (readSize > 0) {
        transport.setReadBufferSize(readSize);
    }
    final int writeSize = Integer.parseInt(transportConfig.getSocketWriteBufferSize());
    if (writeSize > 0) {
        transport.setWriteBufferSize(writeSize);
    }
    final ThreadPoolConfig kernelThreadPoolConfig = transport.getKernelThreadPoolConfig();
    kernelThreadPoolConfig.setPoolName(networkListener.getName() + "-kernel");
    if (acceptorThreads > 0) {
        kernelThreadPoolConfig.setCorePoolSize(acceptorThreads).setMaxPoolSize(acceptorThreads);
    }
    transport.setIOStrategy(loadIOStrategy(transportConfig.getIoStrategy()));
    transport.setNIOChannelDistributor(new RoundRobinConnectionDistributor(transport, Boolean.parseBoolean(transportConfig.getDedicatedAcceptorEnabled())));
    filterChainBuilder.add(new TransportFilter());
}
Also used : TCPNIOTransport(org.glassfish.grizzly.nio.transport.TCPNIOTransport) ThreadPoolConfig(org.glassfish.grizzly.threadpool.ThreadPoolConfig) RoundRobinConnectionDistributor(org.glassfish.grizzly.nio.RoundRobinConnectionDistributor) TransportFilter(org.glassfish.grizzly.filterchain.TransportFilter) ByteBufferManager(org.glassfish.grizzly.memory.ByteBufferManager)

Example 5 with ThreadPoolConfig

use of org.glassfish.grizzly.threadpool.ThreadPoolConfig in project dubbo by alibaba.

the class GrizzlyServer method doOpen.

@Override
protected void doOpen() throws Throwable {
    FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
    filterChainBuilder.add(new TransportFilter());
    filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
    filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
    TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
    ThreadPoolConfig config = builder.getWorkerThreadPoolConfig();
    config.setPoolName(SERVER_THREAD_POOL_NAME).setQueueLimit(-1);
    String threadpool = getUrl().getParameter(Constants.THREADPOOL_KEY, Constants.DEFAULT_THREADPOOL);
    if (Constants.DEFAULT_THREADPOOL.equals(threadpool)) {
        int threads = getUrl().getPositiveParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
        config.setCorePoolSize(threads).setMaxPoolSize(threads).setKeepAliveTime(0L, TimeUnit.SECONDS);
    } else if ("cached".equals(threadpool)) {
        int threads = getUrl().getPositiveParameter(Constants.THREADS_KEY, Integer.MAX_VALUE);
        config.setCorePoolSize(0).setMaxPoolSize(threads).setKeepAliveTime(60L, TimeUnit.SECONDS);
    } else {
        throw new IllegalArgumentException("Unsupported threadpool type " + threadpool);
    }
    builder.setKeepAlive(true).setReuseAddress(false).setIOStrategy(SameThreadIOStrategy.getInstance());
    transport = builder.build();
    transport.setProcessor(filterChainBuilder.build());
    transport.bind(getBindAddress());
    transport.start();
}
Also used : TCPNIOTransportBuilder(org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder) ThreadPoolConfig(org.glassfish.grizzly.threadpool.ThreadPoolConfig) FilterChainBuilder(org.glassfish.grizzly.filterchain.FilterChainBuilder) TransportFilter(org.glassfish.grizzly.filterchain.TransportFilter)

Aggregations

ThreadPoolConfig (org.glassfish.grizzly.threadpool.ThreadPoolConfig)6 TransportFilter (org.glassfish.grizzly.filterchain.TransportFilter)3 FilterChainBuilder (org.glassfish.grizzly.filterchain.FilterChainBuilder)2 TCPNIOTransportBuilder (org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder)2 ThreadPoolMonitor (com.sun.enterprise.v3.services.impl.monitor.ThreadPoolMonitor)1 ThreadPoolStatsProvider (com.sun.enterprise.v3.services.impl.monitor.stats.ThreadPoolStatsProvider)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PluginPoint (org.glassfish.external.probe.provider.PluginPoint)1 ByteBufferManager (org.glassfish.grizzly.memory.ByteBufferManager)1 RoundRobinConnectionDistributor (org.glassfish.grizzly.nio.RoundRobinConnectionDistributor)1 TCPNIOTransport (org.glassfish.grizzly.nio.transport.TCPNIOTransport)1