Skip to content

Commit

Permalink
layer: Use smaller buffer for small payload
Browse files Browse the repository at this point in the history
Closes #938.

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
  • Loading branch information
smallhive committed Sep 4, 2024
1 parent 79f7414 commit e53a086
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions api/layer/multipart_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,19 @@ func (n *layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
},
}

chunk := n.buffers.Get().(*[]byte)
var (
chunk *[]byte
isReturnToPool bool
)

if p.Size > n.neoFS.MaxObjectSize() {
chunk = n.buffers.Get().(*[]byte)
isReturnToPool = true
} else {
smallChunk := make([]byte, p.Size)
chunk = &smallChunk
}

var totalBytes int
// slice part manually. Simultaneously considering the part is a single object for user.
for {
Expand Down Expand Up @@ -350,7 +362,10 @@ func (n *layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf

break
}
n.buffers.Put(chunk)

if isReturnToPool {
n.buffers.Put(chunk)
}

reqInfo := api.GetReqInfo(ctx)
n.log.Debug("upload part",
Expand Down

0 comments on commit e53a086

Please sign in to comment.