-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure IndexSearcher.maxClauseCount() based on Node characteristics #81525
Changes from 3 commits
599c297
7b7ae11
fa76baa
47e4949
6f67b60
ee6b47f
949b32f
2627e4a
a053462
691e7a9
51976f2
0c56f81
8990bb2
baf1f4a
c34cdfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
|
||
package org.elasticsearch.search; | ||
|
||
import org.apache.lucene.search.BooleanQuery; | ||
import org.elasticsearch.common.CheckedBiConsumer; | ||
import org.elasticsearch.common.NamedRegistry; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
|
@@ -268,7 +267,8 @@ public class SearchModule { | |
4096, | ||
1, | ||
Integer.MAX_VALUE, | ||
Setting.Property.NodeScope | ||
Setting.Property.NodeScope, | ||
Setting.Property.DeprecatedWarning | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When would we raise a deprecation warning for node settings, only on startup? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have confirmed with @pgomulka that this will only be emitted on startup, yes. |
||
); | ||
|
||
public static final Setting<Integer> INDICES_MAX_NESTED_DEPTH_SETTING = Setting.intSetting( | ||
|
@@ -292,8 +292,6 @@ public class SearchModule { | |
/** | ||
* Constructs a new SearchModule object | ||
* | ||
* NOTE: This constructor should not be called in production unless an accurate {@link Settings} object is provided. | ||
* When constructed, a static flag is set in Lucene {@link BooleanQuery#setMaxClauseCount} according to the settings. | ||
* @param settings Current settings | ||
* @param plugins List of included {@link SearchPlugin} objects. | ||
*/ | ||
|
@@ -1057,7 +1055,6 @@ private void registerQueryParsers(List<SearchPlugin> plugins) { | |
registerQuery(new QuerySpec<>(MatchAllQueryBuilder.NAME, MatchAllQueryBuilder::new, MatchAllQueryBuilder::fromXContent)); | ||
registerQuery(new QuerySpec<>(QueryStringQueryBuilder.NAME, QueryStringQueryBuilder::new, QueryStringQueryBuilder::fromXContent)); | ||
registerQuery(new QuerySpec<>(BoostingQueryBuilder.NAME, BoostingQueryBuilder::new, BoostingQueryBuilder::fromXContent)); | ||
BooleanQuery.setMaxClauseCount(INDICES_MAX_CLAUSE_COUNT_SETTING.get(settings)); | ||
registerBoolQuery(new ParseField(BoolQueryBuilder.NAME), BoolQueryBuilder::new); | ||
BoolQueryBuilder.setMaxNestedDepth(INDICES_MAX_NESTED_DEPTH_SETTING.get(settings)); | ||
registerQuery(new QuerySpec<>(TermQueryBuilder.NAME, TermQueryBuilder::new, TermQueryBuilder::fromXContent)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.search; | ||
|
||
import org.apache.lucene.search.IndexSearcher; | ||
import org.elasticsearch.monitor.jvm.JvmStats; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
|
||
public final class SearchUtils { | ||
|
||
/** | ||
* Configure the maximum lucene query clause count based on the size of the search thread pool and maximum heap | ||
*/ | ||
public static void configureMaxClauses(ThreadPool threadPool) { | ||
int searchThreadPoolSize = threadPool.info(ThreadPool.Names.SEARCH).getMax(); | ||
long heapSize = JvmStats.jvmStats().getMem().getHeapMax().getGb(); | ||
configureMaxClauses(searchThreadPoolSize, heapSize); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if you start Elasticsearch with 512MB of heap, does it mean you get zero max clauses? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have updated this so that we will always return a minimum of 4096, or larger if the heap/cpu size permits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this work if we used the heap size in GB as a fractional number instead? |
||
} | ||
|
||
static void configureMaxClauses(long threadPoolSize, long heapInGb) { | ||
if (threadPoolSize <= 0 || heapInGb <= 0) { | ||
return; // If we don't know how to size things, keep the lucene default | ||
} | ||
|
||
int maxClauseCount = Math.toIntExact(heapInGb * 65_536 / threadPoolSize); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add some explanation as to where this 65,536 number comes from? |
||
IndexSearcher.setMaxClauseCount(maxClauseCount); | ||
} | ||
|
||
private SearchUtils() {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This number might be super high now, how slow is the test? Maybe we need to set an artificially low limit for this test to keep it reasonable?