我想看看 go HTTP 服务器可以在我的机器上处理多少请求,所以我尝试做一些测试,但差异太大了,我很困惑。
首先,我尝试使用 ab 进行测试并运行此命令
$ ab -n 100000 -c 1000 http://127.0.0.1/
做 1000 个并发请求。
结果如下:
Concurrency Level: 1000
Time taken for tests: 12.055 seconds
Complete requests: 100000
Failed requests: 0
Write errors: 0
Total transferred: 12800000 bytes
HTML transferred: 1100000 bytes
Requests per second: 8295.15 [#/sec] (mean)
Time per request: 120.552 [ms] (mean)
Time per request: 0.121 [ms] (mean, across all concurrent requests)
Transfer rate: 1036.89 [Kbytes/sec] received
每秒 8295 个请求,这似乎是合理的。
但是后来我尝试使用以下命令在 wrk 上运行它:
$ wrk -t1 -c1000 -d5s http://127.0.0.1:80/
我得到了这些结果:
Running 5s test @ http://127.0.0.1:80/
1 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 18.92ms 13.38ms 234.65ms 94.89%
Req/Sec 27.03k 1.43k 29.73k 63.27%
136475 requests in 5.10s, 16.66MB read
Requests/sec: 26767.50
Transfer/sec: 3.27MB
每秒 26767 个请求?我不明白为什么会有如此巨大的差异。
代码运行是最简单的 Go 服务器
package main
import (
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("Hello World"))
})
http.ListenAndServe(":80", nil)
}
我的目标是在我增加内核数时查看 go 服务器可以处理多少请求,但在我开始添加更多 CPU 能力之前,这差别太大了。有谁知道 Go 服务器在添加更多内核时如何扩展?还有为什么 ab 和 wrk 之间的巨大差异?
MMTTMM
相关分类