Bob*_*man 22 http go osx-yosemite
package main
import (
"io"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello world!\n")
}
func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":8000", nil)
}
Run Code Online (Sandbox Code Playgroud)
我有几个非常基本的HTTP服务器,所有这些都表现出这个问题.
$ ab -c 1000 -n 10000 http://127.0.0.1:8000/
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
apr_socket_recv: Connection refused (61)
Total of 5112 requests completed
Run Code Online (Sandbox Code Playgroud)
由于并发值较小,事情仍然会发生.对我来说,问题似乎通常出现在5k-6k左右:
$ ab -c 10 -n 10000 http://127.0.0.1:8000/
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
apr_socket_recv: Operation timed out (60)
Total of 6277 requests completed
Run Code Online (Sandbox Code Playgroud)
事实上,你可以完全放弃并发,问题仍然(有时)发生:
$ ab -c 1 -n 10000 http://127.0.0.1:8000/
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
apr_socket_recv: Operation timed out (60)
Total of 6278 requests completed
Run Code Online (Sandbox Code Playgroud)
我不禁想知道我是否在某处遇到某种操作系统限制?我怎么说?我该如何缓解?
Jim*_*imB 40
简而言之,您的端口已耗尽.
osx上的默认临时端口范围是49152-65535,它只有16,383个端口.由于每个ab请求都是http/1.0(在第一个示例中没有keepalive),因此每个新请求都需要另一个端口.
当使用每个端口时,它会被放入队列,等待tcp"最大段寿命",在osx上配置为15秒.因此,如果您在15秒内使用超过16,383个端口,则在进一步连接时,您实际上会被操作系统限制.根据哪个进程首先用完了端口,您将从服务器获取连接错误,或者挂起ab.
您可以通过使用http/1.1功能强大的负载生成器wrk或使用keepalive(-k)选项来缓解此问题ab,以便根据工具的并发设置重用连接.
现在,您正在进行基准测试的服务器代码做得很少,负载生成器的负担与服务器本身一样多,本地操作系统和网络堆栈可能会做出很好的贡献.如果要对http服务器进行基准测试,最好从不在同一台机器上运行的多个客户端执行一些有意义的工作.
| 归档时间: |
|
| 查看次数: |
3151 次 |
| 最近记录: |