Skip to content
Snippets Groups Projects
Commit dcb27c15 authored by Bryan O'Sullivan's avatar Bryan O'Sullivan
Browse files

worker: estimate whether it's worth running a task in parallel

Not implemented for Windows yet.
parent fed06dd0
No related branches found
No related tags found
No related merge requests found
......@@ -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``.
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment