Skip to content

Commit

Permalink
innerring: 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 79b5f37 commit 34c63de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pkg/innerring/innerring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net"
"sync"
"sync/atomic"

"github.com/nspcc-dev/neo-go/pkg/core/block"
Expand Down Expand Up @@ -57,6 +58,9 @@ import (
"google.golang.org/grpc"
)

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

type (
// Server is the inner ring application structure that contains all event
// processors, shared variables and event handlers.
Expand Down Expand Up @@ -593,13 +597,20 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<-
cfg.GetDuration("indexer.cache_timeout"),
)

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

clientCache := newClientCache(&clientCacheParams{
Log: log,
Key: &server.key.PrivateKey,
SGTimeout: cfg.GetDuration("audit.timeout.get"),
HeadTimeout: cfg.GetDuration("audit.timeout.head"),
RangeTimeout: cfg.GetDuration("audit.timeout.rangehash"),
AllowExternal: cfg.GetBool("audit.allow_external"),
Buffers: &buffers,
})

server.registerNoErrCloser(clientCache.cache.CloseAll)
Expand Down
5 changes: 4 additions & 1 deletion pkg/innerring/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/ecdsa"
"fmt"
"sync"
"time"

clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
Expand Down Expand Up @@ -40,13 +41,15 @@ type (
AllowExternal bool

SGTimeout, HeadTimeout, RangeTimeout time.Duration

Buffers *sync.Pool
}
)

func newClientCache(p *clientCacheParams) *ClientCache {
return &ClientCache{
log: p.Log,
cache: cache.NewSDKClientCache(cache.ClientCacheOpts{AllowExternal: p.AllowExternal}),
cache: cache.NewSDKClientCache(cache.ClientCacheOpts{AllowExternal: p.AllowExternal, Buffers: p.Buffers}),
key: p.Key,
sgTimeout: p.SGTimeout,
headTimeout: p.HeadTimeout,
Expand Down

0 comments on commit 34c63de

Please sign in to comment.