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;
}
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;
}
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);
}
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);
}
}
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);
}
}
Aggregations