Request Throttling Plug-in¶
The request throttling plug-in limits the number of times an API can be called within a specific time period. It supports parameter-based, basic, and excluded throttling.
Note
If your gateway does not support the request throttling plug-in, contact customer service to upgrade the gateway.
Basic throttling
Throttle requests by API, user, app, or source IP address. This function is equivalent to a request throttling policy but is incompatible with it.
Parameter-based throttling
Throttle requests based on headers, path parameters, methods, query strings, or system variables.
Excluded throttling
Throttle requests based on specific apps or tenants.
Constraints¶
A request throttling policy becomes invalid if a request throttling plug-in is bound to the same API as the policy.
You can define a maximum of 100 parameter rules.
The plug-in content cannot exceed 65,535 characters.
Configuration Parameters¶
Parameter | Description |
---|---|
Policy Type |
|
Period | For how long you want to limit the number of API requests.
|
Max. API Requests | The maximum number of times each bound API can be called within the specified period. This parameter must be used together with Period. |
Max. User Requests | The maximum number of times each bound API can be called by a user within the specified period. For APIs with IAM authentication, the throttling is based on a project ID; for APIs with app authentication, the throttling is based on an account ID. For details about account IDs and project IDs, see the description about Excluded Tenants in this table.
|
Max. App Requests | The maximum number of times each bound API can be called by an app within the specified period. This limit only applies to APIs that are accessed through app authentication.
|
Max. IP Address Requests | The maximum number of times each bound API can be called by an IP address within the specified period.
|
Parameter-based Throttling | Enable or disable parameter-based throttling. After this function is enabled, API requests are throttled based on specified parameters. |
Parameters | Define parameters for throttling rules.
|
Rules | Define throttling rules. A rule consists of conditions, an API request throttling limit, and a period. To add more rules, click Add Rule.
For example, configure parameter-based throttling as follows: add the Host parameter and specify the location as Header; add the condition Host = www.abc.com, and set the throttling limit to 10 and the period to 60s. For APIs whose Host parameter in the request header is equal to www.abc.com, they cannot be called again once called 10 times in 60s. |
Excluded Throttling | Enable or disable excluded throttling. After this function is enabled, the throttling limits for excluded tenants and apps override the Max. User Requests and Max. App Requests in the Basic Throttling area. |
Excluded Tenants | Tenant ID: an account ID or project ID.
Threshold: the maximum number of times that a specific tenant can access an API within the specified period. The threshold cannot exceed the value of Max. API Requests in the Basic Throttling area. |
Excluded Apps | Select an app, and specify the maximum number of times that the app can access an API within the specified period. The threshold cannot exceed the value of Max. API Requests in the Basic Throttling area. |
Example Script¶
{
"scope": "basic",
"default_interval": 60,
"default_time_unit": "second",
"api_limit": 100,
"app_limit": 50,
"user_limit": 50,
"ip_limit": 20,
"specials": [
{
"type": "app",
"policies": [
{
"key": "2e421d76dc6c4c75941511ccf654e368",
"limit": 10
}
]
},
{
"type": "user",
"policies": [
{
"key": "878f1b87f71c40a7a15db0998f358bb9",
"limit": 10
}
]
}
],
"parameters": [
{
"type": "path",
"name": "reqPath",
"value": "reqPath"
},
{
"type": "method",
"name": "method",
"value": "method"
},
{
"type": "header",
"name": "Host",
"value": "Host"
}
],
"rules": [
{
"match_regex": "[\"Host\",\"==\",\"www.abc.com\"]",
"rule_name": "rule-jlce",
"time_unit": "second",
"interval": 0,
"limit": 5
}
]
}