diff options
author | Ahmon Dancy <adancy@wikimedia.org> | 2020-07-27 14:46:49 -0700 |
---|---|---|
committer | Antoine Musso <hashar@free.fr> | 2021-03-10 18:15:07 +0100 |
commit | a160d10735c62e046b72e31e8eb7756c5f06e09f (patch) | |
tree | e35d97523d5df86294d2ac3c7add78cf4d8f1ae9 | |
parent | 089471c8fbe655ae1e519fb415394aa9485a6554 (diff) | |
download | gear-a160d10735c62e046b72e31e8eb7756c5f06e09f.tar.gz |
wakeConnections: Randomize connections before scanning them
gear/__init__.py:
Modified Server.wakeConnections() so that it randomizes the
list of active connections before sending out NOOP's to them.
This will hopefully spread workload across machines more evenly
when there are multiple workers per machine.
Reference: https://phabricator.wikimedia.org/T258630
Change-Id: I05dcb9fa383f3aefc8b5b1bb9dd8b3ff6ff7f37d
-rw-r--r-- | gear/__init__.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/gear/__init__.py b/gear/__init__.py index f7fc767..4a0fcb7 100644 --- a/gear/__init__.py +++ b/gear/__init__.py @@ -15,6 +15,7 @@ import errno import logging import os +import random import select import six import socket @@ -3295,7 +3296,13 @@ class Server(BaseClientServer): def wakeConnections(self, job=None): p = Packet(constants.RES, constants.NOOP, b'') - for connection in self.active_connections: + + # Use a randomized copy of active_connections to try + # to spread workload across the machines that workers are on. + conns = self.active_connections[:] + random.shuffle(conns) # Modifies the list + + for connection in conns: if connection.state == 'SLEEP': if ((job and job.name in connection.functions) or (job is None)): |