EasySwoole中采用MySQL连接池并发测试

测试机

  MacBook Pro (Retina, 15-inch, Mid 2014)
  2.2 GHz Intel Core i7
  16 GB 1600 MHz DDR3

环境( brew 默认安装配置)

  PHP: 7.2.20 (cli) (built: Jul 5 2019 12:51:26) ( NTS )
  MySQL: Ver 14.14 Distrib 5.7.26, for osx10.14 (x86_64) using EditLine wrapper

不采用连接池代码

$conf = new \EasySwoole\Mysqli\Config(\EasySwoole\EasySwoole\Config::getInstance()->getConf('MYSQL'));

$db = new \EasySwoole\Mysqli\Mysqli($conf);

$data = $db->get('user');

return $this->writeJson (200,$data,'ok');
采用连接池代码
$db = MysqlPool::defer();

$data = (new \App\Model\UserModel($db))->getall ();

return $this->writeJson (200,$data,'ok');

输出结果

{
    "ret": 200,
    "data": [
        {
            "id": "1",
            "avatar": "/Static/upload/5d09ceac4de6312262La2-0.jpg",
            "nickname": "php工程师",
            "username": "test2",
            "password": "$2y$10$ueMA2hy8x.Tan3nxZlpCmugUcViGCaV/cAeA4V5YX.yU.1kCtAtzq",
            "sign": "123",
            "status": "offline"
        },
        {
            "id": "2",
            "avatar": "/Static/upload/5d09c7da7bc97tx20218.jpg",
            "nickname": "前端工程师",
            "username": "test1",
            "password": "$2y$10$m.4h0u0L56G2Oje6ZnNMyulR.9DMvPT4VkXo2RcTHr8NEqVa.cq8C",
            "sign": "我是前端工程师",
            "status": "offline"
        },
        {
            "id": "3",
            "avatar": "/Static/upload/5d09c6a5b6def15337177846531748ac16fb.jpg",
            "nickname": "jin",
            "username": "jin",
            "password": "$2y$10$cS3rfhqaHeOfVfkAFd1MnuzslrWhihLP/awA07hQPOfUqixV0yp1q",
            "sign": "我是jin",
            "status": "online"
        }
    ],
    "msg": ""
}

测试对比结果

各对以上代码进行并发1000,持续30秒测试

测试结果如下

—- 采用连接池 不采用连接池
请求总数 16864 7724
响应成功数 16864 7695
每秒响应请求数 562 257.4
最大响应时间 380.6ms 430.5ms
最小响应时间 0.154ms 0.097ms
平均响应时间 2.2ms 2.4ms

以上对比看不出效果?继续看下面

  CPU:X5650 2.67GHz 24核心(开启超线程后)
  内存:32 GB 1067 MHz

并发5000,持续30秒测试

—- 采用连接池 php-fpm mysqli
请求总数 426190 394410
响应成功数 426190 372011
每秒响应请求数 14206.3 13146.9
最大响应时间 29.566ms 3024.86ms
最小响应时间 0.035ms 0.038ms
平均响应时间 0.23ms 32.28ms

0 条评论