Configuring Automatic Termination of HBase Slow Queries
Scenarios
To improve cluster reliability and maintenance, HBase allows you to view, identify, terminate, and block slow queries. This helps O&M personnel quickly detect and terminate problematic requests.
To ensure cluster compatibility, slow query termination is disabled by default. You can set hbase.slow.query.check.enabled to true to enable this feature.
Notes and Constraints
This section applies only to MRS 3.6.0-LTS.1 and later.
Configuring Automatic Termination of HBase Slow Queries
- Log in to FusionInsight Manager and choose Cluster > Services > HBase. Click Configurations.
- Search for hbase.slow.query.check.enabled and change its value to true.
- Log in to the HBase client.
- Log in to the node where the HBase client is installed and go to the client installation directory.
cd Client installation directory
- Configure environment variables.
source bigdata_env
- Authenticate the user. If Kerberos authentication is disabled for the cluster (the cluster is in normal mode), skip this step.
kinit Component service user
Specifically:
- If Ranger authentication is disabled for HBase and ACL authentication is used, the HBase role assigned to the service user must have the management permission on global resources. When creating an HBase role, choose Cluster > HBase > HBase Scope under Configure Resource Permission, and select the admin permission in the global row.
- If Ranger authentication is enabled for HBase, modify the default HBase policy all - table, column-family, column on the Ranger policy configuration page. In the Allow Conditions area, select the service user (for example, admintest) in the Select User column, and select Admin in the Permissions column to add a new rule.
- Log in to the HBase client.
hbase shell
- Log in to the node where the HBase client is installed and go to the client installation directory.
- Configure the slow query threshold.
- Global parameter configuration
On the HBase configuration page, search for the hbase.slow.query.check.threshold parameter and set the value. If a scan duration exceeds this threshold, the system defines it as a slow query. The value ranges from 1000 to 2,147,483,647, in milliseconds.
- Table-level parameters (these override cluster-level configurations)
Alternatively, run the following command in the HBase shell to set the slow query threshold for a specific table:
alter 'Table name', CONFIGURATION => {'hbase.slow.query.check.threshold' => Threshold}
Avoid setting the threshold too low. This can cause too many requests to be flagged as slow queries, which may degrade system performance.
- Global parameter configuration
- Enable pre-emptive interception of slow queries.
- Interception 1
- Global parameter configuration
- On the HBase configuration page, search for the hbase.multi.region.scan.enabled parameter and set the value to false to disable cross-region scans.
This parameter intercepts cross-region query requests. Once cross-region querying is disabled, the system automatically intercepts all cross-region scan requests by default.
- Search for the hbase.region.scan.limit.threshold parameter and set the maximum number of records allowed per scan. Only queries that fall within this limit can be executed.
- On the HBase configuration page, search for the hbase.multi.region.scan.enabled parameter and set the value to false to disable cross-region scans.
- Table-level parameters (these override cluster-level configurations)
- Global parameter configuration
- Interception 2
If the scan query caching parameter is missing or the number of cached records per query exceeds the threshold, the system will intercept the request.
You can adjust the hbase.client.scanner.caching.max value on the HBase configuration page to prevent the system from intercepting query requests with a large number of cached records. Alternatively, set this value to 2147483647 to disable the interception feature.
Alternatively, run the following command in the HBase shell to configure the settings for a specific table:
alter 'Table name', CONFIGURATION => {'hbase.client.scanner.caching.max' => Threshold}
- Interception 1
- Enable real-time interception of slow queries.
- Global parameter configuration
- On the HBase configuration page, search for the hbase.regionserver.scan.block.size.threshold parameter. This limits the total volume of data scanned (including data that does not meet query conditions) per request. If a scan exceeds this threshold, the system terminates the query.
- Search for the hbase.regionserver.scan.response.size.threshold parameter. This limits the total volume of returned data (including only data that matches the query conditions) per request. If a scan exceeds this threshold, the system terminates the query.
- Table-level parameters (these override cluster-level configurations)
Alternatively, run the following command in the HBase shell to set the thresholds for a specific table:
alter 'Table name', CONFIGURATION => {'hbase.regionserver.scan.block.size.threshold' => Threshold, 'hbase.regionserver.scan.response.size.threshold' => Threshold}
For more details regarding HBase slow query parameters, refer to Table 1.
- Global parameter configuration
- On the HBase configuration page, update the parameter values and click Save. You also need to run the following command in the HBase shell to apply the settings to the server:
update_all_config
HBase Slow Query API Usage Description
- Viewing slow queries
- HBase Shell command
get_slow_query
Use this command to view all slow queries, including those for a specific table or from a specific client IP address. You can run the following command in the hbase shell to view command help:
help 'get_slow_query'
Figure 1 Viewing HBase slow queries
- API
For more information, refer to the following code snippet.
If Kerberos authentication is enabled for the cluster (the cluster is in security mode), configure security authentication first. For details, see HBase Data Read/Write Example Security Authentication (Single-Cluster Scenario).
/** * View slow query records. * @param admin */ private static void getSlowQuery(Admin admin) throws IOException { //Obtain all slow query records. List<SlowQueryInfo> slowQueryList = admin.getSlowQuery(); slowQueryList.forEach(slowQueryInfo -> printSlowQueryInfo(slowQueryInfo)); // Obtain slow query records from a specified client IP address. slowQueryList = admin.getSlowQueryByClientIp(Arrays.asList("ip1", "ip2")); // Obtain slow query records for a specified table. slowQueryList = admin.getSlowQueryByTable(Arrays.asList("table1", "table2")); } private static void printSlowQueryInfo(SlowQueryInfo slowQueryInfo) { // Obtain the query ID. long queryId = slowQueryInfo.getQueryId(); // Obtain the client IP address. String clientIp = slowQueryInfo.getClientIp(); // Obtain the table name. String tableName = slowQueryInfo.getTableName(); // Obtain the timestamp when the query starts. long starTime = slowQueryInfo.getStartTime(); // Obtain the query details. String scanDetail = slowQueryInfo.getQueryDetails(); // Print slow query information. System.out.println(slowQueryInfo); }
- HBase Shell command
- Terminating a slow query
- HBase Shell command
abort_slow_query
Use this command to terminate a slow query by its ID. To terminate multiple slow queries simultaneously, provide the IDs separated by commas (,). You can run the following command in the hbase shell to view command help:
help 'abort_slow_query'
Figure 2 Terminating an HBase slow query
- API
For more information, refer to the following code snippet.
If Kerberos authentication is enabled for the cluster (the cluster is in security mode), configure security authentication first. For details, see HBase Data Read/Write Example Security Authentication (Single-Cluster Scenario).
/** * Terminate a slow query. * @param admin */ private static void abortSlowQuery(Admin admin) throws IOException { // Specify the ID of the query you want to terminate. List<Long> queryIds = new ArrayList<>(); queryIds.add(123456789L); queryIds.add(987654321L); // Terminate one or more specific slow queries. AbortSlowQueryResponse response = admin.abortSlowQueries(queryIds); // Unknown slow query. The query request corresponding to the query ID may have already finished or been terminated before the abort command was processed. AbortSlowQueryResponse.ResultGroup unknownItems = response.getUnknownItems(); if(unknownItems != null) { List<Long> unknownQueryIds = unknownItems.getQueryIds(); unknownQueryIds.forEach(id -> { System.out.println("unknown: " + id); // Remove the unknown query ID. queryIds.removeIf(id::equals); }); } // Slow queries that cannot be terminated due to an exception. AbortSlowQueryResponse.ResultGroup failedItems = response.getFailedItems(); if(failedItems != null) { List<Long> failedQueryIds = failedItems.getQueryIds(); failedQueryIds.forEach(id -> { System.out.println("failed: " + id); // Remove the unknown query ID. queryIds.removeIf(id::equals); }); } //Remove unknown and failed query IDs. Any remaining query IDs are considered successful. queryIds.forEach(id -> System.out.println("success: " + id)); }
- HBase Shell command
HBase Slow Query Parameters
| Parameter | Description | Default Value | Value Range | Table-Level Configuration Support |
|---|---|---|---|---|
| hbase.slow.query.check.enabled | Enable or disable HBase slow query termination. | false |
| No |
| hbase.slow.query.check.threshold | When the HBase slow query termination feature is enabled, any scan query with an execution time exceeding this parameter's threshold is identified as a slow query. The unit is milliseconds (ms). If the threshold is set too low, an excessive number of requests will be identified as slow queries, impacting service performance. | 10000 | 1000 to 2,147,483,647 | Yes |
| hbase.query.intercept.enabled | Enable or disable the slow query interception feature. When this feature is enabled, the RegionServer intercepts queries. Otherwise, it only prints logs. | false |
| No |
| hbase.multi.region.scan.enabled | Enable or disable cross-region scan query interception. Note: If this parameter is set to false, all cross-region scans that lack a specific limit or exceed the threshold will be intercepted. Exercise caution when setting this parameter, or configure this parameter for a single table only. | true |
| Yes |
| hbase.region.scan.limit.threshold | When cross-region scan query interception is disabled, a scan query is permitted only if a limit is defined for the number of records and the actual number of records does not exceed the specified threshold. Otherwise, the scan query will be intercepted. | -1 | -1 to 2,147,483,647 | Yes |
| hbase.regionserver.scan.block.size.threshold | This parameter specifies the maximum data volume (including data that does not meet query conditions) scanned from the server during each scan request. If this volume exceeds the threshold, the query will be terminated. The unit is bytes. Setting this value to -1 disables the check. | -1 | -1 to 9,223,372,036,854,775,807 | Yes |
| hbase.regionserver.scan.response.size.threshold | This parameter specifies the maximum data volume (including data that does not meet query conditions) scanned from the server during each scan request. If this volume exceeds the threshold, the query will be terminated. The unit is bytes. Setting this value to -1 disables the check. | -1 | -1 to 9,223,372,036,854,775,807 | Yes |
| hbase.client.scanner.caching.max | If the value of the caching parameter in the scan request exceeds this threshold, the request will be intercepted. Leaving this parameter blank or setting it to 2147483647 disables the check. | - | 1 to 2,147,483,647 | Yes |
| hbase.slow.query.znode.limit | This parameter limits the number of slow query records for the HBase service. If the number of slow queries on the znode exceeds this limit, new records are stored only in the logs. An excessive number of slow query records can impact the server's responsiveness. | 10000 | 1 to 2,147,483,647 | No |
| hbase.slow.query.znode.content.limit | This parameter specifies the maximum size of a single slow query record, in bytes. Slow query records include filter data. If a query contains excessive filters, the resulting record may become too large and consume significant server resources. When the size of a slow query record exceeds this parameter value, the filter data is truncated. | 10240 | 1024 to 2,097,152 | No |
| hbase.slow.query.znode.cleaner.interval | This parameter specifies the interval for checking residual slow query records, in milliseconds. The system periodically checks for and clears residual slow query records. | 300000 | 1 to 2,147,483,647 | No |
| hbase.slow.query.znode.ttl | This parameter specifies the retention period for slow query records, in milliseconds. To prevent residual operation records in abnormal scenarios, the system periodically checks for and clears these records. | 600000 | 1 to 2,147,483,647 | No |
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot