Search in sources :

Example 6 with ScalingExecutorBuilder

use of org.opensearch.threadpool.ScalingExecutorBuilder in project asynchronous-search by opensearch-project.

the class AsynchronousSearchServiceFreeContextTests method createObjects.

@Before
public void createObjects() {
    Settings settings = Settings.builder().put("node.name", "test").put("cluster.name", "ClusterServiceTests").put(AsynchronousSearchActiveStore.NODE_CONCURRENT_RUNNING_SEARCHES_SETTING.getKey(), 10).build();
    final Set<Setting<?>> settingsSet = Stream.concat(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), Stream.of(AsynchronousSearchActiveStore.NODE_CONCURRENT_RUNNING_SEARCHES_SETTING, AsynchronousSearchService.MAX_KEEP_ALIVE_SETTING, AsynchronousSearchService.PERSIST_SEARCH_FAILURES_SETTING, AsynchronousSearchService.MAX_SEARCH_RUNNING_TIME_SETTING, AsynchronousSearchService.MAX_WAIT_FOR_COMPLETION_TIMEOUT_SETTING)).collect(Collectors.toSet());
    final int availableProcessors = OpenSearchExecutors.allocatedProcessors(settings);
    List<ExecutorBuilder<?>> executorBuilders = new ArrayList<>();
    executorBuilders.add(new ScalingExecutorBuilder(OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME, 1, Math.min(2 * availableProcessors, Math.max(128, 512)), TimeValue.timeValueMinutes(30)));
    executorBuilder = executorBuilders.get(0);
    clusterSettings = new ClusterSettings(settings, settingsSet);
    persisted = false;
    userMatches = false;
    simulateTimedOut = false;
    simulateUncheckedException = false;
}
Also used : ExecutorBuilder(org.opensearch.threadpool.ExecutorBuilder) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Setting(org.opensearch.common.settings.Setting) ArrayList(java.util.ArrayList) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before)

Example 7 with ScalingExecutorBuilder

use of org.opensearch.threadpool.ScalingExecutorBuilder in project asynchronous-search by opensearch-project.

the class AsynchronousSearchServiceUpdateContextTests method createObjects.

@Before
public void createObjects() {
    Settings settings = Settings.builder().put("node.name", "test").put("cluster.name", "ClusterServiceTests").put(AsynchronousSearchActiveStore.NODE_CONCURRENT_RUNNING_SEARCHES_SETTING.getKey(), 10).build();
    final Set<Setting<?>> settingsSet = Stream.concat(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), Stream.of(AsynchronousSearchActiveStore.NODE_CONCURRENT_RUNNING_SEARCHES_SETTING, AsynchronousSearchService.MAX_KEEP_ALIVE_SETTING, AsynchronousSearchService.PERSIST_SEARCH_FAILURES_SETTING, AsynchronousSearchService.MAX_SEARCH_RUNNING_TIME_SETTING, AsynchronousSearchService.MAX_WAIT_FOR_COMPLETION_TIMEOUT_SETTING)).collect(Collectors.toSet());
    final int availableProcessors = OpenSearchExecutors.allocatedProcessors(settings);
    List<ExecutorBuilder<?>> executorBuilders = new ArrayList<>();
    executorBuilders.add(new ScalingExecutorBuilder(OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME, 1, Math.min(2 * availableProcessors, Math.max(128, 512)), TimeValue.timeValueMinutes(30)));
    executorBuilder = executorBuilders.get(0);
    clusterSettings = new ClusterSettings(settings, settingsSet);
    simulateUncheckedException = false;
    simulateTimedOut = false;
    docNotFound = false;
}
Also used : ExecutorBuilder(org.opensearch.threadpool.ExecutorBuilder) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Setting(org.opensearch.common.settings.Setting) ArrayList(java.util.ArrayList) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before)

Example 8 with ScalingExecutorBuilder

use of org.opensearch.threadpool.ScalingExecutorBuilder in project asynchronous-search by opensearch-project.

the class AsynchronousSearchStateMachineTests method createObjects.

@Before
public void createObjects() {
    settings = Settings.builder().put("node.name", "test").put("cluster.name", "ClusterServiceTests").put(AsynchronousSearchActiveStore.NODE_CONCURRENT_RUNNING_SEARCHES_SETTING.getKey(), 10).put(AsynchronousSearchService.PERSIST_SEARCH_FAILURES_SETTING.getKey(), true).build();
    final Set<Setting<?>> settingsSet = Stream.concat(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), Stream.of(AsynchronousSearchActiveStore.NODE_CONCURRENT_RUNNING_SEARCHES_SETTING, AsynchronousSearchService.MAX_SEARCH_RUNNING_TIME_SETTING, AsynchronousSearchService.PERSIST_SEARCH_FAILURES_SETTING, AsynchronousSearchService.MAX_KEEP_ALIVE_SETTING, AsynchronousSearchService.MAX_WAIT_FOR_COMPLETION_TIMEOUT_SETTING)).collect(Collectors.toSet());
    final int availableProcessors = OpenSearchExecutors.allocatedProcessors(settings);
    List<ExecutorBuilder<?>> executorBuilders = new ArrayList<>();
    executorBuilders.add(new ScalingExecutorBuilder(AsynchronousSearchPlugin.OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME, 1, Math.min(2 * availableProcessors, Math.max(128, 512)), TimeValue.timeValueMinutes(30)));
    executorBuilder = executorBuilders.get(0);
    clusterSettings = new ClusterSettings(settings, settingsSet);
}
Also used : ExecutorBuilder(org.opensearch.threadpool.ExecutorBuilder) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Setting(org.opensearch.common.settings.Setting) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 9 with ScalingExecutorBuilder

use of org.opensearch.threadpool.ScalingExecutorBuilder in project asynchronous-search by opensearch-project.

the class AsynchronousSearchActiveContextTests method testClosedContext.

public void testClosedContext() throws InterruptedException {
    TestThreadPool threadPool = null;
    try {
        int writeThreadPoolSize = randomIntBetween(1, 2);
        int writeThreadPoolQueueSize = randomIntBetween(1, 2);
        Settings settings = Settings.builder().put("thread_pool." + AsynchronousSearchPlugin.OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME + ".size", writeThreadPoolSize).put("thread_pool." + AsynchronousSearchPlugin.OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME + ".queue_size", writeThreadPoolQueueSize).build();
        final int availableProcessors = OpenSearchExecutors.allocatedProcessors(settings);
        ScalingExecutorBuilder scalingExecutorBuilder = new ScalingExecutorBuilder(AsynchronousSearchPlugin.OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME, 1, Math.min(2 * availableProcessors, Math.max(128, 512)), TimeValue.timeValueMinutes(30));
        threadPool = new TestThreadPool("Tests", settings, scalingExecutorBuilder);
        String node = UUID.randomUUID().toString();
        AsynchronousSearchProgressListener asProgressListener = mockAsynchronousSearchProgressListener(threadPool);
        AsynchronousSearchContextId asContextId = new AsynchronousSearchContextId(UUID.randomUUID().toString(), randomNonNegativeLong());
        boolean keepOnCompletion = randomBoolean();
        TimeValue keepAlive = TimeValue.timeValueDays(randomInt(100));
        AsynchronousSearchActiveContext context = new AsynchronousSearchActiveContext(asContextId, node, keepAlive, keepOnCompletion, threadPool, threadPool::absoluteTimeInMillis, asProgressListener, null, () -> true);
        AsynchronousSearchTask task = new AsynchronousSearchTask(randomNonNegativeLong(), "transport", SearchAction.NAME, TaskId.EMPTY_TASK_ID, emptyMap(), context, null, (c) -> {
        });
        context.setTask(task);
        assertEquals(task, context.getTask());
        assertEquals(task.getStartTime(), context.getStartTimeMillis());
        assertEquals(task.getStartTime() + keepAlive.getMillis(), context.getExpirationTimeMillis());
        assertTrue(context.isAlive());
        assertFalse(context.isExpired());
        expectThrows(SetOnce.AlreadySetException.class, () -> context.setTask(task));
        context.setState(AsynchronousSearchState.CLOSED);
        context.close();
        assertFalse(context.isAlive());
        expectThrows(AssertionError.class, () -> context.setExpirationTimeMillis(randomNonNegativeLong()));
        expectThrows(AssertionError.class, () -> context.setTask(task));
    } finally {
        ThreadPool.terminate(threadPool, 30, TimeUnit.SECONDS);
    }
}
Also used : AsynchronousSearchContextId(org.opensearch.search.asynchronous.context.AsynchronousSearchContextId) SetOnce(org.apache.lucene.util.SetOnce) Matchers.containsString(org.hamcrest.Matchers.containsString) TestThreadPool(org.opensearch.threadpool.TestThreadPool) AsynchronousSearchProgressListener(org.opensearch.search.asynchronous.listener.AsynchronousSearchProgressListener) AsynchronousSearchTask(org.opensearch.search.asynchronous.task.AsynchronousSearchTask) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) Settings(org.opensearch.common.settings.Settings) TimeValue(org.opensearch.common.unit.TimeValue)

Example 10 with ScalingExecutorBuilder

use of org.opensearch.threadpool.ScalingExecutorBuilder in project asynchronous-search by opensearch-project.

the class AsynchronousSearchActiveContextTests method testTaskBootstrap.

public void testTaskBootstrap() {
    TestThreadPool threadPool = null;
    try {
        int writeThreadPoolSize = randomIntBetween(1, 2);
        int writeThreadPoolQueueSize = randomIntBetween(1, 2);
        Settings settings = Settings.builder().put("thread_pool." + AsynchronousSearchPlugin.OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME + ".size", writeThreadPoolSize).put("thread_pool." + AsynchronousSearchPlugin.OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME + ".queue_size", writeThreadPoolQueueSize).build();
        final int availableProcessors = OpenSearchExecutors.allocatedProcessors(settings);
        ScalingExecutorBuilder scalingExecutorBuilder = new ScalingExecutorBuilder(AsynchronousSearchPlugin.OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME, 1, Math.min(2 * availableProcessors, Math.max(128, 512)), TimeValue.timeValueMinutes(30));
        threadPool = new TestThreadPool("Tests", settings, scalingExecutorBuilder);
        String node = UUID.randomUUID().toString();
        AsynchronousSearchProgressListener asProgressListener = mockAsynchronousSearchProgressListener(threadPool);
        AsynchronousSearchContextId asContextId = new AsynchronousSearchContextId(UUID.randomUUID().toString(), randomNonNegativeLong());
        boolean keepOnCompletion = randomBoolean();
        User user = TestClientUtils.randomUser();
        TimeValue keepAlive = TimeValue.timeValueDays(randomInt(100));
        AsynchronousSearchActiveContext context = new AsynchronousSearchActiveContext(asContextId, node, keepAlive, keepOnCompletion, threadPool, threadPool::absoluteTimeInMillis, asProgressListener, user, () -> true);
        SubmitAsynchronousSearchRequest request = new SubmitAsynchronousSearchRequest(new SearchRequest("test"));
        request.keepAlive(keepAlive);
        request.keepOnCompletion(keepOnCompletion);
        AsynchronousSearchTask task = new AsynchronousSearchTask(randomNonNegativeLong(), "transport", SearchAction.NAME, TaskId.EMPTY_TASK_ID, emptyMap(), context, request, (c) -> {
        });
        context.setTask(task);
        assertEquals(task, context.getTask());
        assertEquals(task.getStartTime(), context.getStartTimeMillis());
        assertEquals(task.getStartTime() + keepAlive.getMillis(), context.getExpirationTimeMillis());
        String description = task.getDescription();
        assertThat(description, containsString("[asynchronous search]"));
        assertThat(description, containsString("indices[test]"));
        assertThat(description, containsString("keep_alive[" + keepAlive + "]"));
        assertThat(description, containsString("keep_on_completion[" + keepOnCompletion + "]"));
        assertTrue(context.isAlive());
        assertFalse(context.isExpired());
        expectThrows(SetOnce.AlreadySetException.class, () -> context.setTask(task));
        if (keepOnCompletion) {
            assertTrue(context.shouldPersist());
        } else {
            assertFalse(context.shouldPersist());
        }
        assertTrue(user.equals(context.getUser()));
    } finally {
        ThreadPool.terminate(threadPool, 30, TimeUnit.SECONDS);
    }
}
Also used : SearchRequest(org.opensearch.action.search.SearchRequest) SubmitAsynchronousSearchRequest(org.opensearch.search.asynchronous.request.SubmitAsynchronousSearchRequest) User(org.opensearch.commons.authuser.User) SubmitAsynchronousSearchRequest(org.opensearch.search.asynchronous.request.SubmitAsynchronousSearchRequest) AsynchronousSearchContextId(org.opensearch.search.asynchronous.context.AsynchronousSearchContextId) SetOnce(org.apache.lucene.util.SetOnce) Matchers.containsString(org.hamcrest.Matchers.containsString) TestThreadPool(org.opensearch.threadpool.TestThreadPool) AsynchronousSearchProgressListener(org.opensearch.search.asynchronous.listener.AsynchronousSearchProgressListener) AsynchronousSearchTask(org.opensearch.search.asynchronous.task.AsynchronousSearchTask) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) Settings(org.opensearch.common.settings.Settings) TimeValue(org.opensearch.common.unit.TimeValue)

Aggregations

ScalingExecutorBuilder (org.opensearch.threadpool.ScalingExecutorBuilder)12 Settings (org.opensearch.common.settings.Settings)9 ArrayList (java.util.ArrayList)7 ExecutorBuilder (org.opensearch.threadpool.ExecutorBuilder)7 Before (org.junit.Before)6 ClusterSettings (org.opensearch.common.settings.ClusterSettings)6 Setting (org.opensearch.common.settings.Setting)6 TestThreadPool (org.opensearch.threadpool.TestThreadPool)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 TimeValue (org.opensearch.common.unit.TimeValue)4 AsynchronousSearchContextId (org.opensearch.search.asynchronous.context.AsynchronousSearchContextId)4 AsynchronousSearchProgressListener (org.opensearch.search.asynchronous.listener.AsynchronousSearchProgressListener)4 SetOnce (org.apache.lucene.util.SetOnce)2 User (org.opensearch.commons.authuser.User)2 AsynchronousSearchTask (org.opensearch.search.asynchronous.task.AsynchronousSearchTask)2 BeforeClass (org.junit.BeforeClass)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 SearchResponse (org.opensearch.action.search.SearchResponse)1 SubmitAsynchronousSearchRequest (org.opensearch.search.asynchronous.request.SubmitAsynchronousSearchRequest)1 InternalSearchResponse (org.opensearch.search.internal.InternalSearchResponse)1