Repository navigation
Description
Hi!
Bringing this up here to get some feedback on how you think it should be handled - I'm happy to write a fix but obviously don't want to go in a direction that won't be accepted.
We are working in an adaptive-scaling environment, and are hitting a race condition where sometimes workers don't have what the scheduler thinks they have - and thus frees data that it shouldn't. After a lot of time spent tracing and digging, this is, I think what is happening:
- something (e.g. a client, or a future dependent task which is not yet eligible) needs
task1to be kept alive worker1computestask1(state:memory)worker2starts work on atask2which depends ontask1. It obtains the dependency from worker1, and tells the scheduler (ordistributed/distributed/worker.py
Line 1643 in 879cdb3
self.batched_stream.send({'op': 'add-keys', ) that it has it (this notification can be delayed, however).distributed/distributed/worker.py
Line 1226 in 879cdb3
self.batched_stream.send({'op': 'add-keys', - we try to scale the cluster down, and (for whatever reason) decide to close
worker1. The scheduler sees that bothworker1andworker2havetask1, and so does not make a copy anywhere else. worker1closes; scheduler now hastask1.who_has = {worker2}.worker2then completestask2, and frees the dependency (task1) (inrelease_dep), and tells the scheduler that it freed it (but again, this notification can be delayed)- when the notification arrives at the scheduler that
worker2has releasedtask1, it causes it to be recomputed (if it can be - iftask1was scattered data this would then be an error).
I added a log message to worker.py to see occurrences of these:
@@ -939,6 +939,13 @@ class Worker(ServerNode):
if k in self.actors:
from .actor import Actor
data[k] = Actor(type(self.actors[k]), self.address, k)
+ else:
+ logger.warning(
+ "peer %s asked me for key %s but I don't have it!",
+ str(comm.peer_address),
+ str(k))
+ for rel in [l for l in self.log if k in l]:
+ logger.warning("relevant log entry: %s", str(rel))
msg = {'status': 'OK',
'data': {k: to_serialize(v) for k, v in data.items()}}
leading to thousands of messages like (edited):
2018-12-15 15:31:26,180 46221:MainThread WARNING distributed.worker :: peer tcp://xxxx asked me for key YYY but I don't have it!
2018-12-15 15:31:26,182 46221:MainThread WARNING distributed.worker :: relevant log entry: ("YYY", 'new-dep', 'waiting')
2018-12-15 15:31:26,183 46221:MainThread WARNING distributed.worker :: relevant log entry: ('dep', "YYY", 'waiting', 'flight')
2018-12-15 15:31:26,184 46221:MainThread WARNING distributed.worker :: relevant log entry: ("YYY", 'release-dep')
As a test/fix I have commented out the lines linked above where the worker tells the scheduler that it has a task that it obtained as a dependency. Put another way, the worker does not tell the scheduler about tasks it has in memory, unless it plans to keep them.
@@ -1226,8 +1233,8 @@ class Worker(ServerNode):
if self.dependents[dep]:
self.dep_state[dep] = 'memory'
self.put_key_in_memory(dep, value)
- self.batched_stream.send({'op': 'add-keys',
- 'keys': [dep]})
+ #self.batched_stream.send({'op': 'add-keys',
+ # 'keys': [dep]})
else:
self.release_dep(dep)
@@ -1642,9 +1649,9 @@ class Worker(ServerNode):
self.log.append(('receive-dep', worker, list(response['data'])))
- if response['data']:
- self.batched_stream.send({'op': 'add-keys',
- 'keys': list(response['data'])})
+ #if response['data']:
+ # self.batched_stream.send({'op': 'add-keys',
+ # 'keys': list(response['data'])})
except EnvironmentError as e:
logger.exception("Worker stream died during communication: %s",
worker)
With this patch, the above errors are not triggered at all in a many-hours-long run.
Is that an acceptable solution to this problem? If not, what direction would you like the solution to take?
Activity
mrocklin commentedon Dec 17, 2018
I'll take a closer look at this tomorrow, but I wanted to quickly raise a question with this line:
My current understanding is that this doesn't happen. Instead, worker2 tells the scheduler that it has completed task2, the scheduler then makes a determination of whether or not worker2 should free task1. Given that a client wants this data I don't see why the scheduler would make this decision.
But, I haven't yet read through everything you've written (just making a cursory pass over things after getting home and before heading to bed).
Regardless, thank you for the effort to raise this cleanly and for the detailed explanation.
tjb900 commentedon Dec 17, 2018
Thanks for the reply @mrocklin . Indeed, I'm not yet 100% sure what precipitates the
release-dep- a task completing was just my natural assumption. I will take another look at the code and continue investigating.tjb900 commentedon Dec 17, 2018
OK... I see what you mean. I thought I had convinced myself that the worker was unilaterally releasing data that was only gathered due to a dependency, but I see that that's not the case.
I've tweaked some of the internal log entries so that the "relevant log entries" search works a little better. Does this sound more plausible?
worker2requests dependencytask1(log:request-dep) fortask2, taking it intoflightstategather_depyields intoget_data_from_worker, relinquishing control so other events can happentask2is released before it runs - the reason for this is something I am still chasing up, but it might have something to do with rescheduling/stealingrelease_key, the dependency is released because it is still in flightdistributed/distributed/worker.py
Line 1825 in 879cdb3
in_flight_tasksgather_depresumes,task1has arrived, and this is immediately reported to the scheduler here (distributed/distributed/worker.py
Line 1643 in 879cdb3
distributed/distributed/worker.py
Line 1667 in 879cdb3
in_flight_tasks/in_flight_workers.mrocklin commentedon Dec 17, 2018
Yes you're right, that does seems suspicious, and could lead to errors like you suggest.
There doesn't seem to be a yield between the
add-keysline and thetransition_dep(..., 'memory')line, so we should be able to move things around pretty easily. Is this a change you would be interesting in submitting?Also, I'm impressed at your ability to investigate the scheduling code. It's not an easy system to dive into :)
test for dask#2420
test for dask#2420
test for dask#2420
don't tell scheduler about data we don't plan to keep (fixes daskgh-2420
Revert "don't tell scheduler about data we don't plan to keep (fixes d…
jrbourbeau commentedon Jul 3, 2019
I've had users report coming across similar behavior. Namely a worker whose story for a particular key ends with a
"receive-dep"entry, but doesn't have a"put-in-memory"entry. Unfortunately, this behavior it's completely deterministic and constructing a test to reproduce the issue has been hard to come by.The proposed changes in #2421 are to remove
distributed/distributed/worker.py
Lines 1882 to 1885 in a511f0e
where the scheduler is informed the worker has keys before they are loaded into worker memory. With this change, informing the scheduler should take place after the keys have been loaded into memory when
transition_dep_flight_memoryis called. @mrocklin do you have any thoughts on the proposed changes? Does this seem like a reasonable path forward?