comparison mercurial/hgweb/protocol.py @ 29760:5e2365698d44

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 07 Aug 2016 18:09:58 -0700
parents 032c4c2f802a
children b1809f5d7630
comparison
equal deleted inserted replaced
29759:aba2bb2a6d0f 29760:5e2365698d44
72 def restore(self): 72 def restore(self):
73 val = self.ui.fout.getvalue() 73 val = self.ui.fout.getvalue()
74 self.ui.ferr, self.ui.fout = self.oldio 74 self.ui.ferr, self.ui.fout = self.oldio
75 return val 75 return val
76 def groupchunks(self, cg): 76 def groupchunks(self, cg):
77 z = zlib.compressobj() 77 z = zlib.compressobj(self.ui.configint('server', 'zliblevel', -1))
78 while True: 78 while True:
79 chunk = cg.read(4096) 79 chunk = cg.read(4096)
80 if not chunk: 80 if not chunk:
81 break 81 break
82 yield z.compress(chunk) 82 yield z.compress(chunk)