Search in sources :

Example 1 with ExecutorBuilder

use of org.opensearch.threadpool.ExecutorBuilder in project job-scheduler by opensearch-project.

the class JobSchedulerPlugin method getExecutorBuilders.

@Override
public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
    final int processorCount = OpenSearchExecutors.allocatedProcessors(settings);
    List<ExecutorBuilder<?>> executorBuilders = new ArrayList<>();
    executorBuilders.add(new FixedExecutorBuilder(settings, OPEN_DISTRO_JOB_SCHEDULER_THREAD_POOL_NAME, processorCount, 200, "opendistro.jobscheduler.threadpool"));
    return executorBuilders;
}
Also used : ExecutorBuilder(org.opensearch.threadpool.ExecutorBuilder) FixedExecutorBuilder(org.opensearch.threadpool.FixedExecutorBuilder) ArrayList(java.util.ArrayList) FixedExecutorBuilder(org.opensearch.threadpool.FixedExecutorBuilder)

Example 2 with ExecutorBuilder

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

the class AsynchronousSearchPlugin method getExecutorBuilders.

// TODO Revisit these once we performance test the feature
@Override
public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
    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)));
    return executorBuilders;
}
Also used : ExecutorBuilder(org.opensearch.threadpool.ExecutorBuilder) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) ArrayList(java.util.ArrayList)

Example 3 with ExecutorBuilder

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

the class AsynchronousSearchServiceTests method testFindContext.

public void testFindContext() throws InterruptedException {
    DiscoveryNode discoveryNode = new DiscoveryNode("node", OpenSearchTestCase.buildNewFakeTransportAddress(), emptyMap(), DiscoveryNodeRole.BUILT_IN_ROLES, Version.CURRENT);
    ThreadPool testThreadPool = null;
    try {
        testThreadPool = new TestThreadPool(AsynchronousSearchPlugin.OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME, executorBuilder);
        ClusterService mockClusterService = TestUtils.createClusterService(settings, testThreadPool, discoveryNode, clusterSettings);
        FakeClient fakeClient = new FakeClient(testThreadPool);
        AsynchronousSearchActiveStore asActiveStore = new AsynchronousSearchActiveStore(mockClusterService);
        AsynchronousSearchPersistenceService persistenceService = new AsynchronousSearchPersistenceService(fakeClient, mockClusterService, testThreadPool);
        AsynchronousSearchService asService = new AsynchronousSearchService(persistenceService, asActiveStore, fakeClient, mockClusterService, testThreadPool, new InternalAsynchronousSearchStats(), new NamedWriteableRegistry(emptyList()));
        TimeValue keepAlive = timeValueHours(9);
        boolean keepOnCompletion = randomBoolean();
        User user1 = TestClientUtils.randomUser();
        User user2 = TestClientUtils.randomUser();
        SearchRequest searchRequest = new SearchRequest();
        SubmitAsynchronousSearchRequest submitAsynchronousSearchRequest = new SubmitAsynchronousSearchRequest(searchRequest);
        submitAsynchronousSearchRequest.keepOnCompletion(keepOnCompletion);
        submitAsynchronousSearchRequest.keepAlive(keepAlive);
        AsynchronousSearchContext context = asService.createAndStoreContext(submitAsynchronousSearchRequest, System.currentTimeMillis(), () -> null, user1);
        assertTrue(context instanceof AsynchronousSearchActiveContext);
        AsynchronousSearchActiveContext asActiveContext = (AsynchronousSearchActiveContext) context;
        assertNull(asActiveContext.getTask());
        assertNull(asActiveContext.getAsynchronousSearchId());
        assertEquals(asActiveContext.getAsynchronousSearchState(), AsynchronousSearchState.INIT);
        assertEquals(asActiveContext.getUser(), user1);
        // bootstrap search
        AsynchronousSearchTask task = new AsynchronousSearchTask(randomNonNegativeLong(), "transport", SearchAction.NAME, TaskId.EMPTY_TASK_ID, emptyMap(), (AsynchronousSearchActiveContext) context, null, (c) -> {
        });
        asService.bootstrapSearch(task, context.getContextId());
        assertEquals(asActiveContext.getTask(), task);
        assertEquals(asActiveContext.getStartTimeMillis(), task.getStartTime());
        assertEquals(asActiveContext.getExpirationTimeMillis(), task.getStartTime() + keepAlive.millis());
        assertEquals(asActiveContext.getAsynchronousSearchState(), AsynchronousSearchState.RUNNING);
        CountDownLatch findContextLatch = new CountDownLatch(3);
        ActionListener<AsynchronousSearchContext> expectedSuccessfulActive = new LatchedActionListener<>(wrap(r -> {
            assertTrue(r instanceof AsynchronousSearchActiveContext);
            assertEquals(r, context);
        }, e -> fail("Find context shouldn't have failed. " + e.getMessage())), findContextLatch);
        ActionListener<AsynchronousSearchContext> expectedSecurityException = new LatchedActionListener<>(wrap(r -> fail("Expecting security exception"), e -> assertTrue(e instanceof ResourceNotFoundException)), findContextLatch);
        asService.findContext(asActiveContext.getAsynchronousSearchId(), asActiveContext.getContextId(), user1, expectedSuccessfulActive);
        asService.findContext(asActiveContext.getAsynchronousSearchId(), asActiveContext.getContextId(), user2, expectedSecurityException);
        asService.findContext(asActiveContext.getAsynchronousSearchId(), asActiveContext.getContextId(), null, expectedSuccessfulActive);
        findContextLatch.await();
        AsynchronousSearchProgressListener asProgressListener = asActiveContext.getAsynchronousSearchProgressListener();
        boolean success = randomBoolean();
        if (success) {
            // successful search response
            asProgressListener.onResponse(getMockSearchResponse());
        } else {
            // exception occurred in search
            asProgressListener.onFailure(new RuntimeException("test"));
        }
        waitUntil(() -> asService.getAllActiveContexts().isEmpty());
        if (keepOnCompletion) {
            // persist to disk
            assertEquals(1, fakeClient.persistenceCount.intValue());
        } else {
            assertEquals(fakeClient.persistenceCount, Integer.valueOf(0));
            CountDownLatch freeContextLatch = new CountDownLatch(1);
            asService.findContext(context.getAsynchronousSearchId(), context.getContextId(), null, new LatchedActionListener<>(wrap(r -> fail("No context should have been found but found " + asService.getAllActiveContexts().size()), e -> assertTrue(e instanceof ResourceNotFoundException)), freeContextLatch));
            freeContextLatch.await();
        }
    } finally {
        ThreadPool.terminate(testThreadPool, 200, TimeUnit.MILLISECONDS);
    }
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) InternalAsynchronousSearchStats(org.opensearch.search.asynchronous.stats.InternalAsynchronousSearchStats) ExecutorBuilder(org.opensearch.threadpool.ExecutorBuilder) AsynchronousSearchState(org.opensearch.search.asynchronous.context.state.AsynchronousSearchState) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ActionRequest(org.opensearch.action.ActionRequest) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) LatchedActionListener(org.opensearch.action.LatchedActionListener) InternalAggregations(org.opensearch.search.aggregations.InternalAggregations) ScalingExecutorBuilder(org.opensearch.threadpool.ScalingExecutorBuilder) ActionListener(org.opensearch.action.ActionListener) ActionResponse(org.opensearch.action.ActionResponse) ActionType(org.opensearch.action.ActionType) AsynchronousSearchContext(org.opensearch.search.asynchronous.context.AsynchronousSearchContext) TimeValue(org.opensearch.common.unit.TimeValue) SearchHit(org.opensearch.search.SearchHit) Collections.emptyList(java.util.Collections.emptyList) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) NoOpClient(org.opensearch.test.client.NoOpClient) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) AsynchronousSearchTask(org.opensearch.search.asynchronous.task.AsynchronousSearchTask) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) Collectors(java.util.stream.Collectors) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Stream(java.util.stream.Stream) SubmitAsynchronousSearchRequest(org.opensearch.search.asynchronous.request.SubmitAsynchronousSearchRequest) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) IndexAction(org.opensearch.action.index.IndexAction) ActionListener.wrap(org.opensearch.action.ActionListener.wrap) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) AsynchronousSearchActiveContext(org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveContext) ClusterServiceUtils(org.opensearch.test.ClusterServiceUtils) SearchProfileShardResults(org.opensearch.search.profile.SearchProfileShardResults) SearchAction(org.opensearch.action.search.SearchAction) ThreadPool(org.opensearch.threadpool.ThreadPool) AsynchronousSearchProgressListener(org.opensearch.search.asynchronous.listener.AsynchronousSearchProgressListener) AsynchronousSearchContextId(org.opensearch.search.asynchronous.context.AsynchronousSearchContextId) AsynchronousSearchPlugin(org.opensearch.search.asynchronous.plugin.AsynchronousSearchPlugin) TimeValue.timeValueHours(org.opensearch.common.unit.TimeValue.timeValueHours) SearchHits(org.opensearch.search.SearchHits) ResourceNotFoundException(org.opensearch.ResourceNotFoundException) OpenSearchExecutors(org.opensearch.common.util.concurrent.OpenSearchExecutors) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ArrayList(java.util.ArrayList) SearchRequest(org.opensearch.action.search.SearchRequest) SearchResponse(org.opensearch.action.search.SearchResponse) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) Setting(org.opensearch.common.settings.Setting) TestUtils(org.opensearch.search.asynchronous.utils.TestUtils) TaskId(org.opensearch.tasks.TaskId) InternalSearchResponse(org.opensearch.search.internal.InternalSearchResponse) TotalHits(org.apache.lucene.search.TotalHits) TimeUnit(java.util.concurrent.TimeUnit) User(org.opensearch.commons.authuser.User) TestClientUtils(org.opensearch.search.asynchronous.utils.TestClientUtils) Suggest(org.opensearch.search.suggest.Suggest) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure) ClusterService(org.opensearch.cluster.service.ClusterService) AsynchronousSearchActiveStore(org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveStore) Assert(org.junit.Assert) Collections(java.util.Collections) SubmitAsynchronousSearchRequest(org.opensearch.search.asynchronous.request.SubmitAsynchronousSearchRequest) SearchRequest(org.opensearch.action.search.SearchRequest) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) User(org.opensearch.commons.authuser.User) AsynchronousSearchContext(org.opensearch.search.asynchronous.context.AsynchronousSearchContext) TestThreadPool(org.opensearch.threadpool.TestThreadPool) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) LatchedActionListener(org.opensearch.action.LatchedActionListener) ResourceNotFoundException(org.opensearch.ResourceNotFoundException) TimeValue(org.opensearch.common.unit.TimeValue) SubmitAsynchronousSearchRequest(org.opensearch.search.asynchronous.request.SubmitAsynchronousSearchRequest) InternalAsynchronousSearchStats(org.opensearch.search.asynchronous.stats.InternalAsynchronousSearchStats) AsynchronousSearchActiveContext(org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveContext) CountDownLatch(java.util.concurrent.CountDownLatch) AsynchronousSearchActiveStore(org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveStore) AsynchronousSearchProgressListener(org.opensearch.search.asynchronous.listener.AsynchronousSearchProgressListener) AsynchronousSearchTask(org.opensearch.search.asynchronous.task.AsynchronousSearchTask) ClusterService(org.opensearch.cluster.service.ClusterService)

Example 4 with ExecutorBuilder

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

the class AsynchronousSearchServiceTests 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_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(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);
    blockPersistence = 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) Before(org.junit.Before)

Example 5 with ExecutorBuilder

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

the class AsynchronousSearchPostProcessorTests 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.PERSIST_SEARCH_FAILURES_SETTING, AsynchronousSearchService.MAX_KEEP_ALIVE_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(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) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before)

Aggregations

ArrayList (java.util.ArrayList)10 ExecutorBuilder (org.opensearch.threadpool.ExecutorBuilder)10 ScalingExecutorBuilder (org.opensearch.threadpool.ScalingExecutorBuilder)9 Before (org.junit.Before)8 ClusterSettings (org.opensearch.common.settings.ClusterSettings)8 Setting (org.opensearch.common.settings.Setting)8 Settings (org.opensearch.common.settings.Settings)6 Collections (java.util.Collections)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.emptyMap (java.util.Collections.emptyMap)2 List (java.util.List)2 Set (java.util.Set)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 TotalHits (org.apache.lucene.search.TotalHits)2 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)2 Assert (org.junit.Assert)2 OpenSearchTimeoutException (org.opensearch.OpenSearchTimeoutException)2