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
=== modified file 'utilities/create-lp-wadl-and-apidoc.py'
--- utilities/create-lp-wadl-and-apidoc.py 2010-10-25 13:16:10 +0000
+++ utilities/create-lp-wadl-and-apidoc.py 2010-11-19 14:39:37 +0000
@@ -12,6 +12,7 @@
12"""12"""
13import _pythonpath # Not lint, actually needed.13import _pythonpath # Not lint, actually needed.
1414
15from multiprocessing import Process
15import optparse16import optparse
16import os17import os
17import sys18import sys
@@ -32,6 +33,31 @@
32 f.close()33 f.close()
3334
3435
36def make_files(path_template, directory, version, force):
37 wadl_filename = path_template % {'version': version}
38 # If the WADL file doesn't exist or we're being forced to regenerate
39 # it...
40 if (not os.path.exists(wadl_filename) or force):
41 print "Writing WADL for version %s to %s." % (
42 version, wadl_filename)
43 write(wadl_filename, generate_wadl(version))
44 else:
45 print "Skipping already present WADL file:", wadl_filename
46
47 # Now, convert the WADL into an human-readable description and
48 # put the HTML in the same directory as the WADL.
49 html_filename = os.path.join(directory, version + ".html")
50 # If the HTML file doesn't exist or we're being forced to regenerate
51 # it...
52 if (not os.path.exists(html_filename) or force):
53 print "Writing apidoc for version %s to %s" % (
54 version, html_filename)
55 write(html_filename, generate_html(wadl_filename,
56 suppress_stderr=False))
57 else:
58 print "Skipping already present HTML file:", html_filename
59
60
35def main(path_template, force=False):61def main(path_template, force=False):
36 WebServiceApplication.cached_wadl = None # do not use cached file version62 WebServiceApplication.cached_wadl = None # do not use cached file version
37 execute_zcml_for_scripts()63 execute_zcml_for_scripts()
@@ -47,29 +73,17 @@
47 f = open(index_filename, 'w')73 f = open(index_filename, 'w')
48 f.write(template(config=config))74 f.write(template(config=config))
4975
76 # Start a process to build each set of WADL and HTML files.
77 processes = []
50 for version in config.active_versions:78 for version in config.active_versions:
51 wadl_filename = path_template % {'version': version}79 p = Process(target=make_files,
52 # If the WADL file doesn't exist or we're being forced to regenerate80 args=(path_template, directory, version, force))
53 # it...81 p.start()
54 if (not os.path.exists(wadl_filename) or force):82 processes.append(p)
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
6083
61 # Now, convert the WADL into an human-readable description and84 # Wait for all the subprocesses to finish.
62 # put the HTML in the same directory as the WADL.85 for p in processes:
63 html_filename = os.path.join(directory, version + ".html")86 p.join()
64 # If the HTML file doesn't exist or we're being forced to regenerate
65 # it...
66 if (not os.path.exists(html_filename) or force):
67 print "Writing apidoc for version %s to %s" % (
68 version, html_filename)
69 write(html_filename, generate_html(wadl_filename,
70 suppress_stderr=False))
71 else:
72 print "Skipping already present HTML file:", html_filename
7387
74 return 088 return 0
7589