利用TCMalloc最佳化Nginx效能

來源:互聯網
上載者:User

標籤:nginx.conf   libunwind   

技術說明:

TCMalloc 全稱Thread-Cachig Malloc,是Google開發的開源工具Google-preftools中的一個成員。與標準的glibc庫的Malloc相比,TCMalloc庫在記憶體配置效率和速度上要高很多,在很大程度上提高了伺服器在高並發情況下的效能,從而降低了系統的負載。

一.安裝libunwind:

1.安裝libunwind:

http://download.savannah.gnu.org/releases/libunwind/

下載libunwind-0.99.tar.gz

2.tar –zxvf libunwind-0.99.tar.gz

3.cd libunwind-0.99

4.CFLAGS=-fPIC ./configure

5.make CFLAGS=-fPIC

6.make CFLAGS=-fPIC install

7.echo "/usr/local/lib" >/etc/ld.so.conf.d/usr_local_lib.conf

8./sbin/ldconfig

二.安裝google-preftools:

1.:

http://download.chinaunix.net/download.php?id=32582&ResourceID=12865

下載google-perftools-1.9.tar.gz

2. chmod 700 google-perftools-1.9.tar.gz

3. tar -zxvf google-perftools-1.9.tar.gz

4. cd google-perftools-1.9

5. ./configure

6. make && make install

7. echo "/usr/local/lib" >/etc/ld.so.conf.d/usr_local_lib.conf

8./sbin/ldconfig

三.重新編譯Nginx:

1. cd nginx-1.5.8

2../configure  --with-google_perftools_module --user=www --group=www --prefix=/usr/local/nginx  --with-http_stub_status_module

3. make && make install

四.為google-perftools添加線程目錄:

mkdir –p /tmp/tcmalloc

chmod 0777 /tmp/tcmalloc

五.修改Nginx主設定檔:

vim /usr/local/nginx/conf/nginx.conf:

#pid logs/nginx.pid;

google_perftools_profiles /tmp/tcmalloc;

六.驗證google-perftools正常載入,命令查看方式:

lsof –n |grep tcmalloc

[[email protected] conf]# lsof -n |greptcmalloc

nginx    15017       www   10w     REG              253,0         0    801420 /tmp/tcmalloc.15017

nginx    15018       www   12w     REG              253,0         0    801417 /tmp/tcmalloc.15018

nginx    15019       www   14w     REG              253,0         0    801415 /tmp/tcmalloc.15019

nginx    15020       www   16w     REG              253,0         0    784898 /tmp/tcmalloc.15020

nginx    15021       www   18w     REG              253,0         0    801274 /tmp/tcmalloc.15021

nginx    15022       www   20w     REG              253,0         0    801414 /tmp/tcmalloc.15022

nginx    15023       www   22w     REG              253,0         0    801418 /tmp/tcmalloc.15023

nginx    15024       www   24w     REG              253,0         0    801419 /tmp/tcmalloc.15024

在Nginx的主設定檔Nginx.conf中設定worker_processes的值為8,所以開啟了8個Nginx線程,每個線程有一行記錄。每個線程檔案後面的數字值就是啟動的Nginx的pid值。

  利用TCMalloc最佳化Nginx可以提高伺服器在高並發下的效能,降低系統負載,使伺服器穩定、高效運行!


本文出自 “林夕” 部落格,請務必保留此出處http://lutaoxu.blog.51cto.com/4224602/1551374

利用TCMalloc最佳化Nginx效能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.