前面做了很多基础测试,但是框架大部分时间都是在操作数据库,所以数据库操作性能很重要,下面对比测试一下 MixPHP 与 Phalcon 的数据库并发性能。
分别测试短连接与长连接。
硬件
虚拟机:4核 1G
使用 ab 工具压测,命令:ab -n 10000 -c 300 URL
环境
[ Phalcon ]
Apache worker模式,mpm配置如下:
<IfModule worker.c>
ServerLimit 50
ThreadLimit 200
StartServers 5
MaxClients 5000
MinSpareThreads 25
MaxSpareThreads 500
ThreadsPerChild 100
MaxRequestsPerChild 0
</IfModule>
[ MixPHP ]
MixHttpd 配置如下:
8个线程处理连接,8个进程处理PHP代码。
reactor_num = 8
worker_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();
}
开始测试
- 测试 Phalcon (短连接),RPS: 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 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.d.com
Server Port: 80
Document Path: /
Document Length: 438 bytes
Concurrency Level: 300
Time taken for tests: 18.039 seconds
Complete requests: 10000
Failed requests: 109
(Connect: 0, Receive: 0, Length: 109, Exceptions: 0)
Total transferred: 6278798 bytes
HTML transferred: 4338907 bytes
Requests 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] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 3.8 1 271
Processing: 11 532 408.9 441 3166
Waiting: 11 504 406.8 411 3165
Total: 12 533 408.9 442 3166
Percentage 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)
- 测试 MixPHP (短连接),RPS: 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 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.a.com
Server Port: 9501
Document Path: /
Document Length: 426 bytes
Concurrency Level: 300
Time taken for tests: 10.921 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 5890000 bytes
HTML transferred: 4260000 bytes
Requests 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] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 1 19
Processing: 93 319 112.9 306 738
Waiting: 51 318 114.2 305 737
Total: 93 320 112.9 306 739
ERROR: 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)
- 测试 Phalcon (长连接),RPS: 无
由于 Apache worker 模式下,开启 Phalcon 的 Pdo 长连接后,高并发下旧连接不回收,导致 mysql 连接全部被占用,无法响应新的请求,测试无法完成。
- 测试 MixPHP (长连接),RPS: 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 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.a.com
Server Port: 9501
Document Path: /
Document Length: 426 bytes
Concurrency Level: 300
Time taken for tests: 5.138 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 5890000 bytes
HTML transferred: 4260000 bytes
Requests 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] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 1 5
Processing: 10 151 16.4 152 337
Waiting: 6 97 38.9 102 321
Total: 10 151 16.4 152 337
ERROR: 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 RPS |
MixPHP (Swoole) (短连接) | 915.64 RPS |
ITEM | DESC |
---|---|
Phalcon (Apache) (长连接) | 无法完成 |
MixPHP (Swoole) (长连接) | 1946.22 RPS |
网友评论