Re: 回复:Re: using nginx workers
bartbant
nginx-forum at nginx.us
Wed Dec 7 00:15:12 UTC 2011
> 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
More information about the nginx
mailing list