# Limit\_conn is not limiting the number of connections in my use case

**URL:** <https://www.ruby-forum.com/t/limit-conn-is-not-limiting-the-number-of-connections-in-my-use-case/244811>\
**Category:** NGINX\
**Created:** [June 18, 2016, 5:49pm UTC](https://www.ruby-forum.com/t/limit-conn-is-not-limiting-the-number-of-connections-in-my-use-case/244811 "2016-06-18T17:49:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [June 18, 2016, 5:49pm UTC](https://www.ruby-forum.com/t/limit-conn-is-not-limiting-the-number-of-connections-in-my-use-case/244811/1 "2016-06-18T17:49:35Z")

</div>

Hello,

I have a hard time understanding limit\_conn

My NGINX has the configuration below. I would expect to see 16  
connections  
on the backend server 192.168.10.131 defined in the “dynamic” directive.

Yet I see ~50-60 connections.

QPS: 3056  
Active connections: 58  
QPS: 3064  
Active connections: 54  
QPS: 3063  
Active connections: 59

Please note the QPS (Query Per Second) limiting works well.

I would greatly appreciate any tip as to what is going on with my use of  
the  
limit\_conn.

Thank you.

upstream locallayer {  
server 127.0.0.1:7999;  
keepalive 32;  
}

server {  
listen 8002;  
proxy\_intercept\_errors on;

```
location / {
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_pass http://locallayer;
}
error_page 302 400 403 404 408 500 502 503 504 = /empty;
location /empty {
    return 204;
}

```

}

upstream dynamic {  
least\_conn;  
server 192.168.10.131:9990;  
keepalive 32;  
}

limit\_conn\_zone $binary\_remote\_addr zone=peripconn:100m;  
limit\_conn\_zone $server\_name zone=perserver:10m;  
limit\_req\_zone $binary\_remote\_addr zone=peripreq:1000m rate=3000r/s;

server {  
listen 7999;  
server\_name [local.com](http://local.com);  
proxy\_intercept\_errors on;  
location / {  
allow 127.0.0.1;  
deny all;  
limit\_conn peripconn 32;  
limit\_conn perserver 32;  
limit\_req zone=peripreq burst=100 nodelay;  
limit\_conn\_status 503;  
limit\_req\_status 503;  
proxy\_http\_version 1.1;  
proxy\_set\_header Connection “”;  
proxy\_connect\_timeout 10ms;  
proxy\_send\_timeout 10ms;  
proxy\_read\_timeout 60ms;  
proxy\_pass [http://dynamic](http://dynamic);  
}  
error\_page 302 400 403 404 408 500 502 503 504 = /empty;  
location /empty {  
return 204;  
}  
}

Posted at Nginx Forum:

> **[limit\_conn is not limiting the number of connections in my use case](https://forum.nginx.org/read.php?2,267688,267688#msg-267688)**
>
> Hello, I have a hard time understanding limit\_conn My NGINX has the configuration below. I would expect to see 16 connections on the backend server 192.168.10.131 defined in the "dynamic" directive. Yet I see ~50-60 connections.

---

<div class="post-metadata">

**Author:** ![matt\_l](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/47e85d/32.png) [@matt\_l](https://www.ruby-forum.com/u/matt_l)\
**Post date:** [June 19, 2016, 12:41am UTC](https://www.ruby-forum.com/t/limit-conn-is-not-limiting-the-number-of-connections-in-my-use-case/244811/2 "2016-06-19T00:41:24Z")

</div>

On Saturday 18 June 2016 11:49:16 matt\_l wrote:

> Active connections: 58  
> QPS: 3064  
> Active connections: 54  
> QPS: 3063  
> Active connections: 59
> 
> Please note the QPS (Query Per Second) limiting works well.
> 
> I would greatly appreciate any tip as to what is going on with my use of the  
> limit\_conn.  
> [..]

The limit\_conn module doesn’t limit number of connections to upstream.  
It’s all about client connections.

Since you have configured “keepalive 32” each worker process can keep  
open  
up to 32 connections to your backend even without client requests.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![matt\_l](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/47e85d/32.png) [@matt\_l](https://www.ruby-forum.com/u/matt_l)\
**Post date:** [June 23, 2016, 9:33am UTC](https://www.ruby-forum.com/t/limit-conn-is-not-limiting-the-number-of-connections-in-my-use-case/244811/3 "2016-06-23T09:33:49Z")

</div>

try this one plz

> **[GitHub - cfsego/nginx-limit-upstream: limit the number of connections to...](https://github.com/cfsego/nginx-limit-upstream)**
>
> limit the number of connections to upstream for NGINX - GitHub - cfsego/nginx-limit-upstream: limit the number of connections to upstream for NGINX

On Sun, Jun 19, 2016 at 6:41 AM, Valentin V. Bartenev [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
