Search in sources :

Example 1 with EsThreadPoolExecutor

use of org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor in project elasticsearch by elastic.

the class ScalingThreadPoolTests method testScalingThreadPoolConfiguration.

public void testScalingThreadPoolConfiguration() throws InterruptedException {
    final String threadPoolName = randomThreadPool(ThreadPool.ThreadPoolType.SCALING);
    final Settings.Builder builder = Settings.builder();
    final int core;
    if (randomBoolean()) {
        core = randomIntBetween(0, 8);
        builder.put("thread_pool." + threadPoolName + ".core", core);
    } else {
        // the defaults
        core = "generic".equals(threadPoolName) ? 4 : 1;
    }
    final int maxBasedOnNumberOfProcessors;
    if (randomBoolean()) {
        final int processors = randomIntBetween(1, 64);
        maxBasedOnNumberOfProcessors = expectedSize(threadPoolName, processors);
        builder.put("processors", processors);
    } else {
        maxBasedOnNumberOfProcessors = expectedSize(threadPoolName, Math.min(32, Runtime.getRuntime().availableProcessors()));
    }
    final int expectedMax;
    if (maxBasedOnNumberOfProcessors < core || randomBoolean()) {
        expectedMax = randomIntBetween(Math.max(1, core), 16);
        builder.put("thread_pool." + threadPoolName + ".max", expectedMax);
    } else {
        expectedMax = maxBasedOnNumberOfProcessors;
    }
    final long keepAlive;
    if (randomBoolean()) {
        keepAlive = randomIntBetween(1, 300);
        builder.put("thread_pool." + threadPoolName + ".keep_alive", keepAlive + "s");
    } else {
        // the defaults
        keepAlive = "generic".equals(threadPoolName) ? 30 : 300;
    }
    runScalingThreadPoolTest(builder.build(), (clusterSettings, threadPool) -> {
        final Executor executor = threadPool.executor(threadPoolName);
        assertThat(executor, instanceOf(EsThreadPoolExecutor.class));
        final EsThreadPoolExecutor esThreadPoolExecutor = (EsThreadPoolExecutor) executor;
        final ThreadPool.Info info = info(threadPool, threadPoolName);
        assertThat(info.getName(), equalTo(threadPoolName));
        assertThat(info.getThreadPoolType(), equalTo(ThreadPool.ThreadPoolType.SCALING));
        assertThat(info.getKeepAlive().seconds(), equalTo(keepAlive));
        assertThat(esThreadPoolExecutor.getKeepAliveTime(TimeUnit.SECONDS), equalTo(keepAlive));
        assertNull(info.getQueueSize());
        assertThat(esThreadPoolExecutor.getQueue().remainingCapacity(), equalTo(Integer.MAX_VALUE));
        assertThat(info.getMin(), equalTo(core));
        assertThat(esThreadPoolExecutor.getCorePoolSize(), equalTo(core));
        assertThat(info.getMax(), equalTo(expectedMax));
        assertThat(esThreadPoolExecutor.getMaximumPoolSize(), equalTo(expectedMax));
    });
}
Also used : Executor(java.util.concurrent.Executor) EsThreadPoolExecutor(org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor) EsThreadPoolExecutor(org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 2 with EsThreadPoolExecutor

use of org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor in project elasticsearch by elastic.

the class UpdateThreadPoolSettingsTests method testFixedExecutorType.

public void testFixedExecutorType() throws InterruptedException {
    String threadPoolName = randomThreadPool(ThreadPool.ThreadPoolType.FIXED);
    ThreadPool threadPool = null;
    try {
        int expectedSize = getExpectedThreadPoolSize(Settings.EMPTY, threadPoolName, 15);
        Settings nodeSettings = Settings.builder().put("node.name", "testFixedExecutorType").put("thread_pool." + threadPoolName + ".size", expectedSize).build();
        threadPool = new ThreadPool(nodeSettings);
        assertThat(threadPool.executor(threadPoolName), instanceOf(EsThreadPoolExecutor.class));
        assertEquals(info(threadPool, threadPoolName).getThreadPoolType(), ThreadPool.ThreadPoolType.FIXED);
        assertThat(threadPool.executor(threadPoolName), instanceOf(EsThreadPoolExecutor.class));
        assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getCorePoolSize(), equalTo(expectedSize));
        assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getMaximumPoolSize(), equalTo(expectedSize));
        assertThat(info(threadPool, threadPoolName).getMin(), equalTo(expectedSize));
        assertThat(info(threadPool, threadPoolName).getMax(), equalTo(expectedSize));
        // keep alive does not apply to fixed thread pools
        assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getKeepAliveTime(TimeUnit.MINUTES), equalTo(0L));
    } finally {
        terminateThreadPoolIfNeeded(threadPool);
    }
}
Also used : Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) EsThreadPoolExecutor(org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Settings (org.elasticsearch.common.settings.Settings)2 EsThreadPoolExecutor (org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor)2 Executor (java.util.concurrent.Executor)1 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Matchers.hasToString (org.hamcrest.Matchers.hasToString)1