Search in sources :

Example 1 with ExecutorConfiguration

use of org.apache.ignite.configuration.ExecutorConfiguration in project ignite by apache.

the class CustomThreadPool method customPool.

void customPool() {
    // tag::pool-config[]
    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setExecutorConfiguration(new ExecutorConfiguration("myPool").setSize(16));
    // end::pool-config[]
    Ignite ignite = Ignition.start(cfg);
    ignite.compute().run(new OuterRunnable());
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignite(org.apache.ignite.Ignite) ExecutorConfiguration(org.apache.ignite.configuration.ExecutorConfiguration)

Example 2 with ExecutorConfiguration

use of org.apache.ignite.configuration.ExecutorConfiguration in project ignite by apache.

the class PoolProcessor method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    super.start();
    IgniteConfiguration cfg = ctx.config();
    UncaughtExceptionHandler oomeHnd = ctx.uncaughtExceptionHandler();
    UncaughtExceptionHandler excHnd = new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            ctx.failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
        }
    };
    validateThreadPoolSize(cfg.getPublicThreadPoolSize(), "public");
    execSvc = createExecutorService("pub", cfg.getIgniteInstanceName(), cfg.getPublicThreadPoolSize(), cfg.getPublicThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.PUBLIC_POOL, oomeHnd);
    execSvc.allowCoreThreadTimeOut(true);
    validateThreadPoolSize(cfg.getServiceThreadPoolSize(), "service");
    svcExecSvc = createExecutorService("svc", cfg.getIgniteInstanceName(), cfg.getServiceThreadPoolSize(), cfg.getServiceThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.SERVICE_POOL, oomeHnd);
    svcExecSvc.allowCoreThreadTimeOut(true);
    validateThreadPoolSize(cfg.getSystemThreadPoolSize(), "system");
    sysExecSvc = createExecutorService("sys", cfg.getIgniteInstanceName(), cfg.getSystemThreadPoolSize(), cfg.getSystemThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.SYSTEM_POOL, oomeHnd);
    sysExecSvc.allowCoreThreadTimeOut(true);
    validateThreadPoolSize(cfg.getStripedPoolSize(), "stripedPool");
    WorkersRegistry workerRegistry = ctx.workersRegistry();
    stripedExecSvc = createStripedExecutor(cfg.getStripedPoolSize(), cfg.getIgniteInstanceName(), "sys", log, new IgniteInClosure<Throwable>() {

        @Override
        public void apply(Throwable t) {
            ctx.failure().process(new FailureContext(SYSTEM_WORKER_TERMINATION, t));
        }
    }, false, workerRegistry, cfg.getFailureDetectionTimeout());
    // Note that since we use 'LinkedBlockingQueue', number of
    // maximum threads has no effect.
    // Note, that we do not pre-start threads here as management pool may
    // not be needed.
    validateThreadPoolSize(cfg.getManagementThreadPoolSize(), "management");
    mgmtExecSvc = createExecutorService("mgmt", cfg.getIgniteInstanceName(), cfg.getManagementThreadPoolSize(), cfg.getManagementThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.MANAGEMENT_POOL, oomeHnd);
    mgmtExecSvc.allowCoreThreadTimeOut(true);
    // Note that since we use 'LinkedBlockingQueue', number of
    // maximum threads has no effect.
    // Note, that we do not pre-start threads here as class loading pool may
    // not be needed.
    validateThreadPoolSize(cfg.getPeerClassLoadingThreadPoolSize(), "peer class loading");
    p2pExecSvc = createExecutorService("p2p", cfg.getIgniteInstanceName(), cfg.getPeerClassLoadingThreadPoolSize(), cfg.getPeerClassLoadingThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.P2P_POOL, oomeHnd);
    p2pExecSvc.allowCoreThreadTimeOut(true);
    dataStreamerExecSvc = createStripedExecutor(cfg.getDataStreamerThreadPoolSize(), cfg.getIgniteInstanceName(), "data-streamer", log, new IgniteInClosure<Throwable>() {

        @Override
        public void apply(Throwable t) {
            ctx.failure().process(new FailureContext(SYSTEM_WORKER_TERMINATION, t));
        }
    }, true, workerRegistry, cfg.getFailureDetectionTimeout());
    // Note that we do not pre-start threads here as this pool may not be needed.
    validateThreadPoolSize(cfg.getAsyncCallbackPoolSize(), "async callback");
    callbackExecSvc = new IgniteStripedThreadPoolExecutor(cfg.getAsyncCallbackPoolSize(), cfg.getIgniteInstanceName(), "callback", oomeHnd, false, 0);
    if (cfg.getConnectorConfiguration() != null) {
        validateThreadPoolSize(cfg.getConnectorConfiguration().getThreadPoolSize(), "connector");
        restExecSvc = createExecutorService("rest", cfg.getIgniteInstanceName(), cfg.getConnectorConfiguration().getThreadPoolSize(), cfg.getConnectorConfiguration().getThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, oomeHnd);
        restExecSvc.allowCoreThreadTimeOut(true);
    }
    validateThreadPoolSize(cfg.getUtilityCacheThreadPoolSize(), "utility cache");
    utilityCacheExecSvc = createExecutorService("utility", cfg.getIgniteInstanceName(), cfg.getUtilityCacheThreadPoolSize(), cfg.getUtilityCacheThreadPoolSize(), cfg.getUtilityCacheKeepAliveTime(), new LinkedBlockingQueue<>(), GridIoPolicy.UTILITY_CACHE_POOL, oomeHnd);
    utilityCacheExecSvc.allowCoreThreadTimeOut(true);
    affExecSvc = createExecutorService("aff", cfg.getIgniteInstanceName(), 1, 1, DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.AFFINITY_POOL, oomeHnd);
    affExecSvc.allowCoreThreadTimeOut(true);
    if (IgniteComponentType.INDEXING.inClassPath()) {
        int cpus = Runtime.getRuntime().availableProcessors();
        idxExecSvc = createExecutorService("idx", cfg.getIgniteInstanceName(), cpus, cpus * 2, 3000L, new LinkedBlockingQueue<>(1000), GridIoPolicy.IDX_POOL, oomeHnd);
        int buildIdxThreadPoolSize = cfg.getBuildIndexThreadPoolSize();
        validateThreadPoolSize(buildIdxThreadPoolSize, "build-idx");
        buildIdxExecSvc = createExecutorService("build-idx-runner", cfg.getIgniteInstanceName(), buildIdxThreadPoolSize, buildIdxThreadPoolSize, DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, oomeHnd);
        buildIdxExecSvc.allowCoreThreadTimeOut(true);
    }
    validateThreadPoolSize(cfg.getQueryThreadPoolSize(), "query");
    qryExecSvc = createExecutorService("query", cfg.getIgniteInstanceName(), cfg.getQueryThreadPoolSize(), cfg.getQueryThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.QUERY_POOL, oomeHnd);
    qryExecSvc.allowCoreThreadTimeOut(true);
    schemaExecSvc = createExecutorService("schema", cfg.getIgniteInstanceName(), 2, 2, DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.SCHEMA_POOL, oomeHnd);
    schemaExecSvc.allowCoreThreadTimeOut(true);
    validateThreadPoolSize(cfg.getRebalanceThreadPoolSize(), "rebalance");
    rebalanceExecSvc = createExecutorService("rebalance", cfg.getIgniteInstanceName(), cfg.getRebalanceThreadPoolSize(), cfg.getRebalanceThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, excHnd);
    rebalanceExecSvc.allowCoreThreadTimeOut(true);
    if (CU.isPersistenceEnabled(ctx.config())) {
        snpExecSvc = createExecutorService(SNAPSHOT_RUNNER_THREAD_PREFIX, cfg.getIgniteInstanceName(), cfg.getSnapshotThreadPoolSize(), cfg.getSnapshotThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, excHnd);
        snpExecSvc.allowCoreThreadTimeOut(true);
        reencryptExecSvc = createExecutorService("reencrypt", ctx.igniteInstanceName(), 1, 1, DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, oomeHnd);
        reencryptExecSvc.allowCoreThreadTimeOut(true);
    }
    if (cfg.getClientConnectorConfiguration() != null) {
        thinClientExec = new IgniteThreadPoolExecutor("client-connector", cfg.getIgniteInstanceName(), cfg.getClientConnectorConfiguration().getThreadPoolSize(), cfg.getClientConnectorConfiguration().getThreadPoolSize(), 0, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, oomeHnd);
    }
    rebalanceStripedExecSvc = createStripedThreadPoolExecutor(cfg.getRebalanceThreadPoolSize(), cfg.getIgniteInstanceName(), "rebalance-striped", excHnd, true, DFLT_THREAD_KEEP_ALIVE_TIME);
    if (!F.isEmpty(cfg.getExecutorConfiguration())) {
        validateCustomExecutorsConfiguration(cfg.getExecutorConfiguration());
        customExecs = new HashMap<>();
        for (ExecutorConfiguration execCfg : cfg.getExecutorConfiguration()) {
            ThreadPoolExecutor exec = createExecutorService(execCfg.getName(), cfg.getIgniteInstanceName(), execCfg.getSize(), execCfg.getSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, oomeHnd);
            customExecs.put(execCfg.getName(), exec);
        }
    }
}
Also used : IgniteStripedThreadPoolExecutor(org.apache.ignite.thread.IgniteStripedThreadPoolExecutor) WorkersRegistry(org.apache.ignite.internal.worker.WorkersRegistry) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ExecutorConfiguration(org.apache.ignite.configuration.ExecutorConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) FailureContext(org.apache.ignite.failure.FailureContext) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) SecurityAwareStripedThreadPoolExecutor(org.apache.ignite.internal.processors.security.thread.SecurityAwareStripedThreadPoolExecutor) SecurityAwareThreadPoolExecutor(org.apache.ignite.internal.processors.security.thread.SecurityAwareThreadPoolExecutor) IgniteStripedThreadPoolExecutor(org.apache.ignite.thread.IgniteStripedThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)

Example 3 with ExecutorConfiguration

use of org.apache.ignite.configuration.ExecutorConfiguration in project ignite by apache.

the class GridMBeansTest method getConfiguration.

/**
 * {@inheritDoc}
 *
 * This implementation registers adds custom executors to the configuration.
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setExecutorConfiguration(new ExecutorConfiguration(CUSTOM_EXECUTOR_0), new ExecutorConfiguration(CUSTOM_EXECUTOR_1));
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ExecutorConfiguration(org.apache.ignite.configuration.ExecutorConfiguration)

Example 4 with ExecutorConfiguration

use of org.apache.ignite.configuration.ExecutorConfiguration in project ignite by apache.

the class GridNodeMetricsLogSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setMetricsLogFrequency(1000);
    cfg.setExecutorConfiguration(new ExecutorConfiguration(CUSTOM_EXECUTOR_0), new ExecutorConfiguration(CUSTOM_EXECUTOR_1));
    cfg.setGridLogger(strLog);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ExecutorConfiguration(org.apache.ignite.configuration.ExecutorConfiguration)

Example 5 with ExecutorConfiguration

use of org.apache.ignite.configuration.ExecutorConfiguration in project ignite by apache.

the class IgniteComputeCustomExecutorConfigurationSelfTest method testConfigurations.

/**
 * @throws Exception If failed.
 */
@Test
public void testConfigurations() throws Exception {
    try {
        checkStartWithInvalidConfiguration(getConfiguration("node0").setExecutorConfiguration(new ExecutorConfiguration()));
        checkStartWithInvalidConfiguration(getConfiguration("node0").setExecutorConfiguration(new ExecutorConfiguration("")));
        checkStartWithInvalidConfiguration(getConfiguration("node0").setExecutorConfiguration(new ExecutorConfiguration("exec").setSize(-1)));
        checkStartWithInvalidConfiguration(getConfiguration("node0").setExecutorConfiguration(new ExecutorConfiguration("exec").setSize(0)));
    } finally {
        Ignition.stopAll(true);
    }
}
Also used : ExecutorConfiguration(org.apache.ignite.configuration.ExecutorConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ExecutorConfiguration (org.apache.ignite.configuration.ExecutorConfiguration)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 BinaryBasicNameMapper (org.apache.ignite.binary.BinaryBasicNameMapper)2 AtomicConfiguration (org.apache.ignite.configuration.AtomicConfiguration)2 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)2 TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)2 NoOpFailureHandler (org.apache.ignite.failure.NoOpFailureHandler)2 StopNodeFailureHandler (org.apache.ignite.failure.StopNodeFailureHandler)2 StopNodeOrHaltFailureHandler (org.apache.ignite.failure.StopNodeOrHaltFailureHandler)2 PlatformDotNetBinaryConfiguration (org.apache.ignite.platform.dotnet.PlatformDotNetBinaryConfiguration)2 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)2 NoopEventStorageSpi (org.apache.ignite.spi.eventstorage.NoopEventStorageSpi)2 MemoryEventStorageSpi (org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi)2 Serializable (java.io.Serializable)1 UncaughtExceptionHandler (java.lang.Thread.UncaughtExceptionHandler)1 Map (java.util.Map)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1