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

本文通过对比测试MixPHP与Phalcon框架在数据库操作上的性能表现,尤其是在并发环境下的短连接与长连接场景中,揭示了不同框架在数据库交互效率上的差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前面做了很多基础测试,但是框架大部分时间都是在操作数据库,所以数据库操作性能很重要,下面对比测试一下 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();
}

开始测试

  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 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)
  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 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)
  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 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

ITEMDESC
Phalcon (Apache) (短连接)554.36 QPS
MixPHP (Swoole) (短连接)915.64 QPS
ITEMDESC
Phalcon (Apache) (长连接)无法完成
MixPHP (Swoole) (长连接)1946.22 QPS
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值