Skip to content

Commit

Permalink
[PSL-1201] keep cnode connections alive for same host (#884)
Browse files Browse the repository at this point in the history
* [PSL-1201] keep cnode connections alive for same host

* remove request close instructions

---------

Co-authored-by: Matee Ullah <mateeullah@Matees-MacBook-Pro.local>
  • Loading branch information
mateeullahmalik and Matee Ullah authored Jun 26, 2024
1 parent 4b79083 commit 11ad8c2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pastel/jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ func NewClientWithOpts(endpoint string, opts *RPCClientOpts) RPCClient {
endpoint: endpoint,
httpClient: &http.Client{
Timeout: httpTimeout,
Transport: &http.Transport{
DisableKeepAlives: false, // explicitly enable keep-alives - although its the default behavior
MaxIdleConnsPerHost: 75, // increase the number of idle connections per host as we are connecting to the same host
IdleConnTimeout: 60 * time.Second,
},
},
customHeaders: make(map[string]string),
}
Expand Down Expand Up @@ -451,7 +456,7 @@ func (client *rpcClient) doCall(cctx context.Context, RPCRequest *RPCRequest) (*
if err != nil {
return nil, fmt.Errorf("rpc call %v() on %v: %v", RPCRequest.Method, client.endpoint, err.Error())
}
httpRequest.Close = true

httpResponse, err := client.httpClient.Do(httpRequest)
if err != nil {
return nil, fmt.Errorf("rpc call %v() on %v: %v", RPCRequest.Method, httpRequest.URL.String(), err.Error())
Expand Down Expand Up @@ -496,7 +501,7 @@ func (client *rpcClient) doBatchCall(rpcRequest []*RPCRequest) ([]*RPCResponse,
if err != nil {
return nil, fmt.Errorf("rpc batch call on %v: %v", client.endpoint, err.Error())
}
httpRequest.Close = true

httpResponse, err := client.httpClient.Do(httpRequest)
if err != nil {
return nil, fmt.Errorf("rpc batch call on %v: %v", httpRequest.URL.String(), err.Error())
Expand Down

0 comments on commit 11ad8c2

Please sign in to comment.