mirror of
https://github.com/minio/minio.git
synced 2025-04-07 13:15:39 -04:00
Avoid allocating larger buffer if the incoming body is small (#6035)
This commit is contained in:
parent
cb9ee1584a
commit
05f96f3956
@ -375,8 +375,17 @@ func (xl xlObjects) PutObjectPart(ctx context.Context, bucket, object, uploadID
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch buffer for I/O, returns from the pool if not allocates a new one and returns.
|
// Fetch buffer for I/O, returns from the pool if not allocates a new one and returns.
|
||||||
buffer := xl.bp.Get()
|
var buffer []byte
|
||||||
defer xl.bp.Put(buffer)
|
switch size := data.Size(); {
|
||||||
|
case size == 0:
|
||||||
|
buffer = make([]byte, 1) // Allocate atleast a byte to reach EOF
|
||||||
|
case size < blockSizeV1:
|
||||||
|
// No need to allocate fully blockSizeV1 buffer if the incoming data is smaller.
|
||||||
|
buffer = make([]byte, size, 2*size)
|
||||||
|
default:
|
||||||
|
buffer = xl.bp.Get()
|
||||||
|
defer xl.bp.Put(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
file, err := storage.CreateFile(ctx, data, minioMetaTmpBucket, tmpPartPath, buffer, DefaultBitrotAlgorithm, writeQuorum)
|
file, err := storage.CreateFile(ctx, data, minioMetaTmpBucket, tmpPartPath, buffer, DefaultBitrotAlgorithm, writeQuorum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -611,8 +611,17 @@ func (xl xlObjects) putObject(ctx context.Context, bucket string, object string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch buffer for I/O, returns from the pool if not allocates a new one and returns.
|
// Fetch buffer for I/O, returns from the pool if not allocates a new one and returns.
|
||||||
buffer := xl.bp.Get()
|
var buffer []byte
|
||||||
defer xl.bp.Put(buffer)
|
switch size := data.Size(); {
|
||||||
|
case size == 0:
|
||||||
|
buffer = make([]byte, 1) // Allocate atleast a byte to reach EOF
|
||||||
|
case size < blockSizeV1:
|
||||||
|
// No need to allocate fully blockSizeV1 buffer if the incoming data is smaller.
|
||||||
|
buffer = make([]byte, size, 2*size)
|
||||||
|
default:
|
||||||
|
buffer = xl.bp.Get()
|
||||||
|
defer xl.bp.Put(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
// Read data and split into parts - similar to multipart mechanism
|
// Read data and split into parts - similar to multipart mechanism
|
||||||
for partIdx := 1; ; partIdx++ {
|
for partIdx := 1; ; partIdx++ {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user