Using nginx workers

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?

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

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

Best Regards
Jingli Lai
E-mail: [email protected]

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/ 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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs