# CPU load monitoring / dynamically limit number of connections to server

**URL:** <https://www.ruby-forum.com/t/cpu-load-monitoring-dynamically-limit-number-of-connections-to-server/244651>\
**Category:** NGINX\
**Created:** [May 19, 2016, 5:12pm UTC](https://www.ruby-forum.com/t/cpu-load-monitoring-dynamically-limit-number-of-connections-to-server/244651 "2016-05-19T17:12:19Z")\
**Posts on this page:** 6\
**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:** [May 19, 2016, 5:12pm UTC](https://www.ruby-forum.com/t/cpu-load-monitoring-dynamically-limit-number-of-connections-to-server/244651/1 "2016-05-19T17:12:19Z")

</div>

Hi to all,

Is there a way to monitor the busyness of my dedicated server cpu cores  
and  
stop serving new connections passed a given cpu load threshold?  
Put another way, what is the standard approach/technique to dynamically  
limit the maximum number of connections my machine can cope with?

Thank you,

ohenley

Posted at Nginx Forum:

> **[CPU load monitoring / dynamically limit number of connections to server](https://forum.nginx.org/read.php?2,267003,267003#msg-267003)**
>
> Hi to all, Is there a way to monitor the busyness of my dedicated server cpu cores and stop serving new connections passed a given cpu load threshold? Put another way, what is the standard approach/technique to dynamically limit the maximum number of...

---

<div class="post-metadata">

**Author:** ![ohenley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6de8d8/32.png) [@ohenley](https://www.ruby-forum.com/u/ohenley)\
**Post date:** [May 20, 2016, 8:26pm UTC](https://www.ruby-forum.com/t/cpu-load-monitoring-dynamically-limit-number-of-connections-to-server/244651/2 "2016-05-20T20:26:47Z")

</div>

[Module ngx\_http\_limit\_conn\_module](http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html) - not  
system load based though

–  
Anoop P Alias

---

<div class="post-metadata">

**Author:** ![ohenley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6de8d8/32.png) [@ohenley](https://www.ruby-forum.com/u/ohenley)\
**Post date:** [May 20, 2016, 9:46pm UTC](https://www.ruby-forum.com/t/cpu-load-monitoring-dynamically-limit-number-of-connections-to-server/244651/3 "2016-05-20T21:46:49Z")

</div>

‎Bear in mind one IP can be many eyeballs. I use the module with a  
setting of 10 per IP. I set the firewall to a higher limit to allow some  
non-web services, but not infinite. This can fight back a very  
unsophisticated DOS attack. A real DOS is distributed, so the IP limit  
won’t be useful.

I had a document hit Twitter and their servers hammered my lowly VPS.  
Besides an IP limit, I suggest a rewrite to eliminate hot linking, which  
effectively is what Twitter can do. If they tweet a link to a webpage,  
no problem. That would limit those twitter users to each individually  
set their browser ‎to a webpage, which slows the requests. Out of  
paranoia, I blocked all of Twitter IP space. The same for Facebook.  
Again, the eyeballs can use their ISP via a link. I’m not comfortable  
with social media companies directly accessing my server since they have  
huge data bandwidth.

That leaves large corporations and universities as the situation where  
one IP is really many eyeballs. A connection limit of 10 will be too low  
in these cases occasionally, but you have to set the limit somewhere.

Original Message  
From: Anoop A.  
Sent: Friday, May 20, 2016 11:26 AM  
To: Nginx  
Reply To: removed\_email\_address@domain.invalid  
Subject: Re: CPU load monitoring / dynamically limit number of  
connections to server

[Module ngx\_http\_limit\_conn\_module](http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html) - not  
system load based though

–  
Anoop P Alias

* * *

nginx mailing list  
removed\_email\_address@domain.invalid  
[http://mailman.nginx.org/mailman/listinfo/nginx](http://mailman.nginx.org/mailman/listinfo/nginx)

---

<div class="post-metadata">

**Author:** ![ohenley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6de8d8/32.png) [@ohenley](https://www.ruby-forum.com/u/ohenley)\
**Post date:** [May 21, 2016, 9:37pm UTC](https://www.ruby-forum.com/t/cpu-load-monitoring-dynamically-limit-number-of-connections-to-server/244651/4 "2016-05-21T21:37:27Z")

</div>

Found it:

[https://www.scalyr.com/community/guides/how-to-monitor-nginx-the-essential-guide](https://www.scalyr.com/community/guides/how-to-monitor-nginx-the-essential-guide)

Posted at Nginx Forum:

> **[Re: CPU load monitoring / dynamically limit number of connections to server](https://forum.nginx.org/read.php?2,267003,267019#msg-267019)**
>
> Hi to all, Is there a way to monitor the busyness of my dedicated server cpu cores and stop serving new connections passed a given cpu load threshold? Put another way, what is the standard approach/technique to dynamically limit the maximum number of...

---

<div class="post-metadata">

**Author:** ![ohenley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6de8d8/32.png) [@ohenley](https://www.ruby-forum.com/u/ohenley)\
**Post date:** [May 25, 2016, 4:07pm UTC](https://www.ruby-forum.com/t/cpu-load-monitoring-dynamically-limit-number-of-connections-to-server/244651/5 "2016-05-25T16:07:30Z")

</div>

Thx gariac.

Posted at Nginx Forum:

> **[Re: CPU load monitoring / dynamically limit number of connections to server](https://forum.nginx.org/read.php?2,267003,267145#msg-267145)**
>
> Hi to all, Is there a way to monitor the busyness of my dedicated server cpu cores and stop serving new connections passed a given cpu load threshold? Put another way, what is the standard approach/technique to dynamically limit the maximum number of...

---

<div class="post-metadata">

**Author:** ![ohenley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6de8d8/32.png) [@ohenley](https://www.ruby-forum.com/u/ohenley)\
**Post date:** [May 22, 2016, 3:39am UTC](https://www.ruby-forum.com/t/cpu-load-monitoring-dynamically-limit-number-of-connections-to-server/244651/6 "2016-05-22T03:39:37Z")

</div>

Does that really limit per the OP’s request? Reading the document, it  
seems like a monitoring module, but not something that limits nginx. For  
example, ulimit is just a linux command. Maybe you could set a chron job  
to sniff the load based on this monitoring and adjust system parameters  
accordingly. (Beware of positive feedback loops.!

This was my method to set limits on nginx. First, download  
[http://www.labs.hpe.com/research/linux/httperf/](http://www.labs.hpe.com/research/linux/httperf/)  
I found my server could handle 3000 requests per minute. Note this is  
running httperf ON the server itself. This does not include the  
connection to the Internet. But now you know how much abuse the server  
can take.

Then I ran httperf over the Internet from a number of different ISPs.  
The performace was more like 100 requests per second at best. Clearly  
the pipe I share is the limiting factor. ‎I pulled a somewhat arbitrary  
10 users at a time limit, which is actually real life most of the time.  
I’m not CNN or a porn site. So I set the limit request to 10 per second.  
Remember every photo, document, etc. takes one request.

This is barely scientific, but it is better than nothing.

Original Message  
From: ohenley  
Sent: Saturday, May 21, 2016 12:37 PM  
To: removed\_email\_address@domain.invalid  
Reply To: removed\_email\_address@domain.invalid  
Subject: Re: CPU load monitoring / dynamically limit number of  
connections to server

Found it:

[https://www.scalyr.com/community/guides/how-to-monitor-nginx-the-essential-guide](https://www.scalyr.com/community/guides/how-to-monitor-nginx-the-essential-guide)

Posted at Nginx Forum:

> **[Re: CPU load monitoring / dynamically limit number of connections to server](https://forum.nginx.org/read.php?2,267003,267019#msg-267019)**
>
> Hi to all, Is there a way to monitor the busyness of my dedicated server cpu cores and stop serving new connections passed a given cpu load threshold? Put another way, what is the standard approach/technique to dynamically limit the maximum number of...

* * *

nginx mailing list  
removed\_email\_address@domain.invalid  
[http://mailman.nginx.org/mailman/listinfo/nginx](http://mailman.nginx.org/mailman/listinfo/nginx)
