From 04b5ec759b0ddaea6886cb4696628a75d897096d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 6 Dec 2022 13:25:19 +0300 Subject: [PATCH] [#2139] object/put: Use `sync.Pool` for temporary payloads Signed-off-by: Evgenii Stratonikov --- CHANGELOG.md | 1 + pkg/services/object/put/distributed.go | 5 +++++ pkg/services/object/put/pool.go | 20 ++++++++++++++++++++ pkg/services/object/put/streamer.go | 1 + 4 files changed, 27 insertions(+) create mode 100644 pkg/services/object/put/pool.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 053f914a9..d6df3cbeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Changelog for NeoFS Node - Policer cache size is now 1024 (#2158) - Tree service now synchronizes with container nodes in a random order (#2127) - Pilorama no longer tries to apply already applied operations (#2161) +- Use `sync.Pool` in Object.PUT service (#2139) ### Fixed - Open FSTree in sync mode by default (#1992) diff --git a/pkg/services/object/put/distributed.go b/pkg/services/object/put/distributed.go index afc38289b..4c3220acf 100644 --- a/pkg/services/object/put/distributed.go +++ b/pkg/services/object/put/distributed.go @@ -128,6 +128,11 @@ func (t *distributedTarget) Write(p []byte) (n int, err error) { } func (t *distributedTarget) Close() (*transformer.AccessIdentifiers, error) { + defer func() { + putPayload(t.payload) + t.payload = nil + }() + t.obj.SetPayload(t.payload) var err error diff --git a/pkg/services/object/put/pool.go b/pkg/services/object/put/pool.go new file mode 100644 index 000000000..842d76745 --- /dev/null +++ b/pkg/services/object/put/pool.go @@ -0,0 +1,20 @@ +package putsvc + +import ( + "sync" +) + +const defaultAllocSize = 1024 + +var putBytesPool = &sync.Pool{ + New: func() interface{} { return make([]byte, 0, defaultAllocSize) }, +} + +func getPayload() []byte { + return putBytesPool.Get().([]byte) +} + +func putPayload(p []byte) { + //nolint:staticcheck + putBytesPool.Put(p[:0]) +} diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index 5b6de7a5b..e5942d099 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -215,6 +215,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget { extraBroadcastEnabled: withBroadcast, }, + payload: getPayload(), remotePool: p.remotePool, localPool: p.localPool, nodeTargetInitializer: func(node nodeDesc) preparedObjectTarget {