[#2139] object/put: Use `sync.Pool` for temporary payloads

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
fyrchik/simplify-services
Evgenii Stratonikov 2022-12-06 13:25:19 +03:00 committed by Anton Nikiforov
parent 9e0decd12d
commit 04b5ec759b
4 changed files with 27 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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])
}

View File

@ -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 {