Use custom http transport settings in bitcoind rpc

indexv1
Martin Boehm 2018-03-02 13:54:21 +01:00
parent 1eb77fbc27
commit a04fd8642e
1 changed files with 6 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"time"
@ -180,17 +181,13 @@ 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")
transport := &http.Transport{
Dial: (&net.Dialer{KeepAlive: 600 * time.Second}).Dial,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 100, // necessary to not to deplete ports
}
// 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, Transport: &defaultTransport},
client: http.Client{Timeout: timeout, Transport: transport},
URL: url,
User: user,
Password: password,