From 9f02f51b879146fa630f36aa7394f67178df3987 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Tue, 12 Jul 2022 07:42:04 -0700 Subject: [PATCH] Add 4K minimum compressed size (#15273) There is no point in compressing very small files. Typically the effective size on disk will be the same due to disk blocks. So don't waste resources on extremely small files. We don't check on multipart. 1) because we don't know and 2) this is very likely a big object anyway. --- cmd/object-handlers.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index f4089255a..2dc4fbc3a 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -83,6 +83,9 @@ const ( encryptBufferThreshold = 1 << 20 // add an input buffer of this size. encryptBufferSize = 1 << 20 + + // minCompressibleSize is the minimum size at which we enable compression. + minCompressibleSize = 4096 ) // setHeadGetRespHeaders - set any requested parameters as response headers. @@ -1156,6 +1159,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re // Pass the decompressed stream to such calls. isDstCompressed := objectAPI.IsCompressionSupported() && isCompressible(r.Header, dstObject) && + length > minCompressibleSize && !isRemoteCopyRequired(ctx, srcBucket, dstBucket, objectAPI) && !cpSrcDstSame && !objectEncryption if isDstCompressed { compressMetadata = make(map[string]string, 2) @@ -1720,7 +1724,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req actualSize := size var idxCb func() []byte - if objectAPI.IsCompressionSupported() && isCompressible(r.Header, object) && size > 0 { + if objectAPI.IsCompressionSupported() && isCompressible(r.Header, object) && size > minCompressibleSize { // Storing the compression metadata. metadata[ReservedMetadataPrefix+"compression"] = compressionAlgorithmV2 metadata[ReservedMetadataPrefix+"actual-size"] = strconv.FormatInt(size, 10) @@ -2073,7 +2077,7 @@ func (api objectAPIHandlers) PutObjectExtractHandler(w http.ResponseWriter, r *h actualSize := size var idxCb func() []byte - if objectAPI.IsCompressionSupported() && isCompressible(r.Header, object) && size > 0 { + if objectAPI.IsCompressionSupported() && isCompressible(r.Header, object) && size > minCompressibleSize { // Storing the compression metadata. metadata[ReservedMetadataPrefix+"compression"] = compressionAlgorithmV2 metadata[ReservedMetadataPrefix+"actual-size"] = strconv.FormatInt(size, 10)