MixPHP 与 Phalcon 数据库并发性能测试

来源:互联网 发布:矩阵特征值 编辑:程序博客网 时间:2024/05/17 01:36

前面做了很多基础测试,但是框架大部分时间都是在操作数据库,所以数据库操作性能很重要,下面对比测试一下 MixPHP 与 Phalcon 的数据库并发性能。

分别测试短连接与长连接。

硬件

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

环境

[ Phalcon ]

Apache worker模式,mpm配置如下:

<IfModule worker.c>ServerLimit  50ThreadLimit  200StartServers  5MaxClients  5000MinSpareThreads  25MaxSpareThreads  500ThreadsPerChild  100MaxRequestsPerChild 0</IfModule>

[ MixPHP ]

MixHttpd 配置如下:

8个线程处理连接,8个进程处理PHP代码。

reactor_num = 8worker_num = 8

源代码

请求数据表全部数据(6行),并输出json。

[ Phalcon ]

public function actionIndex(){    $this->view->disable();    $data = $this->modelsManager->executeQuery("SELECT * FROM Test")->toArray();    header("Content-Type:application/json;charset=utf-8");    echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);}

[ MixPHP ]

function actionIndex(){    return \Mix::app()->rdb->createCommand("SELECT * FROM `test`")->queryAll();}

开始测试

  1. 测试 Phalcon (短连接),QPS: 554.36
C:\Server\apache24vc11\bin>ab -n 10000 -c 300 http://www.d.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.d.com (be patient)Completed 1000 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software:        Apache/2.2.32Server Hostname:        www.d.comServer Port:            80Document Path:          /Document Length:        438 bytesConcurrency Level:      300Time taken for tests:   18.039 secondsComplete requests:      10000Failed requests:        109   (Connect: 0, Receive: 0, Length: 109, Exceptions: 0)Total transferred:      6278798 bytesHTML transferred:       4338907 bytesRequests per second:    554.36 [#/sec] (mean)Time per request:       541.160 [ms] (mean)Time per request:       1.804 [ms] (mean, across all concurrent requests)Transfer rate:          339.92 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        0    1   3.8      1     271Processing:    11  532 408.9    441    3166Waiting:       11  504 406.8    411    3165Total:         12  533 408.9    442    3166Percentage of the requests served within a certain time (ms)  50%    442  66%    572  75%    670  80%    754  90%   1016  95%   1405  98%   1777  99%   1925 100%   3166 (longest request)
  1. 测试 MixPHP (短连接),QPS: 915.64
C:\Server\apache24vc11\bin>ab -n 10000 -c 300 http://www.a.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.a.com (be patient)Completed 1000 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software:        swoole-http-serverServer Hostname:        www.a.comServer Port:            9501Document Path:          /Document Length:        426 bytesConcurrency Level:      300Time taken for tests:   10.921 secondsComplete requests:      10000Failed requests:        0Total transferred:      5890000 bytesHTML transferred:       4260000 bytesRequests per second:    915.64 [#/sec] (mean)Time per request:       327.638 [ms] (mean)Time per request:       1.092 [ms] (mean, across all concurrent requests)Transfer rate:          526.67 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        0    0   0.4      1      19Processing:    93  319 112.9    306     738Waiting:       51  318 114.2    305     737Total:         93  320 112.9    306     739ERROR: The median and mean for the initial connection time are more than twice the standard       deviation apart. These results are NOT reliable.Percentage of the requests served within a certain time (ms)  50%    306  66%    353  75%    392  80%    414  90%    481  95%    528  98%    587  99%    618 100%    739 (longest request)
  1. 测试 Phalcon (长连接),QPS: 无

由于 Apache worker 模式下,开启 Phalcon 的 Pdo 长连接后,高并发下旧连接不回收,导致 mysql 连接全部被占用,无法响应新的请求,测试无法完成。

  1. 测试 MixPHP (长连接),QPS: 1946.22
C:\Server\apache24vc11\bin>ab -n 10000 -c 300 http://www.a.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.a.com (be patient)Completed 1000 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software:        swoole-http-serverServer Hostname:        www.a.comServer Port:            9501Document Path:          /Document Length:        426 bytesConcurrency Level:      300Time taken for tests:   5.138 secondsComplete requests:      10000Failed requests:        0Total transferred:      5890000 bytesHTML transferred:       4260000 bytesRequests per second:    1946.22 [#/sec] (mean)Time per request:       154.145 [ms] (mean)Time per request:       0.514 [ms] (mean, across all concurrent requests)Transfer rate:          1119.46 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        0    0   0.3      1       5Processing:    10  151  16.4    152     337Waiting:        6   97  38.9    102     321Total:         10  151  16.4    152     337ERROR: The median and mean for the initial connection time are more than twice the standard       deviation apart. These results are NOT reliable.Percentage of the requests served within a certain time (ms)  50%    152  66%    154  75%    154  80%    155  90%    157  95%    159  98%    175  99%    195 100%    337 (longest request)

结论

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

ITEM DESC Phalcon (Apache) (短连接) 554.36 QPS MixPHP (Swoole) (短连接) 915.64 QPS ITEM DESC Phalcon (Apache) (长连接) 无法完成 MixPHP (Swoole) (长连接) 1946.22 QPS
原创粉丝点击