Skip to content

Commit

Permalink
cache: Pre-allocated buffer for SDK client
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
  • Loading branch information
smallhive committed Oct 23, 2023
1 parent bf98d61 commit 79b5f37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const maxMsgSize = 4 << 20 // transport msg limit 4 MiB
// for each contract listener.
const notificationHandlerPoolSize = 10

// max GRPC message size.
const defaultBufferSize = 4 * 1024 * 1024 // 4MB

// applicationConfiguration reads and stores component-specific configuration
// values. It should not store any application helpers structs (pointers to shared
// structs).
Expand Down Expand Up @@ -545,11 +548,18 @@ func initCfg(appCfg *config.Config) *cfg {
)
fatalOnErr(err)

var buffers sync.Pool
buffers.New = func() any {
b := make([]byte, defaultBufferSize)
return &b
}

cacheOpts := cache.ClientCacheOpts{
DialTimeout: apiclientconfig.DialTimeout(appCfg),
StreamTimeout: apiclientconfig.StreamTimeout(appCfg),
AllowExternal: apiclientconfig.AllowExternal(appCfg),
ReconnectTimeout: apiclientconfig.ReconnectTimeout(appCfg),
Buffers: &buffers,
}
c.shared = shared{
key: key,
Expand Down
1 change: 1 addition & 0 deletions pkg/network/cache/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type (
ReconnectTimeout time.Duration
ResponseCallback func(client.ResponseMetaInfo) error
AllowExternal bool
Buffers *sync.Pool
}
)

Expand Down
2 changes: 2 additions & 0 deletions pkg/network/cache/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func (x *multiClient) createForAddress(addr network.Address) (clientcore.Client,
prmDial client.PrmDial
)

prmInit.SetSignMessageBuffers(x.opts.Buffers)

prmDial.SetServerURI(addr.URIAddr())

if x.opts.DialTimeout > 0 {
Expand Down

0 comments on commit 79b5f37

Please sign in to comment.