changeset 18636:dcb27c153a40

worker: estimate whether it's worth running a task in parallel Not implemented for Windows yet.
author Bryan O'Sullivan <bryano@fb.com>
date Sat, 09 Feb 2013 15:51:26 -0800
parents fed06dd07665
children ac4dbceeb14a
files mercurial/help/config.txt mercurial/worker.py
diffstat 2 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/help/config.txt	Sat Feb 09 15:22:12 2013 -0800
+++ b/mercurial/help/config.txt	Sat Feb 09 15:51:26 2013 -0800
@@ -1463,3 +1463,15 @@
 
 ``templates``
     Where to find the HTML templates. Default is install path.
+
+``worker``
+----------
+
+Parallel master/worker configuration. We currently perform working
+directory updates in parallel on Unix-like systems, which greatly
+helps performance.
+
+``numcpus``
+    Number of CPUs to use for parallel operations. Default is 4 or the
+    number of CPUs on the system, whichever is larger. A zero or
+    negative value is treated as ``use the default``.
--- a/mercurial/worker.py	Sat Feb 09 15:22:12 2013 -0800
+++ b/mercurial/worker.py	Sat Feb 09 15:51:26 2013 -0800
@@ -5,7 +5,8 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-import os
+from i18n import _
+import os, util
 
 def countcpus():
     '''try to count the number of CPUs on the system'''
@@ -27,3 +28,27 @@
         pass
 
     return 1
+
+def _numworkers(ui):
+    s = ui.config('worker', 'numcpus')
+    if s:
+        try:
+            n = int(s)
+            if n >= 1:
+                return n
+        except ValueError:
+            raise util.Abort(_('number of cpus must be an integer'))
+    return min(max(countcpus(), 4), 32)
+
+if os.name == 'posix':
+    _startupcost = 0.01
+else:
+    _startupcost = 1e30
+
+def worthwhile(ui, costperop, nops):
+    '''try to determine whether the benefit of multiple processes can
+    outweigh the cost of starting them'''
+    linear = costperop * nops
+    workers = _numworkers(ui)
+    benefit = linear - (_startupcost * workers + linear / workers)
+    return benefit >= 0.15