Skip to content

crypto/x509: Go opens many more CA cert files than Python #32172

Description

@yyq2013

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

$ go version
go version go1.12.5 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build185645434=/tmp/go-build -gno-record-gcc-switches

What did you do?

Just get html content from a site, but it is slower a lot than patyhon client, I want to know what need to optimize or bug for the language itself

package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/http"
	"time"
)

type AddHeaderTransport struct {
	http.RoundTripper
}

func (adt *AddHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	req.Header.Add("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1")
	req.Header.Add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
	req.Header.Add("cache-control", "max-age=0")
	req.Header.Add("accept-language", "en,zh-CN;q=0.9,zh;q=0.8*")
	req.Header.Add("referer", "https://www.bing.com/")
	return adt.RoundTripper.RoundTrip(req)
}
func main() {
	tr := AddHeaderTransport{http.DefaultTransport}
	http.DefaultClient = &http.Client{Transport: &tr}
	start := time.Now()
	res, err := http.Get("https://www.bing.com/")
	if err != nil {
		log.Println(err)
		return
	}
	fmt.Println(time.Since(start))
	defer res.Body.Close()
	io.CopyN(ioutil.Discard, res.Body, 1024)
}

213.2271ms

import urllib3
import time
from urllib3 import Retry


headers = {
    'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
    'referer': 'https://www.bing.com/',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en,zh-CN;q=0.9,zh;q=0.8',
    'cache-control': 'max-age=0'
}

retries = Retry(connect=10, read=5, redirect=5, backoff_factor=1.2)
urllib3.disable_warnings()
c = urllib3.HTTPSConnectionPool('www.bing.com', port=443, cert_reqs='CERT_NONE',
                                assert_hostname=False, retries=retries)
start_time = time.time()
r = c.request('GET', "/", headers=headers)
elapsed_time = time.time() - start_time
print(elapsed_time)
r.encoding = 'utf-8'
content_type = r.headers['content-type']
index = content_type.find('=')
encode = 'utf-8'
if index > -1:
    encode = content_type[index + 1:]
print(r.data.decode(encode))

0.14572596549987793s

What did you expect to see?

The time elapsed should about the same between golang and python client

What did you see instead?

The time elapsed for golang http client is more than python client, nearly double.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performance

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions