Increate MaxIdleConnsPerHost for BitcoinRPC http client

indexv1
Martin Boehm 2018-02-27 20:39:27 +01:00
parent 9b383c62e3
commit e075f28913
1 changed files with 10 additions and 1 deletions

View File

@ -177,8 +177,17 @@ type BitcoinRPC struct {
// NewBitcoinRPC returns new BitcoinRPC instance.
func NewBitcoinRPC(url string, user string, password string, timeout time.Duration) *BitcoinRPC {
// set higher MaxIdleConnsPerHost to not to deplete pool of sockets
defaultTransportPointer, ok := http.DefaultTransport.(*http.Transport)
if !ok {
glog.Fatal("http.DefaultTransport is not an *http.Transport")
}
// dereference it to get a copy of the struct that the pointer points to
defaultTransport := *defaultTransportPointer
defaultTransport.MaxIdleConns = 100
defaultTransport.MaxIdleConnsPerHost = 100
return &BitcoinRPC{
client: http.Client{Timeout: timeout},
client: http.Client{Timeout: timeout, Transport: &defaultTransport},
URL: url,
User: user,
Password: password,