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
diff --git a/scripts/check-syntax b/scripts/check-syntax
index 28a62a4..37c21cf 100755
--- a/scripts/check-syntax
+++ b/scripts/check-syntax
@@ -21,6 +21,7 @@ import re
21import sys21import sys
22import subprocess22import subprocess
23import signal23import signal
24import concurrent.futures
24import multiprocessing25import multiprocessing
2526
26import cve_lib27import cve_lib
@@ -249,6 +250,13 @@ parser.add_option(
249 action="store_true",250 action="store_true",
250 default=False,251 default=False,
251)252)
253parser.add_option(
254 "-j",
255 "--jobs",
256 type=int,
257 help="Number of jobs to run simultaneously (default: %d)" % multiprocessing.cpu_count(),
258 default=multiprocessing.cpu_count(),
259)
252# parser.add_option("-c", "--cna", help="Ensure every CVE assigned by Canonical's CNA has an entry", action='store_true')260# parser.add_option("-c", "--cna", help="Ensure every CVE assigned by Canonical's CNA has an entry", action='store_true')
253(opt, args) = parser.parse_args()261(opt, args) = parser.parse_args()
254262
@@ -1055,7 +1063,10 @@ def check_cve(cve):
1055 debug(data)1063 debug(data)
1056 return cve_okay1064 return cve_okay
10571065
1058with multiprocessing.Pool(multiprocessing.cpu_count()) as p:1066# use ProcessPoolExecutor for parallel processing since this is more efficient
1067# than multiple threads via ThreadPoolExecutor as we can keep each at 100% CPU
1068# utilisation
1069with concurrent.futures.ProcessPoolExecutor(max_workers=opt.jobs) as p:
1059 results = p.map(check_cve, args)1070 results = p.map(check_cve, args)
1060 all_okay = all(results)1071 all_okay = all(results)
10611072

Subscribers

People subscribed via source and target branches