This is an automated email from the ASF dual-hosted git repository. granthenke pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 9106a3ca8d5b44a8305cb01a012064358bf5dcb9 Author: Todd Lipcon <[email protected]> AuthorDate: Wed Jan 15 01:26:31 2020 -0800 webserver: use faster gzip compression If an HTTP client indicates that it supports gzip, we gzip-compress the web response. This can be beneficial over slow links, but the default gzip compression level is pretty slow. This changes the gzip compression to use the fastest level, which is several times faster, without that much loss in space. Change-Id: If97d883483a7313bd5496af68b17e968a5223b1a Reviewed-on: http://gerrit.cloudera.org:8080/15059 Tested-by: Kudu Jenkins Reviewed-by: Todd Lipcon <[email protected]> --- src/kudu/server/webserver.cc | 2 +- src/kudu/util/zlib.cc | 6 +++++- src/kudu/util/zlib.h | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/kudu/server/webserver.cc b/src/kudu/server/webserver.cc index 3dad6d7..f0c9861 100644 --- a/src/kudu/server/webserver.cc +++ b/src/kudu/server/webserver.cc @@ -626,7 +626,7 @@ void Webserver::SendResponse(struct sq_connection* connection, } ostringstream oss; - Status s = zlib::Compress(uncompressed, &oss); + Status s = zlib::CompressLevel(uncompressed, 1, &oss); if (s.ok()) { resp->output.str(oss.str()); is_compressed = true; diff --git a/src/kudu/util/zlib.cc b/src/kudu/util/zlib.cc index 4805885..702e6f6 100644 --- a/src/kudu/util/zlib.cc +++ b/src/kudu/util/zlib.cc @@ -70,9 +70,13 @@ Status ZlibResultToStatus(int rc) { } // anonymous namespace Status Compress(Slice input, ostream* out) { + return CompressLevel(input, Z_DEFAULT_COMPRESSION, out); +} + +Status CompressLevel(Slice input, int level, ostream* out) { z_stream zs; memset(&zs, 0, sizeof(zs)); - ZRETURN_NOT_OK(deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, + ZRETURN_NOT_OK(deflateInit2(&zs, level, Z_DEFLATED, 15 + 16 /* 15 window bits, enable gzip */, 8 /* memory level, max is 9 */, Z_DEFAULT_STRATEGY)); diff --git a/src/kudu/util/zlib.h b/src/kudu/util/zlib.h index 35330fd..478382b 100644 --- a/src/kudu/util/zlib.h +++ b/src/kudu/util/zlib.h @@ -29,6 +29,10 @@ namespace zlib { // In case of an error, some data may still be appended to 'out'. Status Compress(Slice input, std::ostream* out); +// The same as the above, but with a custom level (1-9, where 1 is fastest +// and 9 is best compression). +Status CompressLevel(Slice input, int level, std::ostream* out); + // Uncompress the zlib-compressed data in 'compressed', appending the result // to 'out'. //
