API traffic limit lets you set limits for individual APIs, default rate limits for all APIs, and a total rate limit for an application. This feature prevents your backend servers from being overwhelmed during peak traffic. If you set both a default API rate limit and a total application rate limit, the lower of the two limits takes precedence.
This topic describes how to configure default API rate limits and total application rate limits. To set a rate limit for a specific API, you can configure it on the API details page. For more information, see Configure an API.
Prerequisites
To use traffic limit configurations, you must first enable the traffic limit feature. Log on to the mPaaS console. In the navigation pane on the left, choose Mobile Gateway > Gateway Management. Then, turn on the Limit API traffic switch.
Default API rate limit
You can set a default rate limit for all APIs in the current application. The default rate limit is applied based on the following rules:
If a rate limit is configured for a specific API, that limit overwrites the default rate limit.
A per-API throttling configuration overwrites the default configuration.
Changes to the default rate limit configuration affect all APIs that use the default configuration.
Steps:
Turn on the API default traffic limit switch.
In the default rate limit configuration box, click Edit and configure the rate limit information.
Default rate limit: Set a reasonable threshold based on your business needs. Requests that exceed this value are throttled.
NoteThe rate limit threshold is the maximum number of requests per second.
Traffic limit response: The default response for throttled requests is:
{"resultStatus":1002,"tips":"The server is busy. Please try again later."}To customize the throttling response, use the following format:{ "result": "==Enter your custom response content here==", "tips": "ok", "resultStatus": 1000, }Where:
resultis the custom response data in JSON format. The client processes this field only whenresultStatusis 1000.tipsis the custom throttling message. IfresultStatusis 1002, this field is used to notify the user.resultStatusis the result code returned for a throttled request. For more information about result code definitions, see Gateway result codes.
Total application rate limit
You can set a total rate limit for all APIs in the current application. If the total number of requests exceeds this limit, all subsequent requests to any API in the application are throttled.
Steps:
Turn on the Total traffic limit of the App switch.
In the total application rate limit configuration box, click Edit and configure the rate limit information.
Total rate limit: Set a reasonable threshold in requests per second based on your business needs. Requests that exceed this value are throttled.
Traffic limit response: The default response for throttled requests is:
{"resultStatus":1002,"tips":"The server is busy. Please try again later."}To customize the throttling response, use the following format:{ "result": "==Enter your custom response content here==", "tips": "ok", "resultStatus": 1000, }Where:
resultis the custom response data in JSON format. The client processes this field only whenresultStatusis 1000.resultStatusis the result code returned for a throttled request. For more information about result code definitions, see Gateway result codes.tipsis the custom throttling message. IfresultStatusis 1002, this field is used to notify the user.