Patchwork [07,of,11] worker: estimate whether it's worth running a task in parallel

login
register
mail settings
Submitter Bryan O'Sullivan
Date Feb. 9, 2013, 2:06 p.m.
Message ID <d167155227b6752f01da.1360418807@australite.local>
Download mbox | patch
Permalink /patch/872/
State Accepted
Commit dcb27c153a40ec251f0642ec4c1580a9d2b9b441
Headers show

Comments

Bryan O'Sullivan - Feb. 9, 2013, 2:06 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@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.

Patch

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