diff --git a/main.go b/main.go index e0c9f95..479c57b 100644 --- a/main.go +++ b/main.go @@ -44,7 +44,12 @@ func main() { ctx, cancel := context.WithCancel(context.Background()) // Init components - remoteClient := relay.NewRemoteClient(logger, &relay.RemoteClientCfg{Address: remoteAddress, AuthToken: authToken, Timeout: timeout}) + remoteClient := relay.NewRemoteClient(logger, &relay.RemoteClientCfg{ + Address: remoteAddress, + AuthToken: authToken, + Timeout: timeout, + MaxIdleConnsPerHost: numWorkers, + }) // TODO(eh-am): a find a better default for num of workers queue := relay.NewRemoteQueue(logger, &relay.RemoteQueueCfg{NumWorkers: numWorkers}, remoteClient) ctrl := relay.NewController(logger, queue) diff --git a/relay/client.go b/relay/client.go index 48a2e3d..c883dbc 100644 --- a/relay/client.go +++ b/relay/client.go @@ -18,9 +18,10 @@ var ( type RemoteClientCfg struct { // Address refers to the remote address the request will be made to - Address string - AuthToken string - Timeout time.Duration + Address string + AuthToken string + Timeout time.Duration + MaxIdleConnsPerHost int } type RemoteClient struct { @@ -34,12 +35,17 @@ func NewRemoteClient(log *logrus.Entry, config *RemoteClientCfg) *RemoteClient { if timeout == 0 { timeout = time.Second * 10 } - + if config.MaxIdleConnsPerHost == 0 { + config.MaxIdleConnsPerHost = 5 + } return &RemoteClient{ log: log, config: config, client: &http.Client{ Timeout: timeout, + Transport: &http.Transport{ + MaxIdleConnsPerHost: config.MaxIdleConnsPerHost, + }, }, } }