From 846f3e8f59dea8a0d4793e65b9f985fda12da7d8 Mon Sep 17 00:00:00 2001 From: wd256 Date: Fri, 20 Apr 2018 09:15:14 +1000 Subject: [PATCH] Disable "chunked" uploading by the GCS client for objects smaller than the chunk size. (#5835) By disabling chunked uploading when the object size is less than the chunk size, memory is not allocated unnecessarily. --- cmd/gateway/gcs/gateway-gcs.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/gateway/gcs/gateway-gcs.go b/cmd/gateway/gcs/gateway-gcs.go index c16743a13..e64f99dd9 100644 --- a/cmd/gateway/gcs/gateway-gcs.go +++ b/cmd/gateway/gcs/gateway-gcs.go @@ -839,6 +839,11 @@ func (l *gcsGateway) PutObject(ctx context.Context, bucket string, key string, d object := l.client.Bucket(bucket).Object(key) w := object.NewWriter(l.ctx) + // Disable "chunked" uploading in GCS client if the size of the data to be uploaded is below + // the current chunk-size of the writer. This avoids an unnecessary memory allocation. + if data.Size() < int64(w.ChunkSize) { + w.ChunkSize = 0 + } applyMetadataToGCSAttrs(metadata, &w.ObjectAttrs) if _, err := io.Copy(w, data); err != nil {