hgweb: config option to control zlib compression level
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 07 Aug 2016 18:09:58 -0700
changeset 29760 5e2365698d44
parent 29759 aba2bb2a6d0f
child 29761 155f0cc3f813
hgweb: config option to control zlib compression level Before this patch, the HTTP transport protocol would always zlib compress certain responses (notably "getbundle" wire protocol commands) at zlib compression level 6. zlib can be a massive CPU resource sink for servers. Some server operators may wish to reduce server-side CPU requirements while requiring more bandwidth. This is common on corporate intranets, for example. Others may wish to use more CPU but reduce bandwidth. This patch introduces a config option to allow server operators to control the zlib compression level. On the "mozilla-unified" generaldelta repository, setting this value to "0" (disable compression) results in server-side CPU utilization for a `hg clone` going from ~180s to ~124s CPU time on my i7-6700K. A level of "1" (which increases the transfer size from ~1,074 MB at level 6 to ~1,222 MB) utilizes ~132s CPU time.
mercurial/help/config.txt
mercurial/hgweb/protocol.py
--- a/mercurial/help/config.txt	Sat Aug 06 17:04:22 2016 -0700
+++ b/mercurial/help/config.txt	Sun Aug 07 18:09:58 2016 -0700
@@ -1557,6 +1557,21 @@
     repositories to the exchange format required by the bundle1 data
     format can consume a lot of CPU.
 
+``zliblevel``
+    Integer between ``-1`` and ``9`` that controls the zlib compression level
+    for wire protocol commands that send zlib compressed output (notably the
+    commands that send repository history data).
+
+    The default (``-1``) uses the default zlib compression level, which is
+    likely equivalent to ``6``. ``0`` means no compression. ``9`` means
+    maximum compression.
+
+    Setting this option allows server operators to make trade-offs between
+    bandwidth and CPU used. Lowering the compression lowers CPU utilization
+    but sends more bytes to clients.
+
+    This option only impacts the HTTP server.
+
 ``smtp``
 --------
 
--- a/mercurial/hgweb/protocol.py	Sat Aug 06 17:04:22 2016 -0700
+++ b/mercurial/hgweb/protocol.py	Sun Aug 07 18:09:58 2016 -0700
@@ -74,7 +74,7 @@
         self.ui.ferr, self.ui.fout = self.oldio
         return val
     def groupchunks(self, cg):
-        z = zlib.compressobj()
+        z = zlib.compressobj(self.ui.configint('server', 'zliblevel', -1))
         while True:
             chunk = cg.read(4096)
             if not chunk: