Swoole benchmark

TechEmpower third party web framework benchmarks result

TechEmpower Framework Benchmarks

Benchmark and get QPS on your own machine

The following code launches ab process and sending 100K request to Swoole HTTP server with 128 connections.

You can get an idea about the QPS supported by the Swoole HTTP server and your machine.

#!/usr/bin/env php
<?php
$wait = new Swoole\Atomic(0);
$pid = pcntl_fork();
if ($pid === 0) {
    $http = new Swoole\Http\Server('127.0.0.1', 9501, SWOOLE_BASE);
    $http->set(['log_file' => '/dev/null', 'log_level' => SWOOLE_LOG_INFO, 'worker_num' => swoole_cpu_num() * 2]);
    $http->on('workerStart', function () use ($wait) { $wait->set(1); });
    $http->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) {
        $response->end('<h1>Hello Swoole!</h1>');
    });
    $http->start();
} else {
    $wait->wait();
    System('ab -c 128 -n 100000 -k http://127.0.0.1:9501/ 2>&1');
    Swoole\Process::kill($pid);
}
Swoole\Event::wait();

Another benchmark code

<?php
$http = new swoole_http_server("127.0.0.1", 1337, SWOOLE_BASE);

$http->set([
    'worker_num' => 4,
]);

$data = [
  'code' => 'ok',
  'error' => false,
  'payload' => 'Hello World'
];

$http->on('request', function ($request, swoole_http_response $response)  use($data)  {
    $response->header('Content-Type', 'application/json');   
    $response->end(json_encode($data));
});

$http->start();

Test case #1

Testing environment
  • CentOS 7 64bit
  • 8GB Memory
  • 24 Cores
  • Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz
  • PHP 7.1
  • Swoole v1.9.22
Benchmark result
Running 10s test @ http://127.0.0.1:1337/
4 threads and 400 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 3.56ms 2.95ms 218.94ms 98.04%
Req/Sec 27.80k 4.73k 37.95k 87.00%
1108229 requests in 10.03s, 223.00MB read
Requests/sec: 110515.99
Transfer/sec: 22.24MB

Test case #2

Testing environment
  • Ubuntu 16.04 LTS
  • Intel® Core™ i5-4590 CPU @ 3.30GHz × 4
  • 16G Memory
  • PHP 7.1
  • Swoole v1.9.22
Testing result
wrk -t4 -c400 -d10s http://127.0.0.1:1337/
Running 10s test @ http://127.0.0.1:1337/
  4 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.46ms    1.42ms  27.96ms   85.66%
    Req/Sec    75.29k    36.43k  183.55k    72.75%
  3007806 requests in 10.06s, 605.25MB read
Requests/sec: 299103.32
Transfer/sec:     60.19MB