org.wildfly.common.cpu.ProcessorInfo Java Examples

The following examples show how to use org.wildfly.common.cpu.ProcessorInfo. 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: BatchFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a default batch fraction.
 * <p>
 * Uses an {@code in-memory} job repository with the {@linkplain #DEFAULT_JOB_REPOSITORY_NAME default name}.
 * </p>
 *
 * <p>
 * Uses a default thread-pool with a calculated maximum number of threads based on the available number of processors. A
 * keep alive time of 30 seconds is used for the thread-pool.
 * </p>
 *
 * @return a new default batch fraction
 */
public static BatchFraction createDefaultFraction() {
    final BatchFraction fraction = new BatchFraction();
    final InMemoryJobRepository<?> jobRepository = new InMemoryJobRepository<>(DEFAULT_JOB_REPOSITORY_NAME);
    fraction.inMemoryJobRepository(jobRepository)
            .defaultJobRepository(jobRepository.getKey());

    // Default thread-pool
    final ThreadPool<?> threadPool = new ThreadPool<>(DEFAULT_THREAD_POOL_NAME);
    threadPool.maxThreads(ProcessorInfo.availableProcessors())
            .keepaliveTime("time", "30")
            .keepaliveTime("unit", "seconds");
    fraction.threadPool(threadPool)
            .defaultThreadPool(threadPool.getKey());

    return fraction;

}
 
Example #3
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 #4
Source File: IOSubsystem20TestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testRuntime() throws Exception {
    KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization())
            .setSubsystemXml(getSubsystemXml());
    KernelServices mainServices = builder.build();
    if (!mainServices.isSuccessfulBoot()) {
        Assert.fail(String.valueOf(mainServices.getBootError()));
    }
    ServiceController<XnioWorker> workerServiceController = (ServiceController<XnioWorker>) mainServices.getContainer().getService(IOServices.WORKER.append("default"));
    workerServiceController.setMode(ServiceController.Mode.ACTIVE);
    workerServiceController.awaitValue();
    XnioWorker worker = workerServiceController.getService().getValue();
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 2, worker.getIoThreadCount());
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 16, worker.getOption(Options.WORKER_TASK_MAX_THREADS).intValue());
    PathAddress addr = PathAddress.parseCLIStyleAddress("/subsystem=io/worker=default");
    ModelNode op = Util.createOperation("read-resource", addr);
    op.get("include-runtime").set(true);
    mainServices.executeOperation(op);
}
 
Example #5
Source File: IOSubsystem11TestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testRuntime() throws Exception {
    KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization())
            .setSubsystemXml(getSubsystemXml());
    KernelServices mainServices = builder.build();
    if (!mainServices.isSuccessfulBoot()) {
        Assert.fail(mainServices.getBootError().toString());
    }
    ServiceController<XnioWorker> workerServiceController = (ServiceController<XnioWorker>) mainServices.getContainer().getService(IOServices.WORKER.append("default"));
    workerServiceController.setMode(ServiceController.Mode.ACTIVE);
    workerServiceController.awaitValue();
    XnioWorker worker = workerServiceController.getService().getValue();
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 2, worker.getIoThreadCount());
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 16, worker.getOption(Options.WORKER_TASK_MAX_THREADS).intValue());
    PathAddress addr = PathAddress.parseCLIStyleAddress("/subsystem=io/worker=default");
    ModelNode op = Util.createOperation("read-resource", addr);
    op.get("include-runtime").set(true);
    mainServices.executeOperation(op);
}
 
Example #6
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 #7
Source File: VertxHttpRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static void startServerAfterFailedStart() {
    if (closeTask != null) {
        //it is possible start failed after the server was started
        //we shut it down in this case, as we have no idea what state it is in
        final Handler<RoutingContext> prevHotReplacementHandler = hotReplacementHandler;
        shutDownDevMode();
        // reset back to the older hot replacement handler, so that it can be used
        // to watch any artifacts that need hot deployment to fix the reason which caused
        // the server start to fail
        hotReplacementHandler = prevHotReplacementHandler;
    }
    VertxConfiguration vertxConfiguration = new VertxConfiguration();
    ConfigInstantiator.handleObject(vertxConfiguration);
    Vertx vertx = VertxCoreRecorder.initialize(vertxConfiguration, null);

    try {
        HttpBuildTimeConfig buildConfig = new HttpBuildTimeConfig();
        ConfigInstantiator.handleObject(buildConfig);
        HttpConfiguration config = new HttpConfiguration();
        ConfigInstantiator.handleObject(config);
        Router router = Router.router(vertx);
        if (hotReplacementHandler != null) {
            router.route().order(Integer.MIN_VALUE).blockingHandler(hotReplacementHandler);
        }
        rootHandler = router;

        //we can't really do
        doServerStart(vertx, buildConfig, config, LaunchMode.DEVELOPMENT, new Supplier<Integer>() {
            @Override
            public Integer get() {
                return ProcessorInfo.availableProcessors() * 2; //this is dev mode, so the number of IO threads not always being 100% correct does not really matter in this case
            }
        }, null);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #8
Source File: AbstractInstallationReporter.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Create a ModelNode representing the CPU the instance is running on.
 *
 * @return a ModelNode representing the CPU the instance is running on.
 * @throws OperationFailedException
 */
private ModelNode createCPUNode() throws OperationFailedException {
    ModelNode cpu = new ModelNode().setEmptyObject();
    cpu.get(ARCH).set(getProperty("os.arch"));
    cpu.get(AVAILABLE_PROCESSORS).set(ProcessorInfo.availableProcessors());
    return cpu;
}
 
Example #9
Source File: IOSubsystem10TestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRuntime() throws Exception {
    KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization())
            .setSubsystemXml(getSubsystemXml());
    KernelServices mainServices = builder.build();
    if (!mainServices.isSuccessfulBoot()) {
        Assert.fail(mainServices.getBootError().toString());
    }
    ServiceController<XnioWorker> workerServiceController = (ServiceController<XnioWorker>) mainServices.getContainer().getService(IOServices.WORKER.append("default"));
    workerServiceController.setMode(ServiceController.Mode.ACTIVE);
    workerServiceController.awaitValue();
    XnioWorker worker = workerServiceController.getService().getValue();
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 2, worker.getIoThreadCount());
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 16, worker.getOption(Options.WORKER_TASK_MAX_THREADS).intValue());
}
 
Example #10
Source File: IOSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRuntime() throws Exception {
    KernelServices mainServices = startKernelServices(getSubsystemXml());
    XnioWorker worker = startXnioWorker(mainServices);
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 2, worker.getIoThreadCount());
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 16, worker.getOption(Options.WORKER_TASK_MAX_THREADS).intValue());
    PathAddress addr = PathAddress.parseCLIStyleAddress("/subsystem=io/worker=default");
    ModelNode op = Util.createOperation("read-resource", addr);
    op.get("include-runtime").set(true);
    mainServices.executeOperation(op);
}
 
Example #11
Source File: AbstractEventLoggerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static ExecutorService createExecutor() {
    return Executors.newFixedThreadPool(Math.max(2, ProcessorInfo.availableProcessors() - 2));
}
 
Example #12
Source File: ThreadsParser.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static int getScaledCount(BigDecimal count, BigDecimal perCpu) {
    return count.add(perCpu.multiply(BigDecimal.valueOf((long) ProcessorInfo.availableProcessors()), MathContext.DECIMAL64), MathContext.DECIMAL64).round(MathContext.DECIMAL64).intValueExact();
}
 
Example #13
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();
}