MixPHP 与 Phalcon 并发压力测试

说起 PHP 高性能框架,一定会有人说 Yaf/Phalcon,这两个C扩展类型的框架基本是高性能框架的代表了,而 MixPHP 是基于 Swoole 扩展的高性能 PHP 框架,今天我来测试下 MixPHP 能否可以挑战C扩展框架 Phalcon。

环境

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

Phalcon

Apache worker模式,mpm配置如下:


ServerLimit  50
ThreadLimit  200
StartServers  5
MaxClients  5000
MinSpareThreads  25
MaxSpareThreads  500
ThreadsPerChild  100
MaxRequestsPerChild 0

用最简单的方式搭建 Phalcon 框架,没有加入任何其他依赖,只注册了一下路由与命名空间。

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

public function indexAction()
{
    echo 'Hello World';
}

MixPHP

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

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

开始测试

首先测试 Phalcon,QPS: 968.31

C:\Server\apache24vc11\bin>ab -n 10000 -c 300 http://www.p.com/
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.p.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:        Apache/2.2.32
Server Hostname:        www.p.com
Server Port:            80

Document Path:          /
Document Length:        11 bytes

Concurrency Level:      300
Time taken for tests:   10.327 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      2040000 bytes
HTML transferred:       110000 bytes
Requests per second:    968.31 [#/sec] (mean)
Time per request:       309.819 [ms] (mean)
Time per request:       1.033 [ms] (mean, across all concurrent requests)
Transfer rate:          192.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      22
Processing:    11  304  30.5    308     370
Waiting:        5  177  84.4    180     354
Total:         12  304  30.5    309     371

Percentage of the requests served within a certain time (ms)
  50%    309
  66%    312
  75%    314
  80%    315
  90%    317
  95%    320
  98%    323
  99%    326
 100%    371 (longest request)

然后测试 MixPHP,QPS: 1263.34

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.916 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1600000 bytes
HTML transferred:       120000 bytes
Requests per second:    1263.34 [#/sec] (mean)
Time per request:       237.465 [ms] (mean)
Time per request:       0.792 [ms] (mean, across all concurrent requests)
Transfer rate:          197.40 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.4      1       4
Processing:    12  234  26.3    239     261
Waiting:        6  139  65.5    140     259
Total:         12  235  26.4    240     262

Percentage of the requests served within a certain time (ms)
  50%    240
  66%    243
  75%    246
  80%    247
  90%    252
  95%    254
  98%    258
  99%    259
 100%    262 (longest request)

结论

Phalcon 与 MixPHP 做 Hello World 输出就已经差异这么多 QPS,项目开发中各种数据库操作,各种分层封装,QPS 上的差异还会进一步拉开距离。

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

ITEM DESC
Phalcon 968.31 QPS
MixPHP 1263.34 QPS

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