目錄
System Administration Tips, Security, Internet
Stay Updated
Other Posts
Random Posts
Post navigation
Categories
Recent Posts
首頁 後端開發 php教程 php-fpm nginx.conf

php-fpm nginx.conf

Jun 23, 2016 pm 01:43 PM

Query Admin

System Administration Tips, Security, Internet

Skip to content

Home

About Me

500 Million hits/day with Nginx + PHP-FPM + MySQL

I have recently registered to blitz.io, a very interested cloud service which allows users to stress-test a web server simulating up to 50K concurrent connections, with the possibility to specify different regions to originate requests, the HTTP method, the timeout and much more. This service can help to properly configure the web server (Nginx, Lighttpd, etc), the PHP-FPM and the MySQL to handle as more concurrent connections as possible.

I wanted to test how many concurrent connections Nginx + PHP-FPM + MySQL (Percona) could handle in one dedicated server and the results are very promising as the server handled more than 10,000 concurrent connections with an average CPU usage of 50% / 65%.

The dedicated server has the following hardware specs: Intel Xeon E3 1230v3 (4 cores 8 threads at 3.3 GHz), 32 GB DDR3 ECC, 120 GB SSD, 300 Mbit/s Bandwidth. The Nginx version used is 1.4.5-stable, the MySQL (Percona Server) version used is 5.6.15-63.0 and the PHP-FPM version used is PHP 5.5.9-1~dotdeb.1 (fpm-fcgi).

The test involved the GET request of a remote PHP web page (/test.php?item=testing-12444) used to query the MySQL database with a table of more than 100K rows and print the found row’s items in a HTML web page. So we have not tested the serving of a static file but a PHP page used to display dynamic content.

The following parameters were used in the Blitz rush test:

This is a screenshot of the Nginx status page showing active connections:

This is a screenshot of the output generated by the “top” command:

This is a screenshot of the PHP-FPM status page:

Now lets see how I have configured Nginx, PHP-FPM, MySQL and Sysctl.conf file.

/etc/nginx/nginx.conf:

user nginx;worker_processes 8;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;worker_rlimit_nofile 150000; events {  worker_connections 150000;  multi_accept on;  use epoll;} http {    include /etc/nginx/mime.types;    default_type application/octet-stream;    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                      '$status $body_bytes_sent "$http_referer" '                      '"$http_user_agent" "$http_x_forwarded_for"';     access_log /var/log/nginx/access.log  main;     sendfile on;    tcp_nopush on;    keepalive_timeout 65;    reset_timedout_connection on;    types_hash_max_size 2048;    server_tokens off;    server_names_hash_bucket_size 256;    client_max_body_size 32k;    client_body_buffer_size 32k;    client_body_in_single_buffer on;    client_body_timeout 180s;    client_header_timeout 180s;    client_header_buffer_size 32k;    large_client_header_buffers 4 32k;     include /etc/nginx/conf.d/*.conf;}
登入後複製

/etc/nginx/fastcgi_params:

...# Custom parametersfastcgi_connect_timeout 180s;fastcgi_send_timeout 600s;fastcgi_read_timeout 600s;fastcgi_intercept_errors on;fastcgi_max_temp_file_size 0;fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_index index.php;
登入後複製

/etc/php5/fpm/pool.d/www.conf:

...listen = 127.0.0.1:9000pm = staticpm.max_children = 4000pm.max_requests = 50000...
登入後複製

/etc/sysctl.conf:

fs.file-max = 150000net.core.netdev_max_backlog=32768net.core.optmem_max=20480#net.core.rmem_default=65536#net.core.rmem_max=16777216net.core.somaxconn=50000#net.core.wmem_default=65536#net.core.wmem_max=16777216net.ipv4.tcp_fin_timeout=120#net.ipv4.tcp_keepalive_intvl=30#net.ipv4.tcp_keepalive_probes=3#net.ipv4.tcp_keepalive_time=120net.ipv4.tcp_max_orphans=262144net.ipv4.tcp_max_syn_backlog=524288net.ipv4.tcp_max_tw_buckets=524288#net.ipv4.tcp_mem=1048576 1048576 2097152#net.ipv4.tcp_no_metrics_save=1net.ipv4.tcp_orphan_retries=0#net.ipv4.tcp_rmem=4096 16384 16777216#net.ipv4.tcp_synack_retries=2net.ipv4.tcp_syncookies=1#net.ipv4.tcp_syn_retries=2#net.ipv4.tcp_wmem=4096 32768 16777216
登入後複製

/etc/mysql/my.cnf:

# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208 [mysql] # CLIENT #port                           = 3306socket                         = /var/run/mysqld/mysqld.sock [mysqld] # GENERAL #user                           = mysqldefault-storage-engine         = InnoDBsocket                         = /var/run/mysqld/mysqld.sockpid-file                       = /var/run/mysqld/mysqld.pidtmpdir                         = /tmp # MyISAM #key-buffer-size                = 32Mmyisam-recover                 = FORCE,BACKUP # SAFETY #max-allowed-packet             = 16Mmax-connect-errors             = 1000000skip-name-resolvesysdate-is-now                 = 1innodb                         = FORCEinnodb-strict-mode             = 1 # DATA STORAGE #datadir                        = /var/lib/mysql # CACHES AND LIMITS #tmp-table-size                 = 32Mmax-heap-table-size            = 32Mquery-cache-type               = 0query-cache-size               = 0max-connections                = 15000thread-cache-size              = 50open-files-limit               = 65535table-definition-cache         = 1024table-open-cache               = 2048 # INNODB #innodb-flush-method            = O_DIRECTinnodb-log-files-in-group      = 2innodb-log-file-size           = 128Minnodb-flush-log-at-trx-commit = 2innodb-file-per-table          = 1innodb-buffer-pool-size        = 1456Minnodb_fast_shutdown           = 0 # LOGGING #log-error                      = /var/log/mysql/mysql-error.loglog-queries-not-using-indexes  = 0slow-query-log                 = 1slow-query-log-file            = /var/log/mysql/mysql-slow.log # REDUCE MEMORY USAGE #performance_schema             = 0
登入後複製

Finally, this is the screenshot of the Blitz rush test results:

As you can see, the test generated 344,447 successful hits in 60.00 seconds and it transferred 3.39 GB of data in and out of our PHP web page (that involved queries to our database of 100K rows). The average hit rate of 5,740.78/second translates to about 496,003,680 hits/day.

This is a screenshot of the hit rate graph:

This is a screenshot of the responses time:

Contact me if you have any questions.

                   

Stay Updated

Receive News Directly on Your Email

Become a Fan on Our Facebook Page

Subscribe to RSS Feeds

1 Billion hits/day with Nginx + PHP5-FPM + MySQL

Building a simple multilingual PHP website

New wave of spam emails that spread zBot trojan

SMTP ERROR: Password command failed: 534-5.7.14

Automatically close alert message on Twitter Bootstrap

How to use MySQL LOAD DATA LOCAL INFILE

Flush and clear cached memory in Linux server

Import large bulk of data into MySQL InnoDB

Random Posts

500 Million hits/day with Nginx + PHP-FPM + MySQL

Fix the Nginx 504 gateway timeout

Optimize Linux Sysctl.conf Parameters

Connect() to unix:/var/run/php5-fpm.sock failed

Configure FastCGI_Cache for WordPress and Nginx

Enable Nginx status page

Configure PHP-CGI without Spawn-FCGI

111 Connection refused while connecting to upstream

                   

This entry was posted in Nginx and tagged blitz io test, blitz site test, concurrent connections, nginx benchmark, nginx concurrent connections on February 23, 2014.

Post navigation

← Fix the Nginx 504 gateway timeout Free world flags icon sets →

Search for:

Categories

Apache (8)

Free Icons (1)

Htaccess (6)

Lighttpd (9)

Linux (55)

Microsoft Windows (12)

MySQL (21)

Nginx (19)

Raspberry Pi (7)

Uncategorized (18)

WordPress (21)

Recent Posts

Check if Hardware DEP is enabled on Windows OS

Check if PAE is enabled on Windows 7

XenServer VM virtual disk could not be found

Create a screenshot of a website with PHP

CSS3Pie Basic Usage

jQuery $( document ).ready(function()

Check if Bootstrap modal is already open

Delay display of Bootstrap 3 modal after click

WordPress get Page ID outside the Loop

PHP readfile() corrupted ZIP file

Fixed height and vertical scrollbar on SyntaxHighlighter Evolved

Organize uploads folder by Post ID, Slug, Author, Media Type

Use meta tags to disable caching in web browsers

Enable DEP and ASLR on a Delphi XE executable

Automate Code Signing with InnoSetup

Proudly powered by WordPress


本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1658
14
CakePHP 教程
1415
52
Laravel 教程
1309
25
PHP教程
1257
29
C# 教程
1231
24
會話如何劫持工作,如何在PHP中減輕它? 會話如何劫持工作,如何在PHP中減輕它? Apr 06, 2025 am 12:02 AM

會話劫持可以通過以下步驟實現:1.獲取會話ID,2.使用會話ID,3.保持會話活躍。在PHP中防範會話劫持的方法包括:1.使用session_regenerate_id()函數重新生成會話ID,2.通過數據庫存儲會話數據,3.確保所有會話數據通過HTTPS傳輸。

說明PHP中的不同錯誤類型(注意,警告,致命錯誤,解析錯誤)。 說明PHP中的不同錯誤類型(注意,警告,致命錯誤,解析錯誤)。 Apr 08, 2025 am 12:03 AM

PHP中有四種主要錯誤類型:1.Notice:最輕微,不會中斷程序,如訪問未定義變量;2.Warning:比Notice嚴重,不會終止程序,如包含不存在文件;3.FatalError:最嚴重,會終止程序,如調用不存在函數;4.ParseError:語法錯誤,會阻止程序執行,如忘記添加結束標籤。

PHP和Python:比較兩種流行的編程語言 PHP和Python:比較兩種流行的編程語言 Apr 14, 2025 am 12:13 AM

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

說明PHP中的安全密碼散列(例如,password_hash,password_verify)。為什麼不使用MD5或SHA1? 說明PHP中的安全密碼散列(例如,password_hash,password_verify)。為什麼不使用MD5或SHA1? Apr 17, 2025 am 12:06 AM

在PHP中,應使用password_hash和password_verify函數實現安全的密碼哈希處理,不應使用MD5或SHA1。1)password_hash生成包含鹽值的哈希,增強安全性。 2)password_verify驗證密碼,通過比較哈希值確保安全。 3)MD5和SHA1易受攻擊且缺乏鹽值,不適合現代密碼安全。

什麼是HTTP請求方法(獲取,發布,放置,刪除等),何時應該使用? 什麼是HTTP請求方法(獲取,發布,放置,刪除等),何時應該使用? Apr 09, 2025 am 12:09 AM

HTTP請求方法包括GET、POST、PUT和DELETE,分別用於獲取、提交、更新和刪除資源。 1.GET方法用於獲取資源,適用於讀取操作。 2.POST方法用於提交數據,常用於創建新資源。 3.PUT方法用於更新資源,適用於完整更新。 4.DELETE方法用於刪除資源,適用於刪除操作。

PHP:網絡開發的關鍵語言 PHP:網絡開發的關鍵語言 Apr 13, 2025 am 12:08 AM

PHP是一種廣泛應用於服務器端的腳本語言,特別適合web開發。 1.PHP可以嵌入HTML,處理HTTP請求和響應,支持多種數據庫。 2.PHP用於生成動態網頁內容,處理表單數據,訪問數據庫等,具有強大的社區支持和開源資源。 3.PHP是解釋型語言,執行過程包括詞法分析、語法分析、編譯和執行。 4.PHP可以與MySQL結合用於用戶註冊系統等高級應用。 5.調試PHP時,可使用error_reporting()和var_dump()等函數。 6.優化PHP代碼可通過緩存機制、優化數據庫查詢和使用內置函數。 7

解釋PHP 7.4中引入的箭頭功能(短閉合)。 解釋PHP 7.4中引入的箭頭功能(短閉合)。 Apr 06, 2025 am 12:01 AM

箭頭函數在PHP7.4中引入,是短閉包的簡化形式。 1)它們使用=>運算符定義,省略function和use關鍵字。 2)箭頭函數自動捕獲當前作用域變量,無需use關鍵字。 3)它們常用於回調函數和短小計算,提高代碼簡潔性和可讀性。

PHP行動:現實世界中的示例和應用程序 PHP行動:現實世界中的示例和應用程序 Apr 14, 2025 am 12:19 AM

PHP在電子商務、內容管理系統和API開發中廣泛應用。 1)電子商務:用於購物車功能和支付處理。 2)內容管理系統:用於動態內容生成和用戶管理。 3)API開發:用於RESTfulAPI開發和API安全性。通過性能優化和最佳實踐,PHP應用的效率和可維護性得以提升。

See all articles