压力测试 Autocannnon

web开发完成需要进行压力测试,以检测页面性能。我们使用autocannon插件进行压力测试,比Wrk更加方便。
  • 安装
  npm i autocannon -D  # or npm i autocannon -g  
  • 全局使用
  autocannon -c 100 -d 10 -p 5 http://127.0.0.1:3000/
  • 参数说明
    -c 并发数 默认10 [connections]
    -p 每个连接进程请求数量 默认1 [pipelining]
    -d 执行时间 单位秒 [duration]
    -m 请求类型 默认GET [method]
    -b 请求体body [body]

  • 结果

  
┌─────────┬────────┬─────────┬─────────┬─────────┬────────────┬────────────┬────────────┐
│ Stat    │ 2.5%   │ 50%     │ 97.5%   │ 99%     │ Avg        │ Stdev      │ Max        │
├─────────┼────────┼─────────┼─────────┼─────────┼────────────┼────────────┼────────────┤
│ Latency │ 556 ms │ 2575 ms │ 4099 ms │ 4099 ms │ 2225.81 ms │ 1441.45 ms │ 4099.95 ms │
└─────────┴────────┴─────────┴─────────┴─────────┴────────────┴────────────┴────────────┘
┌───────────┬─────┬──────┬────────┬────────┬────────┬────────┬────────┐
│ Stat      │ 1%  │ 2.5% │ 50%    │ 97.5%  │ Avg    │ Stdev  │ Min    │
├───────────┼─────┼──────┼────────┼────────┼────────┼────────┼────────┤
│ Req/Sec   │ 0   │ 0    │ 1      │ 2      │ 1      │ 0.64   │ 1      │
├───────────┼─────┼──────┼────────┼────────┼────────┼────────┼────────┤
│ Bytes/Sec │ 0 B │ 0 B  │ 254 kB │ 509 kB │ 254 kB │ 161 kB │ 254 kB │
└───────────┴─────┴──────┴────────┴────────┴────────┴────────┴────────┘

Req/Bytes counts sampled once per second.

5 requests in 5.1s, 1.27 MB read
  • 开发
'use strict'

const autocannon = require('autocannon')
async test () {
  const result = await autocannon({
    url: 'http://127.0.0.1:3000',
    connections: 100, // -c 并发数 默认10
    pipelining: 5, //-p 每个连接进程请求数量 默认1
    duration: 10 // -d 执行时间 单位秒
  })
  console.log(result)
  return result
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容