What version of Go are you using (go version)?
go version go1.9.2 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/will/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/26/bqp0svv9187cxr93vbhdh86m0000gn/T/go-build149896180=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
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?
I write a simple code to test the go TLS performance. The connection speed decreases significantly when I enable TLS.
Server with TLS enabled:
package main
import (
"crypto/tls"
"log"
)
func main() {
cert, err := tls.LoadX509KeyPair("server.pem", "server.key")
if err != nil {
log.Fatal("error while loading server.pem and server.key")
}
config := &tls.Config{
Certificates: []tls.Certificate{cert},
MinVersion: tls.VersionTLS10,
}
_ = config
l, _ := tls.Listen("tcp", ":8080", config)
conn ,_:= l.Accept()
buff := make([]byte, 4096)
for {
_, er := conn.Write(buff)
if er != nil{
break
}
}
conn.Close()
l.Close()
}
Server without TLS:
package main
import (
"net"
)
func main() {
//cert, err := tls.LoadX509KeyPair("server.pem", "server.key")
//if err != nil {
// log.Fatal("error while loading server.pem and server.key")
//}
//config := &tls.Config{
// Certificates: []tls.Certificate{cert},
// MinVersion: tls.VersionTLS10,
//}
//_ = config
l, _ := net.Listen("tcp", ":8080")
conn ,_:= l.Accept()
buff := make([]byte, 4096)
for {
_, er := conn.Write(buff)
if er != nil{
break
}
}
conn.Close()
l.Close()
}
What did you expect to see?
I use curl to test the network speed:
curl -k https://127.0.0.1:8080 -o test.bin
gives the speed:
curl -k https://127.0.0.1:8080 -o test.bin
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 377M 0 377M 0 0 35.6M 0 --:--:-- 0:00:10 --:--:-- 35.7M
and
curl http://127.0.0.1:8080 -o test.bin
gives the speed:
curl http://127.0.0.1:8080 -o test.bin
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2757M 0 2757M 0 0 507M 0 --:--:-- 0:00:05 --:--:-- 511M
The speed is only around 35.7MB/s when enabling TLS while it is more than 500MB/s with a plain TCP connection.
P.S. I generated the server.pem and server.key by following these command: https://github.com/denji/golang-tls
What version of Go are you using (
go version)?go version go1.9.2 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/will/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/26/bqp0svv9187cxr93vbhdh86m0000gn/T/go-build149896180=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
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?
I write a simple code to test the go TLS performance. The connection speed decreases significantly when I enable TLS.
Server with TLS enabled:
Server without TLS:
What did you expect to see?
I use curl to test the network speed:
curl -k https://127.0.0.1:8080 -o test.bingives the speed:
and
curl http://127.0.0.1:8080 -o test.bingives the speed:
The speed is only around 35.7MB/s when enabling TLS while it is more than 500MB/s with a plain TCP connection.
P.S. I generated the
server.pemandserver.keyby following these command: https://github.com/denji/golang-tls