From 11ad8c2c49b7175ba5c3187b6dc97a5aece32d57 Mon Sep 17 00:00:00 2001 From: Matee ullah Malik <46045452+mateeullahmalik@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:10:47 +0300 Subject: [PATCH] [PSL-1201] keep cnode connections alive for same host (#884) * [PSL-1201] keep cnode connections alive for same host * remove request close instructions --------- Co-authored-by: Matee Ullah --- pastel/jsonrpc/jsonrpc.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pastel/jsonrpc/jsonrpc.go b/pastel/jsonrpc/jsonrpc.go index 232a58252..b98b52d2f 100644 --- a/pastel/jsonrpc/jsonrpc.go +++ b/pastel/jsonrpc/jsonrpc.go @@ -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), } @@ -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()) @@ -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())