diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt index fed06dd07665515de823c912bc94b8de087af314_bWVyY3VyaWFsL2hlbHAvY29uZmlnLnR4dA==..dcb27c153a40ec251f0642ec4c1580a9d2b9b441_bWVyY3VyaWFsL2hlbHAvY29uZmlnLnR4dA== 100644 --- a/mercurial/help/config.txt +++ b/mercurial/help/config.txt @@ -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``. diff --git a/mercurial/worker.py b/mercurial/worker.py index fed06dd07665515de823c912bc94b8de087af314_bWVyY3VyaWFsL3dvcmtlci5weQ==..dcb27c153a40ec251f0642ec4c1580a9d2b9b441_bWVyY3VyaWFsL3dvcmtlci5weQ== 100644 --- a/mercurial/worker.py +++ b/mercurial/worker.py @@ -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