-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use in-memory notifications for workers #3247
base: master
Are you sure you want to change the base?
Conversation
os.close(fd) | ||
raise | ||
def __init__(self): | ||
self._val = multiprocessing.Value('d', lock=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if (in the O_TMPFILE and in the shm case) converting to floating point and back is needlessly weird.. We are reading the clock as a nanosecond-precision unsigned integer, are we not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
time.monotonic returns a float: https://docs.python.org/3/library/time.html#time.monotonic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By not using the _ns
variant we ask for it. No bug, just.. why ask for binary64 (@d
) to store uint64 (=Q
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'd' is a double floating point encoding, not binary64. I'm not sure what you mean by asking for it.
That is an implicit |
multiprocessing uses ctypes internally to expose shared memory as a Python object. It doesn't create any dependencies beyond the Python stdlib and any platform differences are handled within. |
The idea is good b ut I think there is a better way than using a shared value . We could instead use an atomic integer there. I will suggest an alternative asap. Let keep this PR open anyway yo compare the reult and safety. |
FWIW, I thought about using a sequence number but this was a more straightforward change, and I couldn't come up with a substantial enough reason it was better. Fewer calls to get the clock? |
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:
top 5 strace summary after: