gunicorn
gunicorn copied to clipboard
Use in-memory notifications for workers
Changes the interprocess notifications for workers to use an in-memory multiprocessing.Value
instead of changing a filesystem timestamp, which requires interaction with the filesystem and can face contention issues or I/O related bottlenecks. The changed code doesn't require any platform-specific logic because it doesn't deal directly with any platform-related idiosyncrasies. multiprocessing.Value
uses shared memory under the hood in most cases so it is very efficient.
I ran a load test using "hey" against a gunicorn with a hello world app wrapped in strace -c
to measure the syscall impact.
top 5 strace summary before:
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
26.44 2.092495 20 100000 sendto
14.22 1.125266 20 53774 close
13.79 1.091552 6 160582 utimensat
11.78 0.931931 9 100001 getsockname
11.76 0.930716 8 105291 55291 accept4
top 5 strace summary after:
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
25.83 2.058187 20 100000 sendto
17.56 1.399223 20 67596 1 pselect6
14.53 1.157935 9 117570 67570 accept4
14.25 1.135567 22 50619 close
10.89 0.867693 8 100001 getsockname