# Using nginx workers

**URL:** <https://www.ruby-forum.com/t/using-nginx-workers/214577>\
**Category:** NGINX\
**Created:** [December 6, 2011, 9:55am UTC](https://www.ruby-forum.com/t/using-nginx-workers/214577 "2011-12-06T09:55:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [December 6, 2011, 9:55am UTC](https://www.ruby-forum.com/t/using-nginx-workers/214577/1 "2011-12-06T09:55:48Z")

</div>

I have a 2 cpu core vps setup, currently with 2 workers (load is  
pretty small atm), would using 4 workers on a 2 core cpu be safe?  
would there be timeouts? any other issues?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 6, 2011, 10:05am UTC](https://www.ruby-forum.com/t/using-nginx-workers/214577/2 "2011-12-06T10:05:40Z")

</div>

On Tuesday 06 December 2011 12:54:52 Fanboy wrote:

> I have a 2 cpu core vps setup, currently with 2 workers (load is  
> pretty small atm), would using 4 workers on a 2 core cpu be safe?

Yes. It would be safe.

> would there be timeouts? any other issues?

No issues.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 6, 2011, 10:18am UTC](https://www.ruby-forum.com/t/using-nginx-workers/214577/3 "2011-12-06T10:18:03Z")

</div>

and how many workers is best for a 2 core cpu?thanks.

–

Best Regards  
Jingli Lai  
E-mail: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 7, 2011, 1:15am UTC](https://www.ruby-forum.com/t/using-nginx-workers/214577/4 "2011-12-07T01:15:43Z")

</div>

> to set as many workers as number of physical CPU  
> cores you have  
> (or virtual, if you in VM environment).

The reason why you should set the number of workers to the number of CPU  
cores is that every worker is single threaded and that’s why every  
worker will use up just one core. So 1 worker on a quad core would give  
you a max of 25% cpu usage. On a quad core you would use 4 workers  
(worker\_processes) so one worker is scheduled to 1 cpu core. More  
workers would increase swapping processes in and out of the cpu cache.

Additionally, if you run linux you might wanna check out  
ulimit -n  
as this will tell you whats the maximum number of file descriptors (= ~  
max connections per worker) and set worker\_processes to this value  
(max!).

To check out how many connections you are using you can add this to your  
virtual host config (probably at /etc/nginx/sites-available/default)

```
    location /nginx_status {
            stub_status on;
            access_log off;
            allow 127.0.0.1;
            deny all;
    }

```

and run  
curl localhost/nginx\_status in console (assume you use linux).  
to see how many connections you really need.  
max connections = worker\_processes \* worker\_connections

If running the latest precompiled stable (1.0.10) you can also check out  
munin [http://munin-monitoring.org/](http://munin-monitoring.org/) as it comes with an nginx plugin and  
shows you the number of connections in graphs by day, week, month and  
year. (munin is the best free monitoring tool i could find on the web.  
its definitely worth checking out to discover problems, watch the growth  
and to predict upcoming bottlenecks

Hope it helps.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,219683,219737#msg-219737](http://forum.nginx.org/read.php?2,219683,219737#msg-219737)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 6, 2011, 10:45am UTC](https://www.ruby-forum.com/t/using-nginx-workers/214577/5 "2011-12-06T10:45:26Z")

</div>

On Tuesday 06 December 2011 13:17:30 laijingli2006 wrote:

> and how many workers is best for a 2 core cpu?thanks.

It depends on many factors, including the number of hard disks  
and their usage pattern. IMO, in most cases, it should be good  
to set as many workers as number of physical CPU cores you have  
(or virtual, if you in VM environment).

But, I haven’t a lot of experience in this area.

wbr, Valentin V. Bartenev
