Golang HTTPS无法处理大数据包

I'm stress testing a simple HTTPS Golang web server which looks like this:

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")
}

So it's just a very basic server, which returns a 1MB file on the url: /bigpacket. The test I'm running does 1000 requests per second (so about 1GB per second is send over the connection) for 30 seconds.

When testing this, only about 30% of the requests are successful! However, when I switch to HTTP (by using log.Fatalln(srv.ListenAndServe())) all requests are successful.. (100%) Could these results be correct? Has HTTPS that much overhead over HTTP?

These are the errors I get:

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-
doutuan6158
doutuan6158 不是没有巨型帧,只有普通的数据包发送了一个大文件(1MB)。好的,谢谢,我只是不太希望TLS开销这么大!
接近 4 年之前 回复
dongshengheng1013
dongshengheng1013 您没有在此处包含有关如何配置“大数据包”的任何信息(您是说巨型帧吗?),但实际上发出的请求数量超出服务器的处理能力。如果1000req/s使HTTP连接饱和,则根本无法使用HTTPS发出相同数量的请求。
接近 4 年之前 回复
donglian6625
donglian6625 每个新会话都需要完整的SSL协商。仅通过SSL证书就可以提供约1-10MB/s的额外网络带宽(因此,仅文件传输的0.1%到1%)。它还增加了一些往返和一些公共密钥加密,这很可能是最沉重的打击。
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐