使用socket方式串連Nginx最佳化php-fpm效能

來源:互聯網
上載者:User

標籤:pre   php   tmpfs   磁碟   dia   nbsp   並發   ipc   fastcgi   

Nginx串連fastcgi的方式有2種:TCP和unix domain socket什麼是Unix domain socket?—— 維基百科Unix domain socket 或者 IPC socket是一種終端,可以使同一台作業系統上的兩個或多個進程進行資料通訊。與管道相比,Unix domain sockets 既可以使用位元組流和資料隊列,而管道通訊則只能通過位元組流。Unix domain sockets的介面和Internet socket很像,但它不使用網路底層協議來通訊。Unix domain socket 的功能是POSIX作業系統裡的一種組件。Unix domain sockets 使用系統檔案的地址來作為自己的身份。它可以被系統進程引用。所以兩個進程可以同時開啟一個Unix domain sockets來進行通訊。不過這種通訊方式是發生在系統核心裡而不會在網路裡傳播。TCP和unix domain socket方式對比TCP是使用TCP連接埠串連127.0.0.1:9000Socket是使用unix domain socket串連通訊端/dev/shm/php-cgi.sock(很多教程使用路徑/tmp,而路徑/dev/shm是個tmpfs,速度比磁碟快得多)測試機是個1核的centos5.4,2使用者並發時系統資源消耗50%左右,10使用者資源就跑得很滿了。          2users    10usersnginx/1.2.9 + PHP 5.2.5    tcp    1060    1294nginx/1.2.9 + PHP 5.2.5    socket    997    1487nginx/1.2.9 + PHP 5.3.10    tcp    906    1082nginx/1.2.9 + PHP 5.3.10    socket    880    1247結論是在伺服器壓力不大的情況下,tcp和socket差別不大,但在壓力比較滿的時候,用通訊端方式,效果確實比較好。下面是php 5.3以上版本將TCP改成socket方式的配置方法:修改php-fpm.conf(/usr/local/php/etc/php-fpm.conf) ;listen = 127.0.0.1:9000listen = /dev/shm/php-cgi.sock修改nginx設定檔server段的配置,將http的方式改為socket方式location ~ [^/]\.php(/|$) {    #fastcgi_pass 127.0.0.1:9000;    fastcgi_pass unix:/dev/shm/php-cgi.sock;    fastcgi_index index.php;    include fastcgi.conf;}重啟php-fpm與nginxservice nginx restartservice php-fpm restartls -al /dev/shm可以看到php-cgi.sock檔案unix通訊端類型參考:http://zh.wikipedia.org/wiki/Unix_domain_socket

 

使用socket方式串連Nginx最佳化php-fpm效能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.