Skip to main content
Version: 2.9




Limiting request concurrency plugin.


connintegerrequiredconn > 0the maximum number of concurrent requests allowed. Requests exceeding this ratio (and below conn + burst) will get delayed(the latency seconds is configured by default_conn_delay) to conform to this threshold.
burstintegerrequiredburst >= 0the number of excessive concurrent requests (or connections) allowed to be delayed.
default_conn_delaynumberrequireddefault_conn_delay > 0the latency seconds of request when concurrent requests exceeding conn but below (conn + burst).
only_use_default_delaybooleanoptionalfalse[true,false]enable the strict mode of the latency seconds. If you set this option to true, it will run strictly according to the latency seconds you set without additional calculation logic.
keyobjectrequired["remote_addr", "server_addr", "http_x_real_ip", "http_x_forwarded_for", "consumer_name"]to limit the concurrency level.
For example, one can use the host name (or server zone) as the key so that we limit concurrency per host name. Otherwise, we can also use the client address as the key so that we can avoid a single client from flooding our service with too many parallel connections or requests.
Now accept those as key: "remote_addr"(client's IP), "server_addr"(server's IP), "X-Forwarded-For/X-Real-IP" in request header, "consumer_name"(consumer's username).
rejected_codestringoptional503[200,...,599]the HTTP status code returned when the request exceeds conn + burst will be rejected.
rejected_msgstringoptionalnon-emptythe response body returned when the request exceeds conn + burst will be rejected.
allow_degradationbooleanoptionalfalseWhether to enable plugin degradation when the limit-conn function is temporarily unavailable. Allow requests to continue when the value is set to true, default false.

Key can be customized by the user, only need to modify a line of code of the plug-in to complete. It is a security consideration that is not open in the plugin.

When used in the stream proxy, only remote_addr and server_addr can be used as key. And rejected_code is meaningless.

How To Enable#

Here's an example, enable the limit-conn plugin on the specified route:

curl -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{    "methods": ["GET"],    "uri": "/index.html",    "plugins": {        "limit-conn": {            "conn": 1,            "burst": 0,            "default_conn_delay": 0.1,            "rejected_code": 503,            "key": "remote_addr"        }    },    "upstream": {        "type": "roundrobin",        "nodes": {            "": 1        }    }}'

You can open dashboard with a browser:, to complete the above operation through the web interface, first add a route:

Then add limit-conn plugin:

Test Plugin#

The parameters of the plugin enabled above indicate that only one concurrent request is allowed. When more than one concurrent request is received, will return 503 directly.

curl -i &
curl -i<html><head><title>503 Service Temporarily Unavailable</title></head><body><center><h1>503 Service Temporarily Unavailable</h1></center><hr><center>openresty</center></body></html>

This means that the limit request concurrency plugin is in effect.

Disable Plugin#

When you want to disable the limit-conn plugin, it is very simple, you can delete the corresponding json configuration in the plugin configuration, no need to restart the service, it will take effect immediately:

curl -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{    "methods": ["GET"],    "uri": "/index.html",    "id": 1,    "plugins": {    },    "upstream": {        "type": "roundrobin",        "nodes": {            "": 1        }    }}'

The limit-conn plugin has been disabled now. It works for other plugins.