duanchai0028
2016-10-10 09:08 阅读 132

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-
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

相关推荐