Skip to content

Commit 8e7719d

Browse files
committed
add logger.warn if thread pool size is clipped; fix test failure
1 parent 7ef43a2 commit 8e7719d

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,18 +533,19 @@ private ExecutorHolder rebuild(String name, ExecutorHolder previousExecutorHolde
533533
throw new IllegalArgumentException("No type found [" + type + "], for [" + name + "]");
534534
}
535535

536-
private int applyHardSizeLimit(String name, int requestedSize) {
536+
private int applyHardSizeLimit(String name, int size) {
537537
int availableProcessors = EsExecutors.boundedNumberOfProcessors(settings);
538-
if (name.equals(Names.BULK) || name.equals(Names.INDEX)) {
538+
if ((name.equals(Names.BULK) || name.equals(Names.INDEX)) && size > availableProcessors) {
539539
// We use a hard max size for the indexing pools, because if too many threads enter Lucene's IndexWriter, it means
540540
// too many segments written, too frequently, too much merging, etc:
541-
542541
// TODO: I would love to be loud here (throw an exception if you ask for a too-big size), but I think this is dangerous
543542
// because on upgrade this setting could be in cluster state and hard for the user to correct?
544-
return Math.min(requestedSize, availableProcessors);
545-
} else {
546-
return requestedSize;
543+
logger.warn("requested thread pool size [{}] for [{}] is too large; setting to maximum [{}] instead",
544+
size, name, availableProcessors);
545+
size = availableProcessors;
547546
}
547+
548+
return size;
548549
}
549550

550551
private void updateSettings(Settings settings) {

core/src/test/java/org/elasticsearch/threadpool/UpdateThreadPoolSettingsTests.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ public void testCachedExecutorType() throws InterruptedException {
211211
}
212212
}
213213

214+
private static int getExpectedThreadPoolSize(Settings settings, String name, int size) {
215+
if (name.equals(ThreadPool.Names.BULK) || name.equals(ThreadPool.Names.INDEX)) {
216+
return Math.min(size, EsExecutors.boundedNumberOfProcessors(settings));
217+
} else {
218+
return size;
219+
}
220+
}
221+
214222
public void testFixedExecutorType() throws InterruptedException {
215223
String threadPoolName = randomThreadPool(ThreadPool.ThreadPoolType.FIXED);
216224
ThreadPool threadPool = null;
@@ -225,12 +233,14 @@ public void testFixedExecutorType() throws InterruptedException {
225233
Settings settings = clusterSettings.applySettings(settingsBuilder()
226234
.put("threadpool." + threadPoolName + ".size", "15")
227235
.build());
236+
237+
int expectedSize = getExpectedThreadPoolSize(nodeSettings, threadPoolName, 15);
228238
assertEquals(info(threadPool, threadPoolName).getThreadPoolType(), ThreadPool.ThreadPoolType.FIXED);
229239
assertThat(threadPool.executor(threadPoolName), instanceOf(EsThreadPoolExecutor.class));
230-
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getCorePoolSize(), equalTo(15));
231-
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getMaximumPoolSize(), equalTo(15));
232-
assertThat(info(threadPool, threadPoolName).getMin(), equalTo(15));
233-
assertThat(info(threadPool, threadPoolName).getMax(), equalTo(15));
240+
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getCorePoolSize(), equalTo(expectedSize));
241+
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getMaximumPoolSize(), equalTo(expectedSize));
242+
assertThat(info(threadPool, threadPoolName).getMin(), equalTo(expectedSize));
243+
assertThat(info(threadPool, threadPoolName).getMax(), equalTo(expectedSize));
234244
// keep alive does not apply to fixed thread pools
235245
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getKeepAliveTime(TimeUnit.MINUTES), equalTo(0L));
236246

@@ -240,20 +250,23 @@ public void testFixedExecutorType() throws InterruptedException {
240250
// Make sure keep alive value is not used
241251
assertThat(info(threadPool, threadPoolName).getKeepAlive(), nullValue());
242252
// Make sure keep pool size value were reused
243-
assertThat(info(threadPool, threadPoolName).getMin(), equalTo(15));
244-
assertThat(info(threadPool, threadPoolName).getMax(), equalTo(15));
253+
assertThat(info(threadPool, threadPoolName).getMin(), equalTo(expectedSize));
254+
assertThat(info(threadPool, threadPoolName).getMax(), equalTo(expectedSize));
245255
assertThat(threadPool.executor(threadPoolName), instanceOf(EsThreadPoolExecutor.class));
246-
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getCorePoolSize(), equalTo(15));
247-
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getMaximumPoolSize(), equalTo(15));
256+
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getCorePoolSize(), equalTo(expectedSize));
257+
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getMaximumPoolSize(), equalTo(expectedSize));
248258

249259
// Change size
250260
Executor oldExecutor = threadPool.executor(threadPoolName);
251261
settings = clusterSettings.applySettings(settingsBuilder().put(settings).put("threadpool." + threadPoolName + ".size", "10").build());
262+
263+
expectedSize = getExpectedThreadPoolSize(nodeSettings, threadPoolName, 10);
264+
252265
// Make sure size values changed
253-
assertThat(info(threadPool, threadPoolName).getMax(), equalTo(10));
254-
assertThat(info(threadPool, threadPoolName).getMin(), equalTo(10));
255-
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getMaximumPoolSize(), equalTo(10));
256-
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getCorePoolSize(), equalTo(10));
266+
assertThat(info(threadPool, threadPoolName).getMax(), equalTo(expectedSize));
267+
assertThat(info(threadPool, threadPoolName).getMin(), equalTo(expectedSize));
268+
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getMaximumPoolSize(), equalTo(expectedSize));
269+
assertThat(((EsThreadPoolExecutor) threadPool.executor(threadPoolName)).getCorePoolSize(), equalTo(expectedSize));
257270
// Make sure executor didn't change
258271
assertEquals(info(threadPool, threadPoolName).getThreadPoolType(), ThreadPool.ThreadPoolType.FIXED);
259272
assertThat(threadPool.executor(threadPoolName), sameInstance(oldExecutor));

0 commit comments

Comments
 (0)