From daebd6cbc2ae642021bcc209484e7249edc656ea Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Wed, 9 Apr 2025 13:59:27 -0700 Subject: [PATCH] sync: Warn about excessive job counts Warn users if the effective job count specified via `-j`, `--jobs-network`, or `--jobs-checkout` exceeds a threshold (currently 100). This encourages users to use more reasonable values. Bug: 406868778 Bug: 254914814 Change-Id: I116e2bbaf3dc824c04d1b2fbe52cf9ca5be77b9a Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/466801 Reviewed-by: Mike Frysinger Commit-Queue: Gavin Mak Tested-by: Gavin Mak --- subcmds/sync.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/subcmds/sync.py b/subcmds/sync.py index 49874c44..3dc74f1f 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -350,6 +350,8 @@ later is required to fix a server side protocol bug. # value later on. PARALLEL_JOBS = 0 + _JOBS_WARN_THRESHOLD = 100 + def _Options(self, p, show_smart=True): p.add_option( "--jobs-network", @@ -1728,6 +1730,24 @@ later is required to fix a server side protocol bug. opt.jobs_network = min(opt.jobs_network, jobs_soft_limit) opt.jobs_checkout = min(opt.jobs_checkout, jobs_soft_limit) + # Warn once if effective job counts seem excessively high. + # Prioritize --jobs, then --jobs-network, then --jobs-checkout. + job_options_to_check = ( + ("--jobs", opt.jobs), + ("--jobs-network", opt.jobs_network), + ("--jobs-checkout", opt.jobs_checkout), + ) + for name, value in job_options_to_check: + if value > self._JOBS_WARN_THRESHOLD: + logger.warning( + "High job count (%d > %d) specified for %s; this may " + "lead to excessive resource usage or diminishing returns.", + value, + self._JOBS_WARN_THRESHOLD, + name, + ) + break + def Execute(self, opt, args): errors = [] try: