Merge lp:~benji/launchpad/faster-wadl into lp:launchpad

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: no longer in the source branch.
Merged at revision: 12039
Proposed branch: lp:~benji/launchpad/faster-wadl
Merge into: lp:launchpad
Diff against target: 81 lines (+35/-21)
1 file modified
utilities/create-lp-wadl-and-apidoc.py (+35/-21)
To merge this branch: bzr merge lp:~benji/launchpad/faster-wadl
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+41315@code.launchpad.net

Commit message

[r=adeuring][ui=none][no-qa] Use the stdlib multiprocess module to run WADL generation in parallel subprocesses.

Description of the change

This branch uses the stdlib multiprocess module to run WADL generation
in parallel subprocesses. This speeds up WADL generation a fair bit:
91.9s to 70.0s on my laptop.

The change was a straight-forward refactoring to lift out the make_files
function and then use it as the target of a Process.

The script can be run by itself like so:

    LPCONFIG=development bin/py ./utilities/create-lp-wadl-and-apidoc.py --force "lib/canonical/launchpad/apidoc/wadl-development-%(version)s.xml"

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote :

Yay, less boredom for staring work on a new branch!

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utilities/create-lp-wadl-and-apidoc.py'
2--- utilities/create-lp-wadl-and-apidoc.py 2010-10-25 13:16:10 +0000
3+++ utilities/create-lp-wadl-and-apidoc.py 2010-11-19 14:39:37 +0000
4@@ -12,6 +12,7 @@
5 """
6 import _pythonpath # Not lint, actually needed.
7
8+from multiprocessing import Process
9 import optparse
10 import os
11 import sys
12@@ -32,6 +33,31 @@
13 f.close()
14
15
16+def make_files(path_template, directory, version, force):
17+ wadl_filename = path_template % {'version': version}
18+ # If the WADL file doesn't exist or we're being forced to regenerate
19+ # it...
20+ if (not os.path.exists(wadl_filename) or force):
21+ print "Writing WADL for version %s to %s." % (
22+ version, wadl_filename)
23+ write(wadl_filename, generate_wadl(version))
24+ else:
25+ print "Skipping already present WADL file:", wadl_filename
26+
27+ # Now, convert the WADL into an human-readable description and
28+ # put the HTML in the same directory as the WADL.
29+ html_filename = os.path.join(directory, version + ".html")
30+ # If the HTML file doesn't exist or we're being forced to regenerate
31+ # it...
32+ if (not os.path.exists(html_filename) or force):
33+ print "Writing apidoc for version %s to %s" % (
34+ version, html_filename)
35+ write(html_filename, generate_html(wadl_filename,
36+ suppress_stderr=False))
37+ else:
38+ print "Skipping already present HTML file:", html_filename
39+
40+
41 def main(path_template, force=False):
42 WebServiceApplication.cached_wadl = None # do not use cached file version
43 execute_zcml_for_scripts()
44@@ -47,29 +73,17 @@
45 f = open(index_filename, 'w')
46 f.write(template(config=config))
47
48+ # Start a process to build each set of WADL and HTML files.
49+ processes = []
50 for version in config.active_versions:
51- wadl_filename = path_template % {'version': version}
52- # If the WADL file doesn't exist or we're being forced to regenerate
53- # it...
54- if (not os.path.exists(wadl_filename) or force):
55- print "Writing WADL for version %s to %s." % (
56- version, wadl_filename)
57- write(wadl_filename, generate_wadl(version))
58- else:
59- print "Skipping already present WADL file:", wadl_filename
60+ p = Process(target=make_files,
61+ args=(path_template, directory, version, force))
62+ p.start()
63+ processes.append(p)
64
65- # Now, convert the WADL into an human-readable description and
66- # put the HTML in the same directory as the WADL.
67- html_filename = os.path.join(directory, version + ".html")
68- # If the HTML file doesn't exist or we're being forced to regenerate
69- # it...
70- if (not os.path.exists(html_filename) or force):
71- print "Writing apidoc for version %s to %s" % (
72- version, html_filename)
73- write(html_filename, generate_html(wadl_filename,
74- suppress_stderr=False))
75- else:
76- print "Skipping already present HTML file:", html_filename
77+ # Wait for all the subprocesses to finish.
78+ for p in processes:
79+ p.join()
80
81 return 0
82