Use custom http transport settings in bitcoind rpc
parent
1eb77fbc27
commit
a04fd8642e
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue