Configure API flow control rules for your gateway application in AHAS to throttle traffic spikes at the entry point and protect downstream services from being overwhelmed. This topic describes how to create and manage these rules.
Create an API flow control rule
Log on to the AHAS console and select a region in the upper-left corner.
In the left-side navigation pane, choose .
On the Gateway Protection page, click the target application's card.
- Click the target gateway application's card, and then use one of the following methods to open the API Flow Control Rules page:
- On the API Details page, click the plus sign (+) in the upper-right corner of the API resource card.
- In the left-side navigation pane, click API Flow Control Rules, and then click New Flow Control Rule in the upper-right corner of the page.
- In the New Flow Control Rule dialog box, configure the rule parameters.
Parameter Description API Select the API that the rule will apply to, or manually enter the Route ID from your route configuration file. Limit by request attribute - If the Limit by request attribute switch is off, rate limiting applies to all requests for the API.
- If the Limit by request attribute switch is on, rate limiting is applied based on a specific request attribute of the API.
You can control traffic based on the following attributes:
- Client IP: The IP address of the client that sends the request.
- Remote Host: The Host header of the request.
- HeaderHeader: Throttles requests based on a specified HTTP header key. You must also specify a match strategy for the request attribute value. Only requests with attribute values that match the pattern are counted toward the limit.
- URL ParameterURL parameters: Throttles requests based on a specified HTTP URL parameter. You must enter the parameter name and specify a match strategy for the request attribute value. Only requests with attribute values that match the pattern are counted toward the limit.
- Match Strategy
- Exact: The attribute value must exactly match the specified string.
- Substring: The attribute value must contain the specified substring. For example, if the substring is
ab, values such asabaandcabcare matched, butcbais not. - Regex: The attribute value is matched against the specified regular expression.
Threshold type - QPS: Queries Per Second. Sets a threshold for the number of requests allowed within a specified statistic interval (second, minute, hour, or day).
For example, if you set the threshold to 10 and the interval to Minute, a maximum of 10 requests are allowed per minute.
- Thread count: The number of threads concurrently executing on the resource.Note When the Limit by request attribute switch is on, thread count is not supported as a threshold type.
Flow control effect - Fail-fast: This effect is available when the threshold type is QPS. Requests are immediately rejected when the threshold is reached.
- Uniform rate queuing: This effect is available when the threshold type is QPS. Requests that exceed the rate limit are queued and processed at a uniform rate.
You must specify a timeout. If the calculated wait time for a request exceeds this timeout, the request is immediately rejected instead of being queued.
For example, if QPS is set to 10, requests are processed at a rate of one every 100 ms. Additional requests are queued, but will be rejected if their wait time exceeds the specified timeout.
Note When you use uniform rate queuing, the QPS value must not exceed 1,000, which corresponds to a request interval of 1 ms.
Burst size When the flow control effect is fail-fast, you can set a burst size. This specifies the number of additional requests allowed to accommodate sudden traffic spikes. Timeout The maximum time a request can wait in the queue before being rejected. This parameter is required when the flow control effect is uniform rate queuing. - Click Add.
The new rule appears on the API Flow Control Rules page.
Manage flow control rules
On the API Flow Control Rules page, you can enable, disable, edit, or delete rules.
Enable or disable a single rule: On the API Flow Control Rules page, find the target rule and click the switch in the Status column to enable or disable it.
Enable or disable multiple rules at once: On the API Flow Control Rules page, select the checkboxes for the target rules, and then click Batch Enable or Batch Disable.
Edit a rule: On the API Flow Control Rules page, find the target rule and click Edit in the Actions column.
Delete a rule: On the API Flow Control Rules page, find the target rule and click Delete in the Actions column.