You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Keep alive for inactive worker/scheduler connection #2524
I noticed that the connection between workers and schedulers (and effectively all Server subclasses using handle_stream) are kept open to continuously listen to incoming requests. This connection is solely used to listen to stream_handler requests while, for instance the heartbeat, uses a different connection from the connection pool. This means that for a longer time of cluster inactivity, the primary connection is inactive. The issue about inactive connections is that some external tools are inclined to kill inactive connections (for instance, we're using haproxy and we kill inactive connections after 1h) which requires for the worker to reconnect and register with the scheduler every hour during inactivity.
I was wondering if this is an issue for somebody else and whether it would be desired to either send a keep alive using the open connection every X secs (simple message to keep the connection active) or even send the hearbeat over this connection. I believe the first option could be implemented fairly easily in handle_stream while the latter is a bit more difficult. In either case I wanted to get some feedback before implementing anything.
(dedicated worker-scheduler connection creation see here, reconnect if connection is broken see here)
Thank you for the excellently worded issue, and my apologies for the delay in response.
I'm hearing two possible solutions:
Move the heartbeat to the long-running connection.
I suspect that the current reason for the heartbeat to be on a separate connection is to trigger a reconnect if something goes wrong with the long-running connection. However, as you point out in Race condition between worker heartbeat and reconnect #2525 we're already handling this, so perhaps this reason is not sufficient (or in fact, problematic).
If so then moving the heartbeat to the long-running connection seems like a good idea
Add a second keep-alive route to the server (probably in the handlers in core.py::Server) and add a periodic callback that sends a message every minute or so. This is easy to do and has low impact, but slightly increases complexity.
Either is fine. If you were interested and have the time to investigate option 1 I think that that would be best, but it's also more work.
We could solve this by moving the heartbeat as suggested, but it seems like this might have other effects?
As an alternative, maybe just a periodic callback that sends a trivial message across every minute or so? We could make a new route that did nothing and send an operation that just hits that route.
Activity
mrocklin commentedon Feb 20, 2019
Thank you for the excellently worded issue, and my apologies for the delay in response.
I'm hearing two possible solutions:
Move the heartbeat to the long-running connection.
I suspect that the current reason for the heartbeat to be on a separate connection is to trigger a reconnect if something goes wrong with the long-running connection. However, as you point out in Race condition between worker heartbeat and reconnect #2525 we're already handling this, so perhaps this reason is not sufficient (or in fact, problematic).
If so then moving the heartbeat to the long-running connection seems like a good idea
Add a second keep-alive route to the server (probably in the handlers in
core.py::Server) and add a periodic callback that sends a message every minute or so. This is easy to do and has low impact, but slightly increases complexity.Either is fine. If you were interested and have the time to investigate option 1 I think that that would be best, but it's also more work.
lr4d commentedon Jul 16, 2019
I've been taking a look at the codebase and I found this function
distributed/distributed/comm/tcp.py
Line 47 in 0a5b8da
Hence, it seems like TCP keep-alives should already be enabled on scheduler-worker connections.
Is there anything I may be missing here?
lr4d commentedon Jul 16, 2019
I have confirmed TCP keep-alives are being sent on the long running connection by looking at the TCP traffic when the heartbeat is disabled.
The scheduler is at
tcp://172.22.0.2:8786:StephanErb commentedon Jul 17, 2019
Sending TCP keep-alives will ensure that firewalls and networking equipment does not close the Dask connection. HAProxy however will close the connection if there is no traffic on the application layer, so even with TCP keep-alives it will close the connection (https://stackoverflow.com/questions/32634980/haproxy-closes-long-living-tcp-connections-ignoring-tcp-keepalive).
The proposal of Matthew to move the heartbeat to the long-running connection sounds sane and should solve this problem.
lr4d commentedon Jul 17, 2019
thanks @StephanErb
mrocklin commentedon Jul 29, 2019
We could solve this by moving the heartbeat as suggested, but it seems like this might have other effects?
As an alternative, maybe just a periodic callback that sends a trivial message across every minute or so? We could make a new route that did nothing and send an operation that just hits that route.
Add keep-alive message between worker and scheduler
mrocklin commentedon Jul 29, 2019
Would this work? #2907
Add keep-alive message between worker and scheduler (#2907)