Browse Source

[git_cl] Limit number of concurrent connections

When git cl status is executed, it's possible that Gerrit will throttle
some requests. This change sets upper bound of concurrent connections to
20.

R=gavinmak@google.com

Fixed: b/319248186
Change-Id: I51b1d87109447efc8c86d615f12bcafe8c317a90
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5181274
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Josip Sokcevic 1 year ago
parent
commit
cd076ba1b0
1 changed files with 4 additions and 3 deletions
  1. 4 3
      git_cl.py

+ 4 - 3
git_cl.py

@@ -81,6 +81,7 @@ GIT_HASH_RE = re.compile(r'\b([a-f0-9]{6})[a-f0-9]{34}\b', flags=re.I)
 GITCOOKIES_REDACT_RE = re.compile(r'1/.*')
 GITCOOKIES_REDACT_RE = re.compile(r'1/.*')
 
 
 MAX_ATTEMPTS = 3
 MAX_ATTEMPTS = 3
+MAX_CONCURRENT_CONNECTION = 20
 
 
 # The maximum number of traces we will keep. Multiplied by 3 since we store
 # The maximum number of traces we will keep. Multiplied by 3 since we store
 # 3 files per trace.
 # 3 files per trace.
@@ -3926,8 +3927,8 @@ def get_cl_statuses(changes, fine_grained, max_processes=None):
     Otherwise, simply indicate if there's a matching url for the given branches.
     Otherwise, simply indicate if there's a matching url for the given branches.
 
 
     If max_processes is specified, it is used as the maximum number of processes
     If max_processes is specified, it is used as the maximum number of processes
-    to spawn to fetch CL status from the server. Otherwise 1 process per branch is
-    spawned.
+    to spawn to fetch CL status from the server. Otherwise 1 process per branch
+    is spawned, up to max of MAX_CONCURRENT_CONNECTION.
 
 
     See GetStatus() for a list of possible statuses.
     See GetStatus() for a list of possible statuses.
     """
     """
@@ -3956,7 +3957,7 @@ def get_cl_statuses(changes, fine_grained, max_processes=None):
                               cl.GetIssue())
                               cl.GetIssue())
             raise
             raise
 
 
-    threads_count = len(changes)
+    threads_count = min(MAX_CONCURRENT_CONNECTION, len(changes))
     if max_processes:
     if max_processes:
         threads_count = max(1, min(threads_count, max_processes))
         threads_count = max(1, min(threads_count, max_processes))
     logging.debug('querying %d CLs using %d threads', len(changes),
     logging.debug('querying %d CLs using %d threads', len(changes),