Shuffle fetch order for channels to prevent starvation

This commit is contained in:
Andrew Godwin 2015-11-06 13:33:51 +01:00
parent aaf2321db1
commit b9f07475b7

View File

@ -56,6 +56,8 @@ class RedisChannelBackend(BaseChannelBackend):
def receive_many(self, channels):
if not channels:
raise ValueError("Cannot receive on empty channel list!")
# Shuffle channels to avoid the first ones starving others of workers
random.shuffle(channels)
# Get a message from one of our channels
while True:
result = self.connection.blpop([self.prefix + channel for channel in channels], timeout=1)