Java Code Examples for org.wildfly.common.cpu.ProcessorInfo#availableProcessors()

The following examples show how to use org.wildfly.common.cpu.ProcessorInfo#availableProcessors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutorRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static EnhancedQueueExecutor createExecutor(ThreadPoolConfig threadPoolConfig) {
    final JBossThreadFactory threadFactory = new JBossThreadFactory(new ThreadGroup("executor"), Boolean.TRUE, null,
            "executor-thread-%t", JBossExecutors.loggingExceptionHandler("org.jboss.executor.uncaught"), null);
    final EnhancedQueueExecutor.Builder builder = new EnhancedQueueExecutor.Builder()
            .setRegisterMBean(false)
            .setHandoffExecutor(JBossExecutors.rejectingExecutor())
            .setThreadFactory(JBossExecutors.resettingThreadFactory(threadFactory));
    final int cpus = ProcessorInfo.availableProcessors();
    // run time config variables
    builder.setCorePoolSize(threadPoolConfig.coreThreads);
    builder.setMaximumPoolSize(threadPoolConfig.maxThreads.orElse(Math.max(8 * cpus, 200)));
    if (threadPoolConfig.queueSize.isPresent()) {
        if (threadPoolConfig.queueSize.getAsInt() < 0) {
            builder.setMaximumQueueSize(Integer.MAX_VALUE);
        } else {
            builder.setMaximumQueueSize(threadPoolConfig.queueSize.getAsInt());
        }
    }
    builder.setGrowthResistance(threadPoolConfig.growthResistance);
    builder.setKeepAliveTime(threadPoolConfig.keepAliveTime);
    return builder.build();
}
 
Example 2
Source File: ServerEnvironment.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Determine the number of threads to use for the bootstrap service container. This reads
 * the {@link #BOOTSTRAP_MAX_THREADS} system property and if not set, defaults to 2*cpus.
 * @see Runtime#availableProcessors()
 * @return the maximum number of threads to use for the bootstrap service container.
 */
public static int getBootstrapMaxThreads() {
    // Base the bootstrap thread on proc count if not specified
    int cpuCount = ProcessorInfo.availableProcessors();
    int defaultThreads = cpuCount * 2;
    String maxThreads = WildFlySecurityManager.getPropertyPrivileged(BOOTSTRAP_MAX_THREADS, null);
    if (maxThreads != null && maxThreads.length() > 0) {
        try {
            int max = Integer.decode(maxThreads);
            defaultThreads = Math.max(max, 1);
        } catch(NumberFormatException ex) {
            ServerLogger.ROOT_LOGGER.failedToParseCommandLineInteger(BOOTSTRAP_MAX_THREADS, maxThreads);
        }
    }
    return defaultThreads;
}
 
Example 3
Source File: VertxCoreRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static int calculateDefaultIOThreads() {
    //we only allow one event loop per 10mb of ram at the most
    //its hard to say what this number should be, but it is also obvious
    //that for constrained environments we don't want a lot of event loops
    //lets start with 10mb and adjust as needed
    int recommended = ProcessorInfo.availableProcessors() * 2;
    long mem = Runtime.getRuntime().maxMemory();
    long memInMb = mem / (1024 * 1024);
    long maxAllowed = memInMb / 10;

    return (int) Math.max(2, Math.min(maxAllowed, recommended));
}
 
Example 4
Source File: WorkerAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static int getCpuCount(){
    return ProcessorInfo.availableProcessors();
}