[#1031] morph: Add maxConnPerHost
option
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
63e035bd8a
commit
c49e53ba9d
3 changed files with 18 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
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.
|
||||
|
|
|
@ -26,6 +26,7 @@ type multiClient struct {
|
|||
func (x *multiClient) createForAddress(addr string) (*Client, error) {
|
||||
cli, err := client.New(x.cfg.ctx, addr, client.Options{
|
||||
DialTimeout: x.cfg.dialTimeout,
|
||||
MaxConnsPerHost: x.cfg.maxConnPerHost,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in a new issue