Skip to content

Commit 9214f26

Browse files
authored
fix: configure MaxIdleConnsPerHost (was 2 by default) (#19)
1 parent 451ab22 commit 9214f26

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ func main() {
4444
ctx, cancel := context.WithCancel(context.Background())
4545

4646
// Init components
47-
remoteClient := relay.NewRemoteClient(logger, &relay.RemoteClientCfg{Address: remoteAddress, AuthToken: authToken, Timeout: timeout})
47+
remoteClient := relay.NewRemoteClient(logger, &relay.RemoteClientCfg{
48+
Address: remoteAddress,
49+
AuthToken: authToken,
50+
Timeout: timeout,
51+
MaxIdleConnsPerHost: numWorkers,
52+
})
4853
// TODO(eh-am): a find a better default for num of workers
4954
queue := relay.NewRemoteQueue(logger, &relay.RemoteQueueCfg{NumWorkers: numWorkers}, remoteClient)
5055
ctrl := relay.NewController(logger, queue)

relay/client.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ var (
1818

1919
type RemoteClientCfg struct {
2020
// Address refers to the remote address the request will be made to
21-
Address string
22-
AuthToken string
23-
Timeout time.Duration
21+
Address string
22+
AuthToken string
23+
Timeout time.Duration
24+
MaxIdleConnsPerHost int
2425
}
2526

2627
type RemoteClient struct {
@@ -34,12 +35,17 @@ func NewRemoteClient(log *logrus.Entry, config *RemoteClientCfg) *RemoteClient {
3435
if timeout == 0 {
3536
timeout = time.Second * 10
3637
}
37-
38+
if config.MaxIdleConnsPerHost == 0 {
39+
config.MaxIdleConnsPerHost = 5
40+
}
3841
return &RemoteClient{
3942
log: log,
4043
config: config,
4144
client: &http.Client{
4245
Timeout: timeout,
46+
Transport: &http.Transport{
47+
MaxIdleConnsPerHost: config.MaxIdleConnsPerHost,
48+
},
4349
},
4450
}
4551
}

0 commit comments

Comments
 (0)