diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index 7190026f..e1584131 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -49,6 +49,7 @@ func initMorphComponents(c *cfg) { client.WithDialTimeout(dialTimeout), client.WithLogger(c.log), client.WithExtraEndpoints(addresses[1:]), + client.WithMaxConnectionPerHost(morphconfig.MaxConnPerHost(c.appCfg)), ) if err == nil { handler(cli) diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 18374dbc..3ad89d55 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -32,12 +32,15 @@ type cfg struct { extraEndpoints []string + maxConnPerHost int + singleCli *client.Client // neo-go client for single client mode } const ( - defaultDialTimeout = 5 * time.Second - defaultWaitInterval = 500 * time.Millisecond + defaultDialTimeout = 5 * time.Second + defaultWaitInterval = 500 * time.Millisecond + defaultMaxConnPerHost = 10 ) func defaultConfig() *cfg { @@ -49,6 +52,7 @@ func defaultConfig() *cfg { signer: &transaction.Signer{ Scopes: transaction.Global, }, + maxConnPerHost: defaultMaxConnPerHost, } } @@ -166,6 +170,15 @@ func WithExtraEndpoints(endpoints []string) Option { } } +// WithMaxConnectionPerHost returns a client constructor +// option that specifies Neo client's maximum opened +// connection per one host. +func WithMaxConnectionPerHost(m int) Option { + return func(c *cfg) { + c.maxConnPerHost = m + } +} + // WithSingleClient returns a client constructor option // that specifies single neo-go client and forces Client // to use it and only it for requests. diff --git a/pkg/morph/client/multi.go b/pkg/morph/client/multi.go index 56c787a2..56b08633 100644 --- a/pkg/morph/client/multi.go +++ b/pkg/morph/client/multi.go @@ -25,7 +25,8 @@ type multiClient struct { // note: must be wrapped into mutex lock. func (x *multiClient) createForAddress(addr string) (*Client, error) { cli, err := client.New(x.cfg.ctx, addr, client.Options{ - DialTimeout: x.cfg.dialTimeout, + DialTimeout: x.cfg.dialTimeout, + MaxConnsPerHost: x.cfg.maxConnPerHost, }) if err != nil { return nil, err