麦壳社区

压力测试 Autocannnon

2020-05-22  本文已影响0人  张Boy
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/
  
┌─────────┬────────┬─────────┬─────────┬─────────┬────────────┬────────────┬────────────┐
│ 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
}
上一篇 下一篇

猜你喜欢

热点阅读