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

前面做了很多基础测试,但是框架大部分时间都是在操作数据库,所以数据库操作性能很重要,下面对比测试一下 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 (短连接),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)
  1. 测试 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)
  1. 测试 Phalcon (长连接),RPS: 无

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

  1. 测试 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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容

  • Apache针对不同的操作系统提供了多个不同的MPM模块,例如:mpm_beos、mpm_event、mpm_ne...
    红鱼绿鱼与驴阅读 3,857评论 0 1
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,100评论 18 139
  • 需要原文的可以留下邮箱我给你发,这里的文章少了很多图,懒得网上粘啦 1数据库基础 1.1数据库定义 1)数据库(D...
    极简纯粹_阅读 7,311评论 0 46
  • 第一章 Nginx简介 Nginx是什么 没有听过Nginx?那么一定听过它的“同行”Apache吧!Ngi...
    JokerW阅读 32,462评论 24 1,003
  • 今天班会最后晓雨老师总结很有力量。我们学习易效能的目的是为了过更好的生活,如何过一天就是如何过一生。越自律的人越自...
    脱变中的我阅读 238评论 0 0