File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -677,14 +677,25 @@ def on_inqueue_close(fd, proc):
677
677
pass
678
678
self .on_inqueue_close<
8000
/span> = on_inqueue_close
679
679
680
- def schedule_writes (ready_fds , shuffle = random .shuffle ):
680
+ def schedule_writes (ready_fds , shuffle = random .shuffle , curindex = [ 0 ] ):
681
681
# Schedule write operation to ready file descriptor.
682
682
# The file descriptor is writeable, but that does not
683
683
# mean the process is currently reading from the socket.
684
684
# The socket is buffered so writeable simply means that
685
685
# 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
688
699
if ready_fd in active_writes :
689
700
# already writing to this fd
690
701
continue
You can’t perform that action at this time.
0 commit comments