wrk – http benchmark 簡易的HTTP 性能測試 nginx unit vs php-fpm

wrk 是用C語言寫的http benchmark 工具,是一種簡易的HTTP 性能測試。

1. 安裝 wrt 
作者將原始檔放在git上,所以要安裝它最直接的方法
就是去git抓下來make就可以了!以下是指令
yum groupinstall 'Development Tools'
yum -y install openssl-devel git
git clone https://github.com/wg/wrk.git wrk
cd wrk
make
# copy wrk 到 PATH 可執行的目錄中,我的習慣釋放到/usr/local/bin
cp wrk /usr/local/bin

2. 使用方法
Usage: wrk <options> <url>
Options:
-c, --connections <N> Connections to keep open
-d, --duration <T> Duration of test
-t, --threads <N> Number of threads to use
-s, --script <S> Load Lua script file
-H, --header <H> Add header to request
--latency Print latency statistics
--timeout <T> Socket/request timeout
-v, --version Print version details
Numeric arguments may include a SI unit (1k, 1M, 1G)
Time arguments may include a time unit (2s, 2m, 2h)
例如:
wrk -t12 -c400 -d30s http://127.0.0.1:8300/

# -t12 用 12 個線程 # -c400 模擬 400 個併發連接 # -d30s 持續 30 秒
輸出 (output)
Running 30s test @ http://127.0.0.1:8300/
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 244.87ms 16.11ms 400.26ms 93.68%
Req/Sec 137.86 93.22 333.00 59.80%
48060 requests in 30.06s, 3.55GB read
Requests/sec: 1598.63
Transfer/sec: 121.00MB

3. nginx unit vs php-fpm 簡易評測

以下是 Nginx Unit 與 php-fpm 兩個的測試,都是執行同一個php程式 phpinfo()
環境 proxmox 中同一個 lxc ,cpu(i3-6100) x1核心 2G-ram, SSD(16G), Centos 8
這個是 Nginx Unit的測試數據
# wrk -t12 -c1000 -d30s --latency http://127.0.0.1:8300/
Running 30s test @ http://127.0.0.1:8300/
12 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 401.01ms 164.14ms 824.90ms 71.34%
Req/Sec 199.53 236.08 1.75k 86.26%
Latency Distribution
50% 377.40ms
75% 491.87ms
90% 673.38ms
99% 693.67ms
45966 requests in 30.10s, 3.40GB read
Socket errors: connect 0, read 4184, write 10502, timeout 461
Requests/sec: 1527.31
Transfer/sec: 115.60MB
這個是 php-fpm 的測試數據
# wrk -t12 -c1000 -d30s --latency http://127.0.0.1/info.php
Running 30s test @ http://127.0.0.1/info.php
12 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 123.82ms 126.50ms 1.98s 88.39%
Req/Sec 590.16 206.62 2.76k 73.59%
Latency Distribution
50% 69.94ms
75% 139.62ms
90% 294.62ms
99% 544.58ms
206197 requests in 30.06s, 2.20GB read
Socket errors: connect 0, read 7, write 0, timeout 1080
Non-2xx or 3xx responses: 186757
Requests/sec: 6859.62
Transfer/sec: 74.98MB

看來若是使用php做為後端語言,以效能來比php-fpm還是比nginx-unit好...
後記: php-fpm 在測試過程中記憶體使用量增加約70K,unit 測試過程中記憶體使用量增加約20K,以記憶體使用量來比,unit 勝!!!

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *