團隊技術負責人宣稱 Swoole 使 PHP 具備多線程、異步非阻塞能力,性能可媲美 Node.js。為驗證該結論,筆者在本地環境進行了基準壓測。
兩側均實現極簡 HTTP 服務,僅返回 "Hello World",無業務邏輯、無數據庫、無 I/O,純測框架吞吐能力。
Server Software:
Server Hostname: 127.0.0.1
Server Port: 8000
Document Path: /
Document Length: 0 bytes
Concurrency Level: 100
Time taken for tests: 1.411 seconds
Complete requests: 5000
Failed requests: 0
Requests per second: 3543.00 [#/sec] (mean)
Time per request: 28.225 [ms] (mean)
Time per request: 0.282 [ms] (mean, across all concurrent requests)
Transfer rate: 38.29 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 1.2 3 7
Processing: 17 25 16.7 23 143
Waiting: 1 9 12.9 7 136
Total: 20 28 16.6 26 143
Percentage of requests served within a certain time (ms)
50% 26
66% 27
75% 27
80% 27
90% 28
95% 29
98% 141
99% 142
100% 143 (longest request)
Server Software:
Server Hostname: 127.0.0.1
Server Port: 1337
Document Path: /
Document Length: 12 bytes
Concurrency Level: 100
Time taken for tests: 1.215 seconds
Complete requests: 5000
Failed requests: 0
Requests per second: 4116.49 [#/sec] (mean)
Time per request: 24.293 [ms] (mean)
Time per request: 0.243 [ms] (mean, across all concurrent requests)
Transfer rate: 454.26 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.6 0 5
Processing: 2 24 21.0 21 175
Waiting: 2 24 20.8 21 174
Total: 6 24 20.9 21 175
Percentage of requests served within a certain time (ms)
50% 21
66% 22
75% 23
80% 24
90% 26
95% 32
98% 159
99% 170
100% 175 (longest request)
| 指標 | Swoole | Node.js | 差異 |
|---|---|---|---|
| 總耗時 | 1.411 s | 1.215 s | Node.js 快 14% |
| QPS (吞吐率) | 3,543 | 4,116 | Node.js 高 16% |
| 平均延遲 | 28.2 ms | 24.3 ms | Node.js 低 14% |
| P99 延遲 | 142 ms | 170 ms | Swoole 更穩定 |
| 最大延遲 | 143 ms | 175 ms | Swoole 更穩定 |
--debug 模式運行(產生大量日誌輸出),且未啟用 OpCache、未調優進程數、未使用 HTTP 服務器優化選項。生產級調優後性能仍有提升空間。後續將在公司測試環境(Linux、生產級配置)進行複測,並補充內存佔用、CPU 佔用、長連接穩定性等維度數據。