Merge ~alexmurray/ubuntu-cve-tracker:check-syntax-n-jobs into ubuntu-cve-tracker:master

Proposed by Alex Murray
Status: Merged
Merged at revision: 465955330a74f28211d0f982060693c8b0dfad01
Proposed branch: ~alexmurray/ubuntu-cve-tracker:check-syntax-n-jobs
Merge into: ubuntu-cve-tracker:master
Diff against target: 37 lines (+12/-1)
1 file modified
scripts/check-syntax (+12/-1)
Reviewer Review Type Date Requested Status
Eduardo Barretto Approve
Review via email: mp+447789@code.launchpad.net

Description of the change

check-syntax can quite easily monopolise your whole CPU making it quite unresponsive - add an option so we can change the number of processes it uses in parallel to limit this impact

https://chat.canonical.com/canonical/pl/4td4fgdp1tg7bmzbfc7wz8yxtr

To post a comment you must log in.
Revision history for this message
Eduardo Barretto (ebarretto) wrote :

lgtm, thanks!

the CI issue is unrelated to this and was fixed already, so a rebase on top of master should make the CI pass.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/check-syntax b/scripts/check-syntax
2index 28a62a4..37c21cf 100755
3--- a/scripts/check-syntax
4+++ b/scripts/check-syntax
5@@ -21,6 +21,7 @@ import re
6 import sys
7 import subprocess
8 import signal
9+import concurrent.futures
10 import multiprocessing
11
12 import cve_lib
13@@ -249,6 +250,13 @@ parser.add_option(
14 action="store_true",
15 default=False,
16 )
17+parser.add_option(
18+ "-j",
19+ "--jobs",
20+ type=int,
21+ help="Number of jobs to run simultaneously (default: %d)" % multiprocessing.cpu_count(),
22+ default=multiprocessing.cpu_count(),
23+)
24 # parser.add_option("-c", "--cna", help="Ensure every CVE assigned by Canonical's CNA has an entry", action='store_true')
25 (opt, args) = parser.parse_args()
26
27@@ -1055,7 +1063,10 @@ def check_cve(cve):
28 debug(data)
29 return cve_okay
30
31-with multiprocessing.Pool(multiprocessing.cpu_count()) as p:
32+# use ProcessPoolExecutor for parallel processing since this is more efficient
33+# than multiple threads via ThreadPoolExecutor as we can keep each at 100% CPU
34+# utilisation
35+with concurrent.futures.ProcessPoolExecutor(max_workers=opt.jobs) as p:
36 results = p.map(check_cve, args)
37 all_okay = all(results)
38

Subscribers

People subscribed via source and target branches