| | |
| | | import org.glassfish.grizzly.nio.transport.TCPNIOTransport; |
| | | import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; |
| | | import org.glassfish.grizzly.strategies.SameThreadIOStrategy; |
| | | import org.glassfish.grizzly.strategies.WorkerThreadIOStrategy; |
| | | import org.glassfish.grizzly.threadpool.ThreadPoolConfig; |
| | | |
| | | import com.forgerock.opendj.util.ReferenceCountedObject; |
| | |
| | | protected TCPNIOTransport newInstance() { |
| | | final TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance(); |
| | | |
| | | builder.setIOStrategy(SameThreadIOStrategy.getInstance()); |
| | | /* |
| | | * Determine which threading strategy to use, and total number of |
| | | * threads. |
| | | */ |
| | | final String useWorkerThreadsStr = |
| | | System.getProperty("org.forgerock.opendj.transport.useWorkerThreads"); |
| | | final boolean useWorkerThreadStrategy; |
| | | if (useWorkerThreadsStr != null) { |
| | | useWorkerThreadStrategy = Boolean.parseBoolean(useWorkerThreadsStr); |
| | | } else { |
| | | /* |
| | | * The most best performing strategy to use is the |
| | | * SameThreadIOStrategy, however it can only be used in cases where |
| | | * result listeners will not block. |
| | | */ |
| | | useWorkerThreadStrategy = true; |
| | | } |
| | | |
| | | if (useWorkerThreadStrategy) { |
| | | builder.setIOStrategy(WorkerThreadIOStrategy.getInstance()); |
| | | } else { |
| | | builder.setIOStrategy(SameThreadIOStrategy.getInstance()); |
| | | } |
| | | |
| | | // Calculate thread counts. |
| | | final int cpus = Runtime.getRuntime().availableProcessors(); |
| | |
| | | if (selectorsStr != null) { |
| | | selectorThreadCount = Integer.parseInt(selectorsStr); |
| | | } else { |
| | | selectorThreadCount = Math.max(5, (cpus / 2) - 1); |
| | | selectorThreadCount = |
| | | useWorkerThreadStrategy ? Math.max(2, cpus / 4) : Math.max(5, (cpus / 2) - 1); |
| | | } |
| | | |
| | | builder.setSelectorThreadPoolConfig(ThreadPoolConfig.defaultConfig().setCorePoolSize( |
| | | selectorThreadCount).setMaxPoolSize(selectorThreadCount).setPoolName( |
| | | "OpenDJ LDAP SDK Grizzly selector thread")); |
| | | |
| | | // Calculate the number of worker threads. |
| | | if (builder.getWorkerThreadPoolConfig() != null) { |
| | | final String workersStr = System.getProperty("org.forgerock.opendj.transport.workers"); |
| | | final int workerThreadCount; |
| | | |
| | | if (workersStr != null) { |
| | | workerThreadCount = Integer.parseInt(workersStr); |
| | | } else { |
| | | workerThreadCount = useWorkerThreadStrategy ? Math.max(5, (cpus * 2)) : 0; |
| | | } |
| | | |
| | | builder.setWorkerThreadPoolConfig(ThreadPoolConfig.defaultConfig().setCorePoolSize( |
| | | workerThreadCount).setMaxPoolSize(workerThreadCount).setPoolName( |
| | | "OpenDJ LDAP SDK Grizzly worker thread")); |
| | | } |
| | | |
| | | // Parse IO related options. |
| | | final String lingerStr = System.getProperty("org.forgerock.opendj.transport.linger"); |
| | | if (lingerStr != null) { |