nginx优化(1)

1、编译过程,默认为Debug 导致编译完后nginx较大,可考虑关闭debug,让nginx编译完后保持小巧,方法:在  auto/cc/gcc下注释掉
    #Debug
    CFLAGS=“¥CFLAGS -g”

2、找到CPU类型,针对特定CPU类型的编译优化
   cat /proc/cpuinfo|grep "model name"
   查询cpu
在GCC编译时使用-O
--with-cc-opt=‘-03’
--with-cpu-opt=。。。 包括pentium,pentiumpro,pentium3,pentium4,athlon,optron,amd64,sparc32, sparc64, ppc64

3、使用google的内存分配库 TCMalloc(Thread-Caching Malloc) 来优化
安装libunwind(64位机需要)和google-perftools
1)安装libunwind
http://download.savannah.gnu.org/releases/libunwind
解压并进入目录
  [root@abc]#CFLAGS=-fPIC ./configure
  [root@abc]#make CFLAGS=-fPIC
  [root@abc]#make CFLAGS=-fPIC install
2)  安装google-gperftools
解压并进入目录
  [root@abc]#./configure
  [root@abc]#make
  [root@abc]#make install
  [root@abc]#echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
  [root@abc]#ldconfig

4编译nginx
./configure --prefix=/usr/local/nginx --with-google_perftools_module
  [root@abc]#lmake
  [root@abc]#lmake install

5为google-perftools添加线程目录
  [root@abc]mkdir /tmp/tcmalloc
  [root@abc]chmod 777 /tmp/tcmalloc
将nginx.conf 修改
#pid logs/nginx.pid
google_perftools_profiles /tmp/tcmalloc

6启动nginx并查看有没有 tcmalloc
  [root@abc]lsof -n|grep tcmalloc
如果在nginx 中设置 worker_processes 为2 则出现2个线程,类推


猜你喜欢

转载自nimolean.iteye.com/blog/2243359