From fba0f09f4f3f3d605b312464d5f1d046d0c1db8e Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 26 Apr 2022 14:25:53 +0200 Subject: [PATCH] Do not compress content smaller than 1400 Bytes --- src/server/response.cpp | 11 +++++++++-- test/server.cpp | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/server/response.cpp b/src/server/response.cpp index c149d59c7..ae80a5846 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -33,8 +33,15 @@ #include - -#define KIWIX_MIN_CONTENT_SIZE_TO_COMPRESS 100 +// This is somehow a magic value. +// If this value is too small, we will compress (and lost cpu time) too much +// content. +// If this value is too big, we will not compress enough content and send too +// much data. +// If we assume that MTU is 1500 Bytes it is useless to compress +// content smaller as the content will be sent in one packet anyway. +// 1400 Bytes seems to be a common accepted limit. +#define KIWIX_MIN_CONTENT_SIZE_TO_COMPRESS 1400 namespace kiwix { diff --git a/test/server.cpp b/test/server.cpp index bf02a70cd..9f4356b5a 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -185,13 +185,10 @@ const ResourceCollection resources200Compressible{ { WITH_ETAG, "/ROOT/skin/taskbar.css" }, { WITH_ETAG, "/ROOT/skin/block_external.js" }, - { NO_ETAG, "/ROOT/catalog/root.xml" }, - { NO_ETAG, "/ROOT/catalog/searchdescription.xml" }, { NO_ETAG, "/ROOT/catalog/search" }, { NO_ETAG, "/ROOT/search?content=zimfile&pattern=a" }, - { NO_ETAG, "/ROOT/suggest?content=zimfile" }, { NO_ETAG, "/ROOT/suggest?content=zimfile&term=ray" }, { NO_ETAG, "/ROOT/catch/external?source=www.example.com" }, @@ -224,7 +221,10 @@ const ResourceCollection resources200Uncompressible{ { WITH_ETAG, "/ROOT/corner_cases/-/empty.css" }, { WITH_ETAG, "/ROOT/corner_cases/-/empty.js" }, - // The title and creator are too small to be compressed + // The following url's responses are too small to be compressed + { NO_ETAG, "/ROOT/catalog/root.xml" }, + { NO_ETAG, "/ROOT/catalog/searchdescription.xml" }, + { NO_ETAG, "/ROOT/suggest?content=zimfile" }, { WITH_ETAG, "/ROOT/raw/zimfile/meta/Creator" }, { WITH_ETAG, "/ROOT/raw/zimfile/meta/Title" }, };