[PATCH 07 of 11] worker: estimate whether it's worth running a task in parallel
Bryan O'Sullivan
bos at serpentine.com
Sat Feb 9 08:06:47 CST 2013
# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1360418465 0
# Node ID d167155227b6752f01da2c0693f27cc42a7a8dde
# Parent 06aa98485023be2c427552053398e8217db7b4d6
worker: estimate whether it's worth running a task in parallel
Not implemented for Windows yet.
diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -27,3 +27,17 @@ def countcpus():
pass
return 1
+
+_numworkers = min(max(countcpus(), 4), 32)
+
+if os.name == 'nt':
+ _startupcost = 1e9
+else:
+ _startupcost = 0.01
+
+def worthwhile(costperop, nops):
+ '''try to determine whether the benefit of multiple processes can
+ outweigh the cost of starting them'''
+ linear = costperop * nops
+ benefit = linear - (_startupcost * _numworkers + linear / _numworkers)
+ return benefit >= 0.15
More information about the Mercurial-devel
mailing list