8000 Prefork: Use i % total to cycle between ready_fds instead of shuffle · alex-python/celery@f5086b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit f5086b3

Browse files
committed
Prefork: Use i % total to cycle between ready_fds instead of shuffle
1 parent bf53df7 commit f5086b3

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

celery/concurrency/asynpool.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,25 @@ def on_inqueue_close(fd, proc):
677677
pass
678678
self.on_inqueue_close< 8000 /span> = on_inqueue_close
679679

680-
def schedule_writes(ready_fds, shuffle=random.shuffle):
680+
def schedule_writes(ready_fds, shuffle=random.shuffle, curindex=[0]):
681681
# Schedule write operation to ready file descriptor.
682682
# The file descriptor is writeable, but that does not
683683
# mean the process is currently reading from the socket.
684684
# The socket is buffered so writeable simply means that
685685
# the buffer can accept at least 1 byte of data.
686-
shuffle(ready_fds)
687-
for ready_fd in ready_fds:
686+
687+
# This means we have to cycle between the ready fds.
688+
# the first version used shuffle, but using i % total
689+
# is about 30% faster with many processes. The latter
690+
# also shows more fairness in write stats when used with
691+
# many processes [XXX On OS X, this may vary depending
692+
# on event loop implementation (i.e select vs epoll), so
693+
# have to test further]
694+
total = len(ready_fds)
695+
696+
for i in range(total):
697+
ready_fd = ready_fds[curindex[0] % total]
698+
curindex[0] += 1
688699
if ready_fd in active_writes:
689700
# already writing to this fd
690701
continue

0 commit comments

Comments
 (0)
0