我正在对一个简单的HTTPS Golang Web服务器进行压力测试,如下所示:
func main() {
srv := &http.Server{
Addr: ":" + port,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
mux := http.NewServeMux()
mux.HandleFunc("/bigpacket", bigpacket)
srv.Handler = mux
log.Fatalln(srv.ListenAndServeTLS(certPath+"cert.pem", certPath+"key.pem"))
}
// Sends 1MB file
func bigpacket(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./bigpacket")
}
所以它只是一个非常基本的服务器,它在url:/ bigpacket上返回一个1MB的文件。我运行的测试每秒执行1000次请求(因此通过连接发送大约每秒1GB)30秒。
测试时,只有约30%的请求成功!但是,当我切换到HTTP(使用log.Fatalln(srv.ListenAndServe())
)时,所有请求都成功..(100%)
这些结果可能是正确的吗? HTTPS上的HTTPS开销是多少吗?
这些是我得到的错误:
read tcp 10.132.0.4:36248->10.132.0.3:8080: read: connection reset by peer
unexpected EOF
Get https://10.132.0.3:8080/bigpacket: unexpected EOF
read tcp 10.132.0.4:34573->10.132.0.3:8080: read: connection reset by peer
Get https://10.132.0.3:8080/bigpacket: read tcp 10.132.0.4:34573->10.132.0.3:8080: read: connection reset by peer
Get https://10.132.0.3:8080/bigpacket: write tcp 10.132.0.4:38955->10.132.0.3:8080: write: broken pipe
Get https://10.132.0.3:8080/bigpacket: http2: no cached connection was available
Get https://10.132.0.3:8080/bigpacket: read tcp 10.132.0.4:59658->10.132.0.3:8080: read: connection reset by peer
read tcp 10.132.0.4:59658->10.132.0.3:8080: read: connection reset by peer
Get https://10.132.0.3:8080/bigpacket: write tcp 10.132.0.4:57612->10.132.0.3:8080: write: connection reset by peer
read tcp 10.132.0.4:48971->10.132.0.3:8080: read: connection reset by peer
Get https://10.132.0.3:8080/bigpacket: write tcp 10.132.0.4:42138->10.132.0.3:8080: write: connection reset by peer
Get https://10.132.0.3:8080/bigpacket: write tcp 10.132.0.4:33734->10.132.0.3:8080: write: broken pipe
read tcp 10.132.0.4:55605->10.132.0.3:8080: read: connection reset by peer
read tcp 10.132.0.4:34132->10.132.0.3:8080: read: connection reset by peer
read tcp 10.132.0.4:59141->10.132.0.3:8080: read: connection reset by peer
Get https://10.132.0.3:8080/bigpacket: read tcp 10.132.0.4:59141-