Auto detect the number of CPU's and set worker_processes

I am trying to get fancy and have nginx.conf auto-detect the number of
CPU’s on the server and then set worker_processes to that number. Here
is
what I have:

worker_processes $(cat /proc/cpuinfo | grep "processor" | sort -u | 

wc
-l);

Unfortunately, that is throwing an error on nginx start. Is it even
possible
to run shell commands from inside nginx configuration files?

Thanks.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,230757,230757#msg-230757

Hi,

On Sun, Sep 16, 2012 at 7:55 AM, justin [email protected] wrote:

It’s not supported in current nginx.

But you may try out tengine, which is a nginx distribution and has the
exact feature you want: http://tengine.taobao.org/document/core.html
More features can be found at: http://tengine.taobao.org/

Regards,

Hello!

On Sat, Sep 15, 2012 at 07:55:49PM -0400, justin wrote:

I am trying to get fancy and have nginx.conf auto-detect the number of
CPU’s on the server and then set worker_processes to that number. Here is
what I have:

worker_processes $(cat /proc/cpuinfo | grep "processor" | sort -u | wc

-l);

Unfortunately, that is throwing an error on nginx start. Is it even possible
to run shell commands from inside nginx configuration files?

No, it’s not currently supported. You may try e.g. make + sed (or
any other templating system) to do this, as well as many other
macro-expansion related things.

Maxim D.

On Sat, 15 Sep 2012 19:55:49 -0400, “justin” [email protected]
wrote:

I am trying to get fancy and have nginx.conf auto-detect

Not knowing how to auto-detect it, I usually just excute this as ROOT:

sed -i ‘/^worker_processes/s,[0-9]+,’"$(sort -u /proc/cpuinfo | grep
-c processor)"’,’ /etc/nginx/nginx.conf

On Sep 16, 2012, at 3:55 , justin wrote:

I am trying to get fancy and have nginx.conf auto-detect the number of
CPU’s on the server and then set worker_processes to that number. Here is
what I have:

worker_processes $(cat /proc/cpuinfo | grep “processor” | sort -u | wc
-l);

Unfortunately, that is throwing an error on nginx start. Is it even possible
to run shell commands from inside nginx configuration files?

You can configure it via command line:
nginx -g “worker_processes cat /proc/cpuinfo | grep "processor" | sort -u | wc -l;”


Igor S.
http://nginx.com/support.html

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