1、GCC参数: 默认Nginx使用的GCC编译参数是-O,需要更加优化可以使用以下两个参数–with-cc-opt=’-O3′–with-cpu-opt=opteron 使得编译针对特定CPU以及增加GCC的优化,针对优化后的结果.我们进行测试结果表明使用-O2以及以上的参数,可以微量增加性能1%左右,而O2和O3基本可以认为是相同的: ./http_load-parallel100-seconds10urls 10811fetches,100maxparallel,5.23252e+06bytes,in10seconds a、默认参数-O 1087.2fetches/sec,526204bytes/sec msecs/connect:45.5374mean,63.984max, 1.008minmsecs/first-response:45.7679 mean,64.201max,2.216min1088.9fetches/sec,527027bytes/sec msecs/connect:45.0159mean,65.291max,0.562minmsecs/first-response:46.1236mean,67.397max,9.169min 1102.2fetches/sec,533465bytes/sec msecs/connect:44.5593mean,67.649max,0.547min msecs/first-response:45.499mean,67.849max,2.495min b、优化编译后-O2 1081.1fetches/sec,523252bytes/sec msecs/connect:45.7144 mean,63.324max,0.823minmsecs/first-response:46.1008mean,61.814max,4.487min 1110.2fetches/sec,537337bytes/sec msecs/connect:43.4943mean,60.066max,0.715min msecs/first-response:45.756 mean,62.076max,3.536min 1107fetches/sec,535788bytes/sec msecs/connect:44.872mean,3036.51max,0.609min msecs/first-response:44.8625mean,59.831max,3.178min c、优化编译后-O3 1097.5fetches/sec,531189bytes/sec msecs/connect:45.1355mean,3040.24max,0.583min msecs/first-response:45.3036mean,68.371max,4.416min 1111.6fetches/sec,538014bytes/sec msecs/connect:44.2514mean,64.831max,0.662min msecs/first-response:44.8366mean,69.904max,3.928min 1099.4fetches/sec,532109bytes/sec msecs/connect:44.7226mean,61.445max,0.596min msecs/first-response:45.4883mean,287.113max,3.336min 2、修改Nginx的header伪装服务器 #cdNginx-0.6.31 #visrc/core/Nginx.h #ifndef_NGINX_H_INCLUDED_ #define_NGINX_H_INCLUDED_ #defineNGINX_VERSION"7.2" #defineNGINX_VER"Freeke/"NGINX_VERSION #defineNGINX_VAR"NGINX" #defineNGX_OLDPID_EXT".oldbin" #endif/*_NGINX_H_INCLUDED_*/
#curl-Iwww.chinarenservice.com HTTP/1.1200OK Server:Freeke/7.2 Date:Mon,24Nov200802:42:51GMT Content-Type:text/html;charset=gbk Transfer-Encoding:chunked Connection:keep-alive 3、Tcmalloc优化Nginx性能 从Nginx0.6.29添加Feature:thengx_google_perftools_module,那Nginx也可以利用Tcmalloc来提长性能。 [root@sunny~]#wgethttp://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz [root@sunny~]#tarzxvflibunwind-0.99-alpha.tar.gz [root@sunny~]#cdlibunwind-0.99-alpha/ [root@sunny~]#CFLAGS=-fPIC./configure [root@sunny~]#makeCFLAGS=-fPIC [root@sunny~]#makeCFLAGS=-fPICinstall [root@sunny~]#wgethttp://google-perftools.googlecode.com/files/google-perftools-0.98.tar.gz [root@sunny~]#tarzxvfgoogle-perftools-0.98.tar.gz [root@sunny~]#cdgoogle-perftools-0.98/ [root@sunny~]#./configure [root@sunny~]#make&&makeinstall [root@sunny~]#echo"/usr/local/lib">/etc/ld.so.conf.d/usr_local_lib.conf [root@sunny~]#ldconfig [root@sunnylocal]#lsof-n|greptcmalloc Nginx 7323 root mem REG 8,2 1412859 440730 /usr/local/lib/libtcmalloc.so.0.0.0 Nginx 7324 www mem REG 8,2 1412859 440730 /usr/local/lib/libtcmalloc.so.0.0.0 Nginx 7325 www mem REG 8,2 1412859 440730 /usr/local/lib/libtcmalloc.so.0.0.0 Nginx 7326 www mem REG 8,2 1412859 440730 /usr/local/lib/libtcmalloc.so.0.0.0 Nginx 7327 www mem REG 8,2 1412859 440730 /usr/local/lib/libtcmalloc.so.0.0.0 Nginx 7328 www mem REG 8,2 1412859 440730 /usr/local/lib/libtcmalloc.so.0.0.0 Nginx 7329 www mem REG 8,2 1412859 440730 /usr/local/lib/libtcmalloc.so.0.0.0 Nginx 7330 www mem REG 8,2 1412859 440730 /usr/local/lib/libtcmalloc.so.0.0.0 Nginx 7331 www mem REG 8,2 1412859 440730 /usr/local/lib/libtcmalloc.so.0.0.0 在编译Nginx时添加参数--with-google_perftools_module 4、减小编译后文件大小: 默认的Nginx编译选项里居然是用debug模式(-g)的(debug模式会插入很多跟踪和ASSERT之类),编译以后一个Nginx有好几兆。去掉Nginx的debug模式编译,编译以后只有375K(Nginx-0.5.33,gcc4)。在auto/cc/gcc,最后几行有: #debugCFLAGS=”$CFLAGS-g” 注释掉或删掉这几行,重新编译即可。
上一篇:Nginx设置如何根据URL分发_应用软件_系统软件
下一篇:几种第三方浏览器介绍_应用软件_系统软件