comparison mercurial/streamclone.py @ 27897:2fdbf22a1b63

streamclone: use backgroundfilecloser (issue4889) Closing files that have been appended to is slow on Windows/NTFS. CloseHandle() calls on this platform often take 1-10ms - and that's on my i7-6700K Skylake processor with a modern and fast SSD. Contrast with other I/O operations, such as writing data, which take <100us. This means that creating/appending thousands of files can add significant overhead. For example, cloning mozilla-central creates ~232,000 revlog files. Assuming 1ms per CloseHandle(), that yields 232s (3:52) of wall time waiting for file closes! The impact of this overhead can be measured most directly when applying stream clone bundles. Applying these files is effectively uncompressing a tar archive (read: it's very fast). Using a RAM disk (read: no I/O wait), the difference in wall time for a `hg debugapplystreamclonebundle` for a ~1731 MB mozilla-central bundle between Windows and Linux from the same machine is drastic: Linux: ~12.8s (128MB/s) Windows: ~352.0s (4.7MB/s) Windows is ~27.5x slower. Yikes! After this patch: Linux: ~12.8s (128MB/s) Windows: ~102.1s (16.1MB/s) Windows is now ~3.4x faster. Unfortunately, it is still ~8x slower than Linux. Profiling reveals a few hot code paths that could likely be improved. But those are for other patches. This patch introduces test-clone-uncompressed.t because existing tests of `clone --uncompressed` are scattered about and adding a variation for background thread closing to e.g. test-http.t doesn't feel correct.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 14 Jan 2016 13:44:01 -0800
parents 1d29893240cc
children 61d1a3cc6e1c aa440c3d7c5d
comparison
equal deleted inserted replaced
27896:1d29893240cc 27897:2fdbf22a1b63
296 handled_bytes = 0 296 handled_bytes = 0
297 repo.ui.progress(_('clone'), 0, total=bytecount) 297 repo.ui.progress(_('clone'), 0, total=bytecount)
298 start = time.time() 298 start = time.time()
299 299
300 with repo.transaction('clone'): 300 with repo.transaction('clone'):
301 if True: 301 with repo.svfs.backgroundclosing(repo.ui, expectedcount=filecount):
302 for i in xrange(filecount): 302 for i in xrange(filecount):
303 # XXX doesn't support '\n' or '\r' in filenames 303 # XXX doesn't support '\n' or '\r' in filenames
304 l = fp.readline() 304 l = fp.readline()
305 try: 305 try:
306 name, size = l.split('\0', 1) 306 name, size = l.split('\0', 1)
310 _('unexpected response from remote server:'), l) 310 _('unexpected response from remote server:'), l)
311 if repo.ui.debugflag: 311 if repo.ui.debugflag:
312 repo.ui.debug('adding %s (%s)\n' % 312 repo.ui.debug('adding %s (%s)\n' %
313 (name, util.bytecount(size))) 313 (name, util.bytecount(size)))
314 # for backwards compat, name was partially encoded 314 # for backwards compat, name was partially encoded
315 with repo.svfs(store.decodedir(name), 'w') as ofp: 315 path = store.decodedir(name)
316 with repo.svfs(path, 'w', backgroundclose=True) as ofp:
316 for chunk in util.filechunkiter(fp, limit=size): 317 for chunk in util.filechunkiter(fp, limit=size):
317 handled_bytes += len(chunk) 318 handled_bytes += len(chunk)
318 repo.ui.progress(_('clone'), handled_bytes, 319 repo.ui.progress(_('clone'), handled_bytes,
319 total=bytecount) 320 total=bytecount)
320 ofp.write(chunk) 321 ofp.write(chunk)