【发布时间】:2015-07-02 01:03:23
【问题描述】:
我正在尝试查看 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 有这么大的区别?
【问题讨论】:
标签: linux go benchmarking