MixPHP 与原生 Swoole 并发压力测试

MixPHP 是基于 Swoole 的高性能框架,封装后比原生 Swoole 对比损失了多少性能呢?今天我们来测试一下。

环境

虚拟机: 4 核,1G
使用 ab 工具压测,命令:ab -n 10000 -c 300 URL

原生 Swoole

代码如下,输出一个 Hello World。

on('request', function ($request, $response) {
    $response->end("Hello World");
});
$http->start();

MixPHP

默认控制器代码如下,输出一个 Hello World。

public function actionIndex()
{
    return 'Hello World';
}

开始测试

首先测试原生 Swoole,RPS: 1413.75

C:\Server\apache24vc11\bin>ab -n 10000 -c 300 http://www.v.com:9501/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.v.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        swoole-http-server
Server Hostname:        www.v.com
Server Port:            9501

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      300
Time taken for tests:   7.073 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1600000 bytes
HTML transferred:       120000 bytes
Requests per second:    1413.75 [#/sec] (mean)
Time per request:       212.202 [ms] (mean)
Time per request:       0.707 [ms] (mean, across all concurrent requests)
Transfer rate:          220.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.3      1      12
Processing:    10  208  21.7    211     237
Waiting:        3  120  58.5    121     228
Total:         10  209  21.7    211     238

Percentage of the requests served within a certain time (ms)
  50%    211
  66%    214
  75%    216
  80%    218
  90%    221
  95%    227
  98%    230
  99%    232
 100%    238 (longest request)

然后测试 MixPHP,RPS: 1239.25

C:\Server\apache24vc11\bin>ab -n 10000 -c 300 http://www.v.com:9501/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.v.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        swoole-http-server
Server Hostname:        www.v.com
Server Port:            9501

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      300
Time taken for tests:   8.069 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1600000 bytes
HTML transferred:       120000 bytes
Requests per second:    1239.25 [#/sec] (mean)
Time per request:       242.083 [ms] (mean)
Time per request:       0.807 [ms] (mean, across all concurrent requests)
Transfer rate:          193.63 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.4      1       6
Processing:    11  238  29.2    238     277
Waiting:        5  146  64.7    151     271
Total:         12  239  29.3    239     278

Percentage of the requests served within a certain time (ms)
  50%    239
  66%    254
  75%    259
  80%    262
  90%    267
  95%    271
  98%    273
  99%    275
 100%    278 (longest request)

结论

一个六千多行代码的框架,比几行代码的原生 Swoole 只损失了 12% 的并发性能,这已经非常不错了。

你也来测试一下吧,https://github.com/mixstart/mixphp

ITEM DESC
原生 Swoole 1413.75 RPS
MixPHP 1239.25 RPS
损失 174.5 RPS
损失比率 12%

你可能感兴趣的:(MixPHP 与原生 Swoole 并发压力测试)