Why PHP7+Swoole Beats Nginx and Go in High‑Concurrency Benchmarks
A benchmark using ApacheBench compares Nginx static serving, a Golang HTTP server, and a PHP7+Swoole server under 100‑concurrent connections for one million requests, showing PHP7+Swoole achieving roughly 75 % higher QPS than both Nginx and Golang, along with detailed environment, code, and resource usage data.
Performance Comparison
Using ApacheBench, we benchmarked Nginx static pages, a Golang HTTP server, and a PHP7+Swoole HTTP server under 100 concurrent connections for 1,000,000 requests. PHP7+Swoole achieved about 75% higher QPS than Nginx and Golang.
Software QPS
Nginx 164,489.92
Golang 166,838.68
PHP7+Swoole 287,104.12
Nginx‑1.9.9 245,058.70Note: Nginx 1.9.9 was tuned with access_log disabled and open_file_cache enabled, reaching 245,058.70 QPS.
Test Environment
Hardware
CPU: Intel® Core™ i5-4590 @ 3.30 GHz × 4
Memory: 16 GB
Disk: 128 GB SSD
OS: Ubuntu 14.04 (Linux 3.16.0‑55‑generic)
Load Tool
ab -c 100 -n 1000000 -k http://127.0.0.1:8080/Software Details
Nginx
Version
nginx/1.4.6 (Ubuntu)VHOST Configuration
server {
listen 80 default_server;
root /data/webroot;
index index.html;
}Test Page
<h1>Hello World!</h1>Process Count
Nginx runs 4 worker processes.
Golang
Version
go version go1.5.2 linux/amd64Test Code
package main
import (
"log"
"net/http"
"runtime"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU() - 1)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Last-Modified", "Thu, 18 Jun 2015 10:24:27 GMT")
w.Header().Add("Accept-Ranges", "bytes")
w.Header().Add("E-Tag", "55829c5b-17")
w.Header().Add("Server", "golang-http-server")
w.Write([]byte("<h1>
Hello world!
</h1>
"))
})
log.Printf("Go http Server listen on :8080")
log.Fatal(http.ListenAndServe(":8080", nil)
}PHP7+Swoole
PHP7 has OpCache enabled.
PHP Version
PHP 7.0.0 (cli) (built: Dec 10 2015 14:36:26) ( NTS )
Zend Engine v3.0.0
with Zend OPcache v7.0.6-devSwoole Version
swoole-1.7.22-alphaPHP Extensions
[PHP Modules]
Core
ctype
curl
...
swoole
Zend OPcache
...
[Zend Modules]
Zend OPcacheTest Code
<?php
$http = new swoole_http_server("127.0.0.1", 9501, SWOOLE_BASE);
$http->set(['worker_num' => 4]);
$http->on('request', function ($request, swoole_http_response $response) {
$response->header('Last-Modified', 'Thu, 18 Jun 2015 10:24:27 GMT');
$response->header('E-Tag', '55829c5b-17');
$response->header('Accept-Ranges', 'bytes');
$response->end("<h1>
Hello Swoole.
</h1>");
});
$http->start();Test Results
Nginx
Requests per second: 164,489.92
Time per request: 0.608 ms (mean)
...Golang
Requests per second: 166,838.68
Time per request: 0.599 ms (mean)
...PHP7+Swoole
Requests per second: 287,104.12
Time per request: 0.348 ms (mean)
...Resource Consumption
Nginx
sar
16:31:05 all 0.00 0.00 0.00 0.00 0.00 100.00
16:31:06 all 11.65 0.00 29.11 0.00 0.00 59.24
... (truncated)vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 3812080 559240 9321032 0 0 4 27 2 25 2 3 95 0 0
... (truncated)Golang
sar
16:42:02 all 2.72 0.00 0.99 0.00 0.00 96.29
... (truncated)vmstat
... (truncated)PHP7+Swoole
sar
16:44:49 CPU %user %nice %system %iowait %steal %idle
16:44:50 all 1.97 0.00 0.99 0.00 0.00 97.04
... (truncated)vmstat
... (truncated)Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
