Skip to content

net/http: Slow HTTPS #23727

Closed
Closed
@gfyrag

Description

@gfyrag

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

Not tested.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/gfyrag/work/gospace"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build524283905=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

package test

import (
	"testing"
	"net/http"
	"net/http/httptest"
	"io"
	"io/ioutil"
)

var (
	data = make([]byte, 1024*1024*100)
	h = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write(data)
	})
)

func BenchmarkHTTP(b *testing.B) {
	srv := httptest.NewServer(h)
	defer srv.Close()

	b.ResetTimer()
	for i := 0 ; i < b.N ; i++ {
		res, err := srv.Client().Get(srv.URL)
		if err != nil {
			b.Error(err)
			continue
		}
		_, err = io.Copy(ioutil.Discard, res.Body)
		if err != nil {
			b.Error(err)
		}
	}
}

func BenchmarkHTTPS(b *testing.B) {
	srv := httptest.NewTLSServer(h)
	defer srv.Close()

	b.ResetTimer()
	for i := 0 ; i < b.N ; i++ {
		res, err := srv.Client().Get(srv.URL)
		if err != nil {
			b.Error(err)
			continue
		}

		_, err = io.Copy(ioutil.Discard, res.Body)
		if err != nil {
			b.Error(err)
		}
	}
}

What did you expect to see?

A small loss on https.

What did you see instead?

A big loss on https :

BenchmarkHTTP-8    	      30	  41739281 ns/op
BenchmarkHTTPS-8   	      10	 148254359 ns/op

I know https is expected to be slower than http. But this seems to be really slow.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions