Nginx 최적화 (전재)

6180 단어 최적화 하 다.

1. Nginx
Nginx , debug , debug ASSERT , , Nginx 。 Nginx debug , Nginx , , , debug , :
Nginx , auto/cc/gcc , :
# debug
CFLAGS=”$CFLAGS -g”
, debug 。
2. CPU CPU
Nginx , GCC “-O”, GCC , :
--with-cc-opt='-O3'
--with-cpu-opt=CPU # CPU , :pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64
CPU , :
[root@localhost home]#cat /proc/cpuinfo | grep "model name"
、 TCMalloc Nginx
TCMalloc Thread-Caching Malloc, “google-perftools” 。 glibc malloc ,TCMalloc , , 。 Nginx TCMalloc 。
TCMalloc , libunwind(32 ) google-perftools ,libunwind 64 CPU 。 TCMalloc Nginx :
1. libunwind
http://download.savannah.gnu.org/releases/libunwind libunwind , libunwind-0.99-alpha.tar.gz, :

[root@localhost home]#tar zxvf libunwind-0.99-alpha.tar.gz
[root@localhost home]# cd libunwind-0.99-alpha/
[root@localhost libunwind-0.99-alpha]#CFLAGS=-fPIC ./configure
[root@localhost libunwind-0.99-alpha]#make CFLAGS=-fPIC
[root@localhost libunwind-0.99-alpha]#make CFLAGS=-fPIC install
2. google-perftools
http://google-perftools.googlecode.com google-perftools , google-perftools-1.8.tar.gz, :

[root@localhost home]#tar zxvf google-perftools-1.8.tar.gz
[root@localhost home]#cd google-perftools-1.8/
[root@localhost google-perftools-1.8]# ./configure
[root@localhost google-perftools-1.8]#make && make install
[root@localhost google-perftools-1.8]#echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
[root@localhost google-perftools-1.8]# ldconfig
,google-perftools 。
3. Nginx
Nginx google-perftools, “–with-google_perftools_module” Nginx, :

[root@localhostnginx-0.7.65]#./configure \
>--with-google_perftools_module --with-http_stub_status_module --prefix=/opt/nginx
[root@localhost nginx-0.7.65]#make
[root@localhost nginx-0.7.65]#make install
Nginx 。
4. google-perftools
, /tmp/tcmalloc , :

[root@localhost home]#mkdir /tmp/tcmalloc
[root@localhost home]#chmod 0777 /tmp/tcmalloc
5. Nginx
nginx.conf , pid :

#pid logs/nginx.pid;
google_perftools_profiles /tmp/tcmalloc;
, Nginx, google-perftools 。
6.
google-perftools , :

[root@ localhost home]# lsof -n | grep tcmalloc
nginx 2395 nobody 9w REG 8,8 0 1599440 /tmp/tcmalloc.2395
nginx 2396 nobody 11w REG 8,8 0 1599443 /tmp/tcmalloc.2396
nginx 2397 nobody 13w REG 8,8 0 1599441 /tmp/tcmalloc.2397
nginx 2398 nobody 15w REG 8,8 0 1599442 /tmp/tcmalloc.2398
Nginx , worker_processes 4, 4 Nginx , 。 Nginx PID 。
, TCMalloc Nginx 。
、Nginx
, Linux Nginx , 。

net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 1
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
/etc/sysctl.conf , :
[root@ localhost home]#/sbin/sysctl -p

 net.ipv4.tcp_max_tw_buckets timewait , 180000, 6000。
 net.ipv4.ip_local_port_range 。
 net.ipv4.tcp_tw_recycle timewait 。
 net.ipv4.tcp_tw_reuse , TIME-WAIT sockets TCP 。
 net.ipv4.tcp_syncookies SYN Cookies, SYN , cookies 。
 net.core.somaxconn 128, tcp , , , , 。
 net.core.netdev_max_backlog , 。
 net.ipv4.tcp_max_orphans TCP 。 , 。 DoS 。 , 。
 net.ipv4.tcp_max_syn_backlog 。 128MB , 1024, 128。
 net.ipv4.tcp_synack_retries SYN+ACK 。
 net.ipv4.tcp_syn_retries SYN 。
 net.ipv4.tcp_fin_timeout FIN-WAIT-2 。 60 。 , Web , 。
 net.ipv4.tcp_keepalive_time keepalive ,TCP keepalive 。 2( )。

좋은 웹페이지 즐겨찾기