comparison mercurial/worker.py @ 28181:f8efc8a3a991

worker: change partition strategy to every Nth element The only consumer of the worker pool code today is `hg update`. Previously, the algorithm to partition work to each worker process preserved input list ordering. We'd take the first N elements, then the next N elements, etc. Measurements on mozilla-central demonstrate this isn't an optimal partitioning strategy. I added debug code to print when workers were exiting. When performing a working copy update on a previously empty working copy of mozilla-central, I noticed that process lifetimes were all over the map. One worker would complete after 7s. Many would complete after 12s. And another worker would often take >16s. This behavior occurred for many worker process counts and was more pronounced on some than others. What I suspect is happening is some workers end up with lots of small files and others with large files. This is because the update code passes in actions according to sorted filenames. And, directories under tend to accumulate similar files. For example, test directories often consist of many small test files and media directories contain binary (often larger) media files. This patch changes the partitioning algorithm to select every Nth element from the input list. Each worker thus has a similar composition of files to operate on. The result of this change is that worker processes now all tend to exit around the same time. The possibility of a long pole due to being unlucky and receiving all the large files has been mitigated. Overall execution time seems to drop, but not by a statistically significant amount on mozilla-central. However, repositories with directories containing many large files will likely show a drop. There shouldn't be any regressions due to partial manifest decoding because the update code already iterates the manifest to determine what files to operate on, so the manifest should already be decoded.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 20 Feb 2016 15:56:44 -0800
parents 56b2bcea2529
children 3eb7faf6d958
comparison
equal deleted inserted replaced
28180:2836a43c7722 28181:f8efc8a3a991
150 if os.name != 'nt': 150 if os.name != 'nt':
151 _platformworker = _posixworker 151 _platformworker = _posixworker
152 _exitstatus = _posixexitstatus 152 _exitstatus = _posixexitstatus
153 153
154 def partition(lst, nslices): 154 def partition(lst, nslices):
155 '''partition a list into N slices of equal size''' 155 '''partition a list into N slices of roughly equal size
156 n = len(lst) 156
157 chunk, slop = n / nslices, n % nslices 157 The current strategy takes every Nth element from the input. If
158 end = 0 158 we ever write workers that need to preserve grouping in input
159 for i in xrange(nslices): 159 we should consider allowing callers to specify a partition strategy.
160 start = end 160 '''
161 end = start + chunk 161 for i in range(nslices):
162 if slop: 162 yield lst[i::nslices]
163 end += 1
164 slop -= 1
165 yield lst[start:end]