草庐IT

centos 6.3 64bit 用tcmalloc优化nginx

deng304749970 2023-03-28 原文
  一,tcmalloc全称thread-caching malloc,是谷歌开发的开源工具。与标准的glibc库的malloc比。tcmalloc在内存分配效率和速度比malloc高。至于为什么比malloc,有兴趣可以参考。下面这个网址。

  1. http://www.mysqlops.com/2011/06/14/google-tcmalloc-malloc.html#more-737 
二,现在开始介绍在64bit centos 6.3的版本中让nginx使用tcmalloc。需要用到的软件都已经上传到附件中。
三,安装libunwind库。

  1. # tar xf libunwind-1.0.tar.gz 
  2. # tar xf libunwind-1.0 
  3. #CFLAGS=-fPIC ./configure添加编译参数 
  4. # make CFLAGS=-fPIC 
  5. # make CFLAGS=-fPIC install 
这样执行会出现如下错误:
  1. libtool: install: error: relink `libunwind-setjmp.la' with the above command before installing it 
  2. make[3]: *** [install-libLTLIBRARIES] Error 1 
  3. make[3]: Leaving directory `/down/libunwind-1.0/src' 
  4. make[2]: *** [install-am] Error 2 
  5. make[2]: Leaving directory `/down/libunwind-1.0/src' 
  6. make[1]: *** [install] Error 2 
  7. make[1]: Leaving directory `/down/libunwind-1.0/src' 
  8. make: *** [install-recursive] Error 1 
产生这种问题的原因:autotools兼容性的问题,运行命令autoreconf -i -f  ,在重新编译安装下。

  1. #autoreconf -i -f 
  2. #make clean 
  3. #CFLAGS=-fPIC ./configure 
  4. #make  CFLAGS=-fPIC  
  5. #make  CFLAGS=-fPIC install 
四,安装gpperftools:

  1. #tar xf  gperftools-2.0.tar.gz 
  2. # cd gperftools-2.0 
  3. #./configure  
  4. #make && make install  
这样安装会会报如下错误:
  1. cc1plus: warning: unrecognized command line option "-Wno-unused-result" 
  2. ake: *** [stacktrace.lo] Error 1 
为什么出现在这种错误,因此是64bit系统,至于更深度的解释,安装说明中有。下面重新编译。

  1. #make clean  
  2. #./configure  --enable-frame-pointers  
  3. #make &&  make install  
  4. #echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf 
  5. #ldconfig 
五,编译pcre,使nginx支持http rewrite。

  1. # tar xf pcre-8.10.tar.gz  
  2. # cd pcre-8.10 
  3. # ./configure 
  4. # make && make install 
六,编译nginx

  1. # tar xf nginx-1.2.3.tar.gz  
  2. # ./configure  \
  3. --with-http_ssl_module \ 
  4.   --with-http_flv_module \ 
  5.   --with-http_stub_status_module \ 
  6.   --with-http_gzip_static_module \ 
  7.   --http-client-body-temp-path=/var/tmp/nginx/client/ \ 
  8.   --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 
  9.   --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ 
  10.   --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ 
  11.   --http-scgi-temp-path=/var/tmp/nginx/scgi \ 
  12.   --with-pcre \ 
  13.   --with-google_perftools_module 
  14. # make && make install 
7,为gperftools创建线程目录

  1. #mkdir /tmp/tcmalloc 
  2. #chmod 0777 /tmp/tcmalloc 
8,修改nginx的配置文件

  1. #vim /usr/local/nginx/conf/nginx.conf 
  2. #pid        logs/nginx.pid; 
  3. google_perftools_profiles /tmp/tcmalloc;添加这一行 
9,启动nginx,并验证tcmalloc有没有正常加载

  1. # /usr/local/nginx/sbin/nginx 
  2. # lsof -n |grep tcmalloc 
  3. nginx      1893    nobody    9w      REG              253,0        0      43018 /tmp/tcmalloc.1893 
  4. nginx      1894    nobody   11w      REG              253,0        0      43016 /tmp/tcmalloc.1894 
至此已经替换成功。

有关centos 6.3 64bit 用tcmalloc优化nginx的更多相关文章

  1. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  2. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  3. kvm虚拟机安装centos7基于ubuntu20.04系统 - 2

    需求:要创建虚拟机,就需要给他提供一个虚拟的磁盘,我们就在/opt目录下创建一个10G大小的raw格式的虚拟磁盘CentOS-7-x86_64.raw命令格式:qemu-imgcreate-f磁盘格式磁盘名称磁盘大小qemu-imgcreate-f磁盘格式-o?1.创建磁盘qemu-imgcreate-fraw/opt/CentOS-7-x86_64.raw10G执行效果#ls/opt/CentOS-7-x86_64.raw2.安装虚拟机使用virt-install命令,基于我们提供的系统镜像和虚拟磁盘来创建一个虚拟机,另外在创建虚拟机之前,提前打开vnc客户端,在创建虚拟机的时候,通过vnc

  4. ruby-on-rails - 如何用不同的用户运行nginx主进程 - 2

    A/ctohttp://wiki.nginx.org/CoreModule#usermaster进程曾经以root用户运行,是否可以以不同的用户运行nginxmaster进程? 最佳答案 只需以非root身份运行init脚本(即/etc/init.d/nginxstart),就可以用不同的用户运行nginxmaster进程。如果这真的是你想要做的,你将需要确保日志和pid目录(通常是/var/log/nginx&/var/run/nginx.pid)对该用户是可写的,并且您所有的listen调用都是针对大于1024的端口(因为绑定(

  5. Ruby 缺少常量表达式优化? - 2

    我希望Ruby的解析器会进行这种微不足道的优化,但似乎并没有(谈到YARV实现,Ruby1.9.x、2.0.0):require'benchmark'deffib1a,b=0,1whileb由于这两种方法除了在第二种方法中使用预定义常量而不是常量表达式外是相同的,因此Ruby解释器似乎在每个循环中一次又一次地计算幂常数。是否有一些Material说明为什么Ruby根本不进行这种基本优化或只在某些特定情况下进行? 最佳答案 很抱歉给出了另一个答案,但我不想删除或编辑我之前的答案,因为它下面有有趣的讨论。正如JörgWMittag所说,

  6. ruby-on-rails - 优化读取数据库和写入csv文件 - 2

    我正在尝试从数据库中读取大量单元格(超过100.000个)并将它们写入VPSUbuntu服务器上的csv文件。碰巧服务器没有足够的内存。我正在考虑一次读取5000行并将它们写入文件,然后再读取5000行,等等。我应该如何重构我当前的代码以使内存不会被完全消耗?这是我的代码:defwrite_rows(emails)File.open(file_path,"w+")do|f|f该函数由sidekiqworker调用:write_rows(user.emails)感谢您的帮助! 最佳答案 这里的问题是,当您调用emails.each时,

  7. ruby-on-rails - Websocket-rails 不适用于 Nginx 和 Unicorn 的生产环境 - 2

    我有带有gemwebsocket-rails0.7的Rails3.2应用程序。在开发机上,一切正常在生产环境中,我使用Nginx/1.6作为代理服务器,Unicorn作为http服务器。Thin用于独立模式(在https://github.com/websocket-rails/websocket-rails/wiki/Standalone-Server-Mode之后)。nginx配置:location/websocket{proxy_passhttp://localhost:3001/websocket;proxy_http_version1.1;proxy_set_headerUp

  8. ruby - 没有 nginx 的 Puma - 同一 IP 上的多个 ruby​​ 应用程序 :PORT - 2

    Nginx在生产中的重要性通常基于它为慢速客户端提供服务的能力;在RESTfulAPI的设置中,它似乎是生产堆栈的一个不必要的层,尤其是Puma(不像广泛使用的unicorn可以处理nginx工作)。Pumacanallowmultipleslowclientstoconnectwithoutrequiringaworkertobeblockedontherequesttransaction.Becauseofthis,Pumahandlesslowclientsgracefully.HerokurecommendsPumaforuseinscenarioswhereyouexpect

  9. ruby-on-rails - Foreman无法启动Nginx,但我可以手动启动。为什么? - 2

    我目前正在运行Foreman在暂存(Ubuntu)上,一旦我开始工作,就会切换到使用upstart。我的Procfile.staging看起来像这样:nginx:sudoservicenginxstartunicorn:bundleexecunicorn-c./config/unicorn.rbredis:bundleexecredis-serversidekiq:bundleexecsidekiq-v-C./config/sidekiq.yml我可以使用以下方法成功启动nginx:$sudoservicenginxstart然而,当我运行$foremanstart时,当其他三个进程成

  10. ruby - open-uri 从以 iso-8859 编码的网页返回 ASCII-8BIT - 2

    我正在使用open-uri读取一个声称以iso-8859-1编码的网页。当我读取页面内容时,open-uri返回一个以ASCII-8BIT编码的字符串。open("http://www.nigella.com/recipes/view/DEVILS-FOOD-CAKE-5310"){|f|pf.content_type,f.charset,f.read.encoding}=>["text/html","iso-8859-1",#]我猜这是因为网页中的字节(或字符)\x92不是有效的iso-8859字符。http://en.wikipedia.org/wiki/ISO/IEC_8859-

随机推荐