yaogengzhu / daily-share

个人博客记录、内容在issues
30 stars 4 forks source link

使用 apache ab 做网站压力测试 (2023-04-14) #184

Open yaogengzhu opened 1 year ago

yaogengzhu commented 1 year ago

使用 apache ab 做网站压力测试

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

https://blog.kelu.org/tech/2016/02/28/apache-ab-test.html