Monitor and manage big queries
This topic describes how to monitor and manage big queries in your StarRocks cluster.
Big queries include queries that scan too many rows or occupy too many CPU and memory resources. They can easily exhaust cluster resources and cause system overload if no restrictions are imposed on them. To tackle this issue, StarRocks provides a series of measures to monitor and manage big queries, preventing queries from monopolizing cluster resources.
The overall idea of handling big queries in StarRocks is as follows:
- Set automatic precautions against big queries with resource groups and query queues.
- Monitor big queries in real-time, and terminate those who bypass the precautions.
- Analyze audit logs and Big Query Logs to study the patterns of big queries, and fine-tune the precaution mechanisms you set earlier.
This feature is supported from v3.0.
Set precautions against big queries
StarRocks provides two precautionary instruments for dealing with big queries - resource groups and query queues. You can use resource groups to stop big queries from being executed. Query queues, on the other hand, can help you queue the incoming queries when the concurrency threshold or resource limit is reached, preventing system overload.
Filter out big queries via resource groups
Resource groups can automatically identify and terminate big queries. When creating a resource group, you can specify the upper limit of CPU time, memory usage, or scan row count that a query is entitled to. Among all queries that hit the resource group, any queries that require more resources are rejected and returned with an error. For more information and instructions on resource groups, see Resource Isolation.
Before creating resource groups, you must execute the following statement to enable Pipeline Engine, on which the Resource Group feature depends:
SET GLOBAL enable_pipeline_engine = true;
The following example creates a resource group bigQuery
that limits the CPU time upper limit to 100
seconds, scan row count upper limit to 100000
, and memory usage upper limit to 1073741824
bytes (1 GB):
CREATE RESOURCE GROUP bigQuery
TO
(db='sr_hub')
WITH (
'cpu_weight' = '10',
'mem_limit' = '20%',
'big_query_cpu_second_limit' = '100',
'big_query_scan_rows_limit' = '100000',
'big_query_mem_limit' = '1073741824'
);
If the required resources of a query exceed any of the limits, the query will not be executed and is returned with an error. The following example shows the error message returned when a query demands too many scan rows:
ERROR 1064 (HY000): exceed big query scan_rows limit: current is 4 but limit is 1
If it is your first time setting up resource groups, we recommend you set relatively higher limits so that they will not hinder regular queries. You can fine-tune these limits after you have a better knowledge of the big query patterns.