2)安装google-perftools
wget http://google-perftools.googlecode.com/files/google-perftools-1.7.tar.gz tar xzvf google-perftools-1.7.tar.gz cd google-perftools-1.7 |
然后开始配置:
./configure --prefix=/usr --enable-frame-pointers (32位可以不添加--enable-frame-pointers) make --j4 && make install |
nginx configure 参数加上--with-google-perftools 重新编译nginx
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --without-http_fastcgi_module --without-http_proxy_module --without-http_upstream_ip_hash_module --without-http_autoindex_module --without-http_ssi_module --without-http_proxy_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_uwsgi_module --without-http_scgi_module --without-http_memcached_module –with-google_perftools_module make && make install |
3)在nginx.conf 的pid部分下,增加
google_perftools_profiles /data0/google_cache; |
重启
service nginx restart |
即可生效。
三、nginx 工作进程优化
通常的做法是在nginx.conf 的
worker_processes 8; |
下面增加
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000; |
但是在纯静态文件环境下,我们可以增加nginx 工作进程,来提升nginx的工作效率。
工作进程 为24个,worker_cpu_affinity 可以这样来调整
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000; |
重启nginx后生效,可以充分利用nginx的对多核心cpu的良好的特性,大幅提升网站的访问速度。