使用 MySQL 线程池对压力测试的影响

使用 MySQL 线程池对压力测试的影响,下面使用两个文件,分别测试一下。


代码:

test1.js 使用了 MySQL 线程池:

export async function test1(ctx) {
 let pool = dbUtil.getPool();
 let connection = await pool.getConnection();
 let [rows] = await connection.query('select * from tb_user limit 10');
 connection.release();
}

test2.js 未使用 MySQL 线程池:

export async function test2(ctx) {
 var rows = await dbUtil.query('select * from tb_user limit 10');
 ctx.body = rows;
}

压测命令:

ab -c 200 -n 9999 http://127.0.0.1:8001/test1


执行结果:

test1.js 的结果:

Server Software:     
Server Hostname:    127.0.0.1
Server Port:      8001

Document Path:     /test1
Document Length:    3140 bytes

Concurrency Level:   200
Time taken for tests:  37.411 seconds
Complete requests:   9999
Failed requests:    0
Total transferred:   32836716 bytes
HTML transferred:    31396860 bytes
Requests per second:  267.28 [#/sec] (mean)
Time per request:    748.287 [ms] (mean)
Time per request:    3.741 [ms] (mean, across all concurrent requests)
Transfer rate:     857.17 [Kbytes/sec] received

Connection Times (ms)
       min mean[+/-sd] median  max
Connect:    0  1  7.2   0   123
Processing:  19 743 93.1  744  1011
Waiting:    4 686 90.3  685   953
Total:     19 744 93.7  745  1084

Percentage of the requests served within a certain time (ms)
 50%  745
 66%  778
 75%  800
 80%  816
 90%  861
 95%  908
 98%  947
 99%  977
 100%  1084 (longest request)


test2.js 的结果:

Server Software:     
Server Hostname:    127.0.0.1
Server Port:      8001

Document Path:     /test2
Document Length:    3140 bytes

Concurrency Level:   200
Time taken for tests:  11.595 seconds
Complete requests:   9999
Failed requests:    0
Total transferred:   32836716 bytes
HTML transferred:    31396860 bytes
Requests per second:  862.39 [#/sec] (mean)
Time per request:    231.914 [ms] (mean)
Time per request:    1.160 [ms] (mean, across all concurrent requests)
Transfer rate:     2765.71 [Kbytes/sec] received

Connection Times (ms)
       min mean[+/-sd] median  max
Connect:    0  0  1.0   0   24
Processing:  14 228 69.6  202   461
Waiting:    3 227 69.4  201   461
Total:     14 229 69.6  202   461

Percentage of the requests served within a certain time (ms)
 50%  202
 66%  217
 75%  240
 80%  258
 90%  354
 95%  393
 98%  440
 99%  454
 100%  461 (longest request)



修改时间 2024-03-05

声明:本站所有文章和图片,如无特殊说明,均为原创发布。商业转载请联系作者获得授权,非商业转载请注明出处。
随机推荐
Wordpress 主样式表(style.css)
JavaScript 工作者线程
JavaScript screen对象
WordPress 使用 shortcode() 增加编辑器功能
MySQL 批量插入数据时如何解决重复问题
uni-app 实现暗黑模式/夜间模式/深色模式/暗黑主题(DarkMode)的几种方法
Debian11 安装笔记3:安装 MySQL 5.7
Nine 主题