All Products
Search
Document Center

Microservices Engine:Create a hot parameter throttling rule for RPC requests

Last Updated:Aug 16, 2024

After you create hot parameter throttling rules for an application, Microservices Engine (MSE) analyzes and collects statistics on the hot parameters that are most frequently accessed during resource calls and throttles resource calls that involve hot parameters. This ensures system stability. This topic describes how to create a hot parameter throttling rule for an application.

Background information

Hot data refers to the frequently accessed data. For example, you need to collect statistics on the most frequently accessed data and perform access control on the frequently accessed data in the following scenarios:

  • Restrict the access to the IDs of the most frequently purchased products in a period of time to prevent a large number of requests from being sent to a database due to cache breakdowns.

  • Restrict the access from the IDs of users who frequently send requests in a period of time is to prevent brushing.

MSE uses the least recently used (LRU) policy to collect statistics on the hot parameters that are most frequently accessed and throttles resource calls that involve hot parameters based on the token bucket algorithm.

Procedure

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Governance > Application Governance.

  3. On the Application list page, click the resource card of the destination application.

  4. On the details page of the application, create a hot parameter throttling rule by using one of the following methods:

    • In the left-side navigation pane, click API Details. On the page that appears, click the RPC service tab. On the RPC service tab, select an API operation. Click the Hotspot Parameter Protection (RPC) tab. On the Hotspot Parameter Protection (RPC) tab, click Add Hotspot Parameter Protection (RPC) Rule.

    • In the left-side pane, click Traffic management. On the page that appears, click the Flow protection tab. On the Flow protection tab, click the Hotspot Parameter Protection (RPC) tab. On the Hotspot Parameter Protection (RPC) tab, click Add Hotspot Parameter Protection (RPC) Rule.

  5. In the Add Hotspot Parameter Protection (RPC) Rule dialog box, configure the parameters. Click New.

    For more information about the parameters, see the Parameters section of this topic.

Scenario 1: Flash sales of hot products

In scenarios such as flash sales, the system may fail to immediately respond or even stop responding due to a large amount of traffic. To ensure system stability, you can create a hot parameter throttling rule. If the specified threshold is exceeded, the system queues the excess requests to purchase the hot products.

For example, if the number of requests to purchase a product exceeds 100 within 1 second, the system processes 100 requests per second and queues the excess requests. To create a hot parameter throttling rule for remote procedure call (RPC) requests, configure the following rule information in the Add Hotspot Parameter Protection (RPC) Rule dialog box:

  • Specify a value for the Interface name parameter.

  • Set the Parameter position Index parameter to the index of the hot parameter specified during tracking. The index corresponds to the index of the parameter in the method com.aliyun.demo:methodA(param0, param1, ...) called by RPC requests. The index starts from 0.

  • Set the Statistical dimension parameter to Number of requests.

  • Set the Statistical cycle time parameter to 1 in units of seconds and the Single machine threshold parameter to 100.

  • Set the Flow control effect parameter to Waiting in line.

  • Set the Timeout parameter to 30. Unit: milliseconds.

After the rule is created, if this API operation is called more than 100 times within 1 second, the excess requests are queued. If a request is queued for more than 30 milliseconds, the request immediately fails.

Scenario 2: Frequent requests that occupy a large number of system resources

In the flash sales scenario, customers may need to modify shipping addresses for orders. If a large number of requests to modify shipping addresses are sent to the system, a large number of resources are consumed to write data to a database. In this case, you can make the excess requests that involve hot parameters immediately fail. To create a hot parameter throttling rule for RPC requests, configure the following rule information in the Add Hotspot Parameter Protection (RPC) Rule dialog box:

  • Specify a value for the Interface name parameter.

  • Set the Parameter position Index parameter to the index of the hot parameter specified during tracking. The index corresponds to the index of the parameter in the method com.aliyun.demo:methodA(param0, param1, ...) called by RPC requests. The index starts from 0.

  • Set the Statistical dimension parameter to Concurrent number.

  • Set the Statistical cycle time parameter to 1 in units of seconds and the Single machine threshold parameter to 100.

  • Set the Flow control effect parameter to Fast failure.

After the rule is created, the system can process up to 100 requests per second. The excess requests immediately fails.

Parameters

The following table describes the parameters that you can configure in the Add Hotspot Parameter Protection (RPC) Rule dialog box.

Parameter

Description

Interface name

The name of the interface to which you want to apply the rule. The name must be the same as the resource name specified during tracking.

Parameter position Index

The index of the hot parameter specified during tracking. The index corresponds to the index of the parameter in the method com.aliyun.demo:methodA(param0, param1, ...) called by RPC requests. The index starts from 0. The index of param0 is 0, and the index of param1 is 1.

Statistical dimension

The dimension based on which the statistics of requests are collected. Valid values:

  • Number of requests: limits the number of requests within a period of time.

  • Concurrent number: limits the maximum number of requests that can be concurrently processed.

Statistical cycle time

The statistical period. Unit: seconds. For example, if the statistical period is 10 seconds and the queries per second (QPS) threshold is 5, each hot parameter can be accessed five times at most within 10 seconds.

Single machine threshold

The QPS threshold for each hot parameter.

Flow control effect

The mode in which the blocked requests are processed. You can configure this parameter if you set the Statistical dimension parameter to Number of requests. Valid values:

  • Fast failure: Requests are immediately blocked if the QPS threshold is reached. In this mode, you can configure the Number of buffered requests parameter, which specifies the number of additionally allowed requests for traffic bursts.

  • Waiting in line: In this mode, the system queues requests and processes the requests at a constant speed. This mode is typically used in scenarios such as message queue (MQ) peak-load shifting. You must specify a timeout period. The estimated queuing duration is calculated when a request is queued. If the estimated queuing duration exceeds the specified timeout period, the request is directly rejected. For example, if the Single machine threshold parameter is set to 5, the system processes a request every 200 milliseconds and queues the excess requests. If you set the timeout period to 1,000 milliseconds and more than five requests are queued, the excess requests are rejected.