Nginx worker_cpu_affinity

By Default, without setting worker_cpu_affinity directive in nginx.conf, linux kernel will spread all nginx’s worker all over CPUs.

I have 4 logical CPUs on my server, which is CPU0 – CPU3

Cpu0  :  2.9%us,  0.9%sy,  0.0%ni, 88.9%id,  7.2%wa,  0.0%hi,  0.2%si,  0.0%st
Cpu1  :  1.8%us,  0.6%sy,  0.0%ni, 95.3%id,  2.2%wa,  0.0%hi,  0.1%si,  0.0%st
Cpu2  :  2.4%us,  0.7%sy,  0.0%ni, 94.3%id,  2.5%wa,  0.0%hi,  0.1%si,  0.0%st
Cpu3  :  1.9%us,  0.7%sy,  0.0%ni, 96.7%id,  0.6%wa,  0.0%hi,  0.0%si,  0.0%st

Using default setting, nginx’s worker always bind to those 4 logical CPUs. which is has “f” bitmask

# taskset -p 12348
pid 25748's current affinity mask: f
# taskset -p 12349
pid 25749's current affinity mask: f
# taskset -p 12351
pid 25751's current affinity mask: f
# taskset -p 12352
pid 25752's current affinity mask: f
# taskset -p 12353
pid 25753's current affinity mask: f

CPU affinity is represented as a bitmask (given in hexadecimal), with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU.
Examples:

How To Make php-fpm Listen On Both Tcp And Unix Socket?

I need to make php-fpm listeing on both tcp/unix socket, and this is how it done.
(this was not pretty workarround i guess, but it work 😀 )
first  download php rpm source

$ wget http://centos.alt.ru/pub/php-fpm/5.3.3-2/SRPMS/php-5.3.3-2.el5.src.rpm

Compile and install

$ rpmbuild --rebuild php-5.3.3-2.el5.src.rpm
$ sudo rpm -Uvh /path/to/RPMS/php-*

Configuring the default php-fpm for using tcp socket
Edit www.conf

$ sudo vi /etc/php-fpm.d/www.conf

Find line containing

listen = 127.0.0.1:9000

We can make it listening to port what ever we desire, ie 9001 etc
Start php-fpm first instance

$ sudo service php-fpm start

Configuring php-fpm for using unix socket

$ sudo cp /etc/php-fpm.conf /etc/php-fpm2.conf
$ sudo cp -rp /etc/php-fpm.d /etc/php-fpm2.d

Edit /etc/php-fpm2.conf

include=/etc/php-fpm2.d/*.conf
pid = /var/run/php-fpm/php-fpm2.pid
error_log = /var/log/php-fpm/error2.log

Edit /etc/php-fpm2.d/www.conf

listen = /tmp/php-fpm.sock
php_admin_value[error_log] = /var/log/php-fpm/www-error2.log

Nginx, Subdirs Without Trailing Slash

If you set [xml] location /mail/ { fastcgi_pass localhost:8888; ... } [/xml] and request "/mail" then nginx will return external redirect to "/mail/". If you do not want the redirect, then [xml] location = /mail { fastcgi_pass localhost:8888; fastcgi_param SCRIPT_FILENAME $document_root/index.php; fastcgi_param SCRIPT_NAME /index.php; root /var/www; } location /mail/ {…

Nginx, Geo IP and Distributed Server

When you have many networks, which are located far apart and in different location. You want users to access the server closest to their network. town1 users when accessing the main server, the server will diredirect town1.example.com, and the town2's users will be redirected to town2.example.com. [xml] http { geo…

Nginx, limit website visitor bandwidth by country

First grab this perl script which you will use to convert Maxmind’s geo IP database into a format usable by Nginx. make it executable [bash] $ chmod 755 geo2nginx.pl [/bash] Then download Maxmind’s latest GeoLite country database in CSV format. Unzip it, and run perl script [bash] $ unzip GeoIPCountryCSV.zip…

Linux related Picture Found On Internet

Linux (commonly /ˈlɪnÉ™ks/ lin-É™ks in English, also pronounced /ˈlɪnÊŠks/ lin-uuks in Europe) refers to the family of Unix-like computer operating systems using the Linux kernel. Linux can be installed on a wide variety of computer hardware, ranging from mobile phones, tablet computers, routers, and video game consoles, to mainframes and…

Nginx enabling TLS SNI support on centos 5

By default centos 5.x has openssl-0.9.8e which is not have tls extention for  sni support. this is workaround on how to get nginx 0.8.48 rpm with TLS SNI enabled

Step 1:

download openssl source, example  openssl-0.9.8l. extract it in /usr/src

$ cd /usr/src
$ wget http://www.openssl.org/source/openssl-0.9.8l.tar.gz
$ tar xvzf openssl-0.9.8l.tar.gz

Step 2:

Download nginx rpm source, example nginx-0.8.49-1.el5.src.rpm

$ wget http://centos.alt.ru/pub/nginx/0.8/RHEL/SRPMS/nginx-0.8.49-1.el5.src.rpm
$ rpm -Uvh nginx-0.8.49-1.el5.src.rpm

Move to directory where the spec file is in and edit nginx.spec

$ cd /path/to/rpm/SPECS/
$ vi nginx.spec