Slow query isolation (Public preview)

更新时间:
复制 MD 格式

To ensure cluster stability, you can isolate large or slow queries in a dedicated thread pool to prevent them from affecting normal queries. The Lindorm search engine supports the isolation of specific slow queries. This topic describes how to use this feature in the Lindorm search engine.

Precautions

The slow query isolation feature for the Lindorm search engine is in public preview. To use this feature, contact Lindorm technical support (DingTalk ID: s0s3eg3) to enable it.

Prerequisites

The search engine version must be 3.9.31 or later.

Slow query statistics

You can view statistics on the search queries that consume the most resources in your system. These statistics help you quickly identify slow queries and requests with high CPU or memory usage. You can use this information for performance tuning, query isolation, and capacity planning.

Syntax

GET /_top_tasks?actions=*search&top=N[&resource=TYPE]&pretty

Parameter description

Parameter

Required

Description

actions=*search

Yes

Static value. Specifies to collect statistics only on search requests (query operations).

top=N

Yes

Returns the top N query tasks that consume the most resources.

resource=TYPE

No

Specifies the resource metric for sorting.
• Default: Sorts by response time (RT).
cpu: Sorts by CPU usage.
memory: Sorts by memory usage.


pretty

No

Returns the result in a formatted JSON structure for readability.

Examples

# Get statistics on the top 5 queries with the longest response times.
curl -XGET "http://solr-1:port/_top_tasks?actions=*search&top=5&pretty"

# Get statistics on the top 5 queries with the highest CPU usage.
curl  -XGET "http://solr-1:port/_top_tasks?actions=*search&top=5&resource=cpu&pretty"

# Get statistics on the top 5 queries with the highest memory usage.
curl -XGET "http://solr-1:port/_top_tasks?actions=*search&top=5&resource=memory&pretty"

Slow query isolation

The Lindorm search engine provides two slow query fencing methods: pattern matching fencing and time threshold fencing. You can choose the appropriate method based on your business scenario to fence specific slow queries.

Pattern matching isolation

This method matches strings in search statements. Queries that match the specified rules are automatically identified and isolated in the slow query pool.

Syntax

PUT _cluster/settings

Parameter description

Parameter

Required

Description

search.slow.query.rule

Yes

Defines the matching rules for slow queries. A query that meets a rule is added to the slow query pool. The rules are based on string matching:

  • AND: Matches multiple strings.

  • ||: Matches any one of the specified strings.

Examples

# Move queries that contain both "date_histogram" and "aggregations" or contain "muti_match" to the slow query pool.
curl -XPUT "host:port/_cluster/settings?" -H "Content-Type: application/json" -d'
{
  "persistent" : {"search.slow.query.rule" : "date_histogram AND aggregations|| muti_match"}
}'

# Move queries that contain "bucket_script" or "muti_match" to the slow query pool.
curl -XPUT "host:port/_cluster/settings?" -H "Content-Type: application/json" -d'
{
  "persistent" : {"search.slow.query.rule" : "bucket_script || muti_match"}
}'

Time threshold isolation

This method automatically identifies and isolates queries whose response time (RT) exceeds a specified threshold. These queries are moved to the slow query pool. This limits their resource consumption and ensures the stability of core queries.

Syntax

PUT _cluster/settings

Parameter description

Parameter

Required

Description

search.slow.query.threshold

Yes

Sets the RT threshold for slow queries. A query is considered a slow query and is moved to the slow query pool if its response time exceeds this value. The unit is milliseconds (ms).

Note
  • This method is primarily for slow queries that are repeated or run periodically. If the queries are different each time, they cannot be isolated.

  • If the RT of the same query later falls below the threshold, the system automatically removes it from the slow query pool and resumes normal scheduling.

Example

# Isolate queries with an RT that exceeds 30s to the slow query pool.
curl -XPUT "host:port/_cluster/settings" -H "Content-Type: application/json" -d'
{
  "persistent" : {"search.slow.query.threshold" : 30000}
}'