const http = require('http')
let h = ''
for (let i = 0; i < 1024 * 10; i++) {
h += 'a'
}
http.createServer((req, res) => {
res.writeHead(200)
res.end(h)
}).listen(8001)
ab -n10000 -c100 http://127.0.0.1:8001/
Concurrency Level: 100
Time taken for tests: 1.207 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 103150000 bytes
HTML transferred: 102400000 bytes
Requests per second: 8284.30 [#/sec] (mean)
Time per request: 12.071 [ms] (mean)
Time per request: 0.121 [ms] (mean, across all concurrent requests)
Transfer rate: 83449.73 [Kbytes/sec] received
改用buffer传输
const http = require('http')
let h = ''
for (let i = 0; i < 1024 * 10; i++) {
h += 'a'
}
h = new Buffer(h)
http.createServer((req, res) => {
res.writeHead(200)
res.end(h)
}).listen(8001)
Concurrency Level: 100
Time taken for tests: 1.545 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 103150000 bytes
HTML transferred: 102400000 bytes
Requests per second: 6473.93 [#/sec] (mean)
Time per request: 15.447 [ms] (mean)
Time per request: 0.154 [ms] (mean, across all concurrent requests)
Transfer rate: 65213.50 [Kbytes/sec] received
使用 apache ab 做网站压力测试
改用buffer传输
https://blog.kelu.org/tech/2016/02/28/apache-ab-test.html