Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] egencache: parallelize --update-changelogs (bug 565540)
Date: Thu, 12 Nov 2015 00:11:34
Message-Id: 1447287069-30866-1-git-send-email-zmedico@gentoo.org
1 Use the TaskScheduler class to parallelize GenChangeLogs. Fix
2 AsyncFunction so it does not re-define 'args' in __slots__.
3
4 X-Gentoo-Bug: 565540
5 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=565540
6 ---
7 bin/egencache | 24 +++++++++++++++++++-----
8 pym/portage/util/_async/AsyncFunction.py | 5 ++++-
9 2 files changed, 23 insertions(+), 6 deletions(-)
10
11 diff --git a/bin/egencache b/bin/egencache
12 index 51d115a..76eb00b 100755
13 --- a/bin/egencache
14 +++ b/bin/egencache
15 @@ -55,7 +55,9 @@ from portage.const import TIMESTAMP_FORMAT
16 from portage.manifest import guessManifestFileType
17 from portage.package.ebuild._parallel_manifest.ManifestScheduler import ManifestScheduler
18 from portage.util import cmp_sort_key, writemsg_level
19 +from portage.util._async.AsyncFunction import AsyncFunction
20 from portage.util._async.run_main_scheduler import run_main_scheduler
21 +from portage.util._async.TaskScheduler import TaskScheduler
22 from portage.util._eventloop.global_event_loop import global_event_loop
23 from portage import cpv_getkey
24 from portage.dep import Atom, isjustname
25 @@ -748,7 +750,8 @@ class _special_filename(_filename_base):
26 return self.file_name < other.file_name
27
28 class GenChangeLogs(object):
29 - def __init__(self, portdb, changelog_output, changelog_reversed):
30 + def __init__(self, portdb, changelog_output, changelog_reversed,
31 + max_jobs=None, max_load=None):
32 self.returncode = os.EX_OK
33 self._portdb = portdb
34 self._wrapper = textwrap.TextWrapper(
35 @@ -758,6 +761,8 @@ class GenChangeLogs(object):
36 )
37 self._changelog_output = changelog_output
38 self._changelog_reversed = changelog_reversed
39 + self._max_jobs = max_jobs
40 + self._max_load = max_load
41
42 @staticmethod
43 def grab(cmd):
44 @@ -882,7 +887,7 @@ class GenChangeLogs(object):
45
46 output.close()
47
48 - def run(self):
49 + def _task_iter(self):
50 repo_path = self._portdb.porttrees[0]
51 os.chdir(repo_path)
52
53 @@ -908,7 +913,12 @@ class GenChangeLogs(object):
54 cmod = 0
55
56 if float(cmod) < float(lmod):
57 - self.generate_changelog(cp)
58 + yield AsyncFunction(target=self.generate_changelog, args=[cp])
59 +
60 + def run(self):
61 + return run_main_scheduler(
62 + TaskScheduler(self._task_iter(), event_loop=global_event_loop(),
63 + max_jobs=self._max_jobs, max_load=self._max_load))
64
65 def egencache_main(args):
66
67 @@ -1149,8 +1159,12 @@ def egencache_main(args):
68 if options.update_changelogs:
69 gen_clogs = GenChangeLogs(portdb,
70 changelog_output=options.changelog_output,
71 - changelog_reversed=options.changelog_reversed)
72 - gen_clogs.run()
73 + changelog_reversed=options.changelog_reversed,
74 + max_jobs=options.jobs,
75 + max_load=options.load_average)
76 + signum = gen_clogs.run()
77 + if signum is not None:
78 + sys.exit(128 + signum)
79 ret.append(gen_clogs.returncode)
80
81 if options.write_timestamp:
82 diff --git a/pym/portage/util/_async/AsyncFunction.py b/pym/portage/util/_async/AsyncFunction.py
83 index b6142a2..40f6c5e 100644
84 --- a/pym/portage/util/_async/AsyncFunction.py
85 +++ b/pym/portage/util/_async/AsyncFunction.py
86 @@ -15,7 +15,10 @@ class AsyncFunction(ForkProcess):
87 "result" attribute after the forked process has exited.
88 """
89
90 - __slots__ = ('args', 'kwargs', 'result', 'target',
91 + # NOTE: This class overrides the meaning of the SpawnProcess 'args'
92 + # attribute, and uses it to hold the positional arguments for the
93 + # 'target' function.
94 + __slots__ = ('kwargs', 'result', 'target',
95 '_async_func_reader', '_async_func_reader_pw')
96
97 def _start(self):
98 --
99 2.4.9

Replies