Repository navigation
Description
I am trying to figure out how to handle the case of dask workers getting bumped from a cluster due to their requested allocation time expiring. From the intro YouTube video at https://www.youtube.com/watch?v=FXsgmwpRExM, it sounds like dask-jobqueue should detect when a worker expires and automatically start a replacement, which is what I want. However, my testing on DOE's edison computer at NERSC is not getting that behavior. If it matters, edison uses SLURM.
I have tried setting up my cluster two ways and both behave the same. I start a worker that uses dask.delayed to do a bunch of embarrassingly parallel tasks, the server spawns one worker, that worker does the first task or two, the worker expires, the server seems to hang, and nothing else happens.
The first approach I used to setup the cluster was with "scale":
cluster = SLURMCluster(cores=1, processes=1) # need all the memory for one task
cluster.scale(1) # testing with as simple as I can get, cycling 1 worker
client = Client(cluster, timeout='45s')
@josephhardinee suggested a 2nd approach using "adapt" instead:
cluster = SLURMCluster(cores=1, processes=1) # need all the memory for one task
cluster.adapt(minimum=1, maximum=1) # trying adapt instead of scale
client = Client(cluster, timeout='45s')
The dask-worker.err log concludes with:
slurmstepd: error: *** JOB 10234215 ON nid01242 CANCELLED AT 2018-08-10T13:25:30 DUE TO TIME LIMIT ***
distributed.dask_worker - INFO - Exiting on signal 15
distributed.nanny - INFO - Closing Nanny at 'tcp://10.128.4.227:35634'
distributed.dask_worker - INFO - Exiting on signal 15
distributed.dask_worker - INFO - End worker
distributed.process - WARNING - reaping stray process <ForkServerProcess(ForkServerProcess-1, started daemon)>
Am I expecting more from dask-jobqueue than I should? Or, is this a bug in my implementation or in dask.distributed of dask-jobqueue?
Thanks,
Bill
Activity
guillaumeeb commentedon Aug 11, 2018
Thanks for this really interesting test! I haven't encounter this yet, as I am currently only using dask for interactive analysis, and usually computations I launch have enough workers to end in a few minutes maximum.
However, I believe that, at least with adaptive cluster, for long running processes, workers should be restarted when allocation time expires. I will certainly need this in the near future. Currently, this is clearly not the case for non adaptive cluster. I cannot see anything in the code that would restart workers when a job ends. For adaptive, I don't know enough dask distributed code base yet, but the answer is probably there. Hopefully @mrocklin can answer this more easily.
I will try to reproduce your use case in my system newt week.
In any case, if this is not a bug of adaptive or our use of it, I think we should propose a solution here for having workers automatically restarted. Any advice @jhamman @mrocklin @lesteve ?
mrocklin commentedon Aug 12, 2018
What you're describing seems like it's in scope for dask-jobqueue, but it's not currently implemented. This could be resolved by recording a set desired number of workers and re-scaling whenever a worker goes away, which could probably be handled by the
remove_workermethod of theJobQueuePlugin(SchedulerPlugin)class.guillaumeeb commentedon Aug 13, 2018
So I take it adaptive clusters in distributed doesn't handle this either? Shouldn't it?
I had that in mind too, I'd be happy to work on it.
mrocklin commentedon Aug 13, 2018
mrocklin commentedon Aug 13, 2018
guillaumeeb commentedon Aug 13, 2018
So i've tried that with and without adaptive. As expected, without adaptive, once the worker is killed, nothing happens anymore.
With adaptive scaling, in my setup, a worker is restarted every time the previous one dies. Cool, that's what I want.
However, I'm still running into a difficult issue. Here is the code I use for some background:
The problem is, the worker is keeping all results into its memory for sending them all at once. But it gets killed half way every time. So we end up after several tries with the following exception:
mrocklin commentedon Aug 13, 2018
josephhardinee commentedon Aug 13, 2018
Out of curiosity, how does that work? I assume when a new worker needs to be started, a new jobscript has to be submitted. I assume that would need to be handled by jobqueue and not distributed?
guillaumeeb commentedon Aug 13, 2018
I don't exactly know how adaptive cluster is implemented in distributed, but the idea is that something is watching for dask cluster load, and calling scale method accordingly, for example if there are a lot more pending tasks than available workers.
Considering the issue here:
mrocklin commentedon Aug 13, 2018
FWIW the adaptive implementation is only 300 lines of code. It might be a good evening read if anyone is interested:
https://github.com/dask/distributed/blob/master/distributed/deploy/adaptive.py
I don't know. @jhamman might have thoughts. Alternatively maybe there is some way to change Adaptive to maintain a set target rather than move that target around.
It should be possible to run a single large graph with an evolving herd of workers, even if the workers don't live very long.
jhamman commentedon Aug 13, 2018
I think this is necessary to do this correctly. Ideally we could have a
Cluster.target_workersproperty. This property would be updated by bothCluster.scale()andAdaptive. My recent attempts to improve the adaptive scaling in jobqueue in #97 have highlighted the need for this.Another thing that would be worth discussing is the ability for Adaptive to query the Cluster for pending workers. This obviously comes up in jobqueue when there are jobs in a queue but I image this will also be useful to other dask deploy managers (dask-kubernetes, etc.).
wgustafson commentedon Aug 13, 2018
Sounds like you have a pretty good idea of my workflow scenario and some initial ideas on what might be needed to enable it to work predictably. Thanks for looking into this.
From @guillaumeeb it looks like there might be something going on with NERSC's edison computer compared to his cluster since I was not seeing any restarts, whereas he was getting restarts but with data passing issues. If you would like me to run any tests on edison, let me know.
guillaumeeb commentedon Aug 13, 2018
@wgustafson, it could still be useful if you could give us some simplified version of the code your trying to run, just to be sure.
For information, I've performed my tests with a dask-jobqueue installed from one of the latest commit in master branch, were you using this to, or did you just pip (or conda) installed the latest released package?
@jhamman just to be sure, appart from fixing some edge case issues detected with #97, you believe it will be a good idea to have automatic restart of finished jobs by default?
@mrocklin from my recent experiment here, I cannot see how it could be possible for now. Are in memory data backed up or transmitted in some way between workers? The simple workflow of submitting a group of independent tasks seems to show that you need to have at least workers that last enough time to process
nb_tasks / nb_workertasks. But I did not try with several workers, so this is just a guess.jhamman commentedon Aug 13, 2018
I was thinking this would only work when using
Adaptive. I think a non-adaptive job that dies due to a wall-clock expiration should stay dead.guillaumeeb commentedon Aug 14, 2018
Yep, I agree with you @jhamman, no reason to implement a more complex default behavior when most of the time this is not needed (and probably not what we want), and also when there is already a complex mechanism that answers the need.
So this works right now with
Adaptive, and you've also opened #112 to fix the edge cases.I let you open another issue for that part, and if you can provide some advantages it would have.
Now @wgustafson, lets try to solve your adaptive problem, and also to see if your workflow is compatible with dying and restarting workers.
62 remaining items
eXpensia commentedon Aug 29, 2019
Thanks for the answers, i'll check the extra parameters.
jni commentedon Oct 14, 2019
@lesteve I'm finally ready to work on this. =) My main issue is that I don't understand how to test everything locally. Does
dask-jobqueueprovide a way to create a "dummy" cluster/scheduler for testing purposes? ie I'd like to test submitting jobs on my machine without having to depend on my institutional SLURM cluster. Any pointers here would be highly appreciated!lesteve commentedon Oct 14, 2019
Great to hear that!
I think an excellent first step would be to have a minimal example to reproduce the original problem on a real cluster. This can be done independently of testing things locally.
About the dask-jobqueue testing infrastructure, we do have a docker-compose setup for some schedulers (SGE, PBS, SLURM) that you can run locally (and that is used for CI).
There is a bit of doc about that in https://jobqueue.dask.org/en/latest/develop.html#test-with-job-scheduler.
#324 might have some additional useful info as well.
PR to improve the doc about how to test locally and/or how to make it more prominent are more than welcome!
jni commentedon Oct 14, 2019
This should be sufficient for a reproducible example. I'm making it take 30min but it should be straightforward to reduce that... I just don't have a good sense of the overhead of launching a worker so I was reluctant to reduce it further. To reduce it:
rangecall infilenames = []to 4 * 60 * target duration (in mins)Everything else should be the same.
Here's my yaml config, though it probably doesn't need much of this:
To work around the issue with current
dask-jobqueue, you do:in the for-loop.
To fix the issue with the latest dask-distributed, when a dask-worker job gets submitted to the cluster, we should add
--lifetime=<value>where value is the walltime of the cluster worker, minus some small margin, e.g. 1min. This will make the dask scheduler not treat the death of that worker as suspicious. I think.adaptwill take care of launching a new worker. It's unclear to me whether--lifetime-staggeris something we should worry about at this point.Please let me know if the script above is sufficient to reproduce the issue for you!
lesteve commentedon Oct 15, 2019
Great thanks a lot for your input!
This is the snippet I am trying to run on my cluster SGE. I just launched it will tell you whether this reproduces or not.
There were are a few fixes I had to do (lines are indicated by
# FIXin the snippet below):30minutesrather than30min,list(enumerate)rather thanenumerateotherwise "TypeError: Dask no longer supports mapping over Iterators or Queues.Consider using a normal for loop and Client.submit")Error:
lesteve commentedon Oct 16, 2019
I can reproduce the problem indeed, which is a great start. I edited my earlier message with the error.
guillaumeeb commentedon May 10, 2020
Thanks to @willsALMANJ issue a few days ago, I tried the
--lifetimeoption and I confirm that it works perfectly with the latest Dask, Distributed and Jobqueue versions.The initial script I used (just reduced time):
It fails with a KilleWorkerException when the first 4 workers are killed due to walltime.
Just modify the cluster initialization:
And it works! I think it solves the problem here.
I think this would be valuable when scaling up with 100s of workers, at that point you don't want them all to stop at the same time.
I'll try to produce some documentation to explain all that and close this issue. The outline should look something like:
How to handle Job Queueing system walltime killing workers
Reaching walltime can be troublesome
If you don't set the proper parameters, you'll run into KilleWorker exceptions in thos two cases.
Use
--lifetimeworker option. This will enables infinite workloads using adaptive.Use
--lifetime-staggerwhen dealing with many workers.Examples
MatthewLennie commentedon Aug 25, 2020
@guillaumeeb Is this still current? It seems like there is an additional flag in the Worker CLI to trigger life time restarts --lifetime-restart. Even with the additional flag this doesn't seem to work for me.
guillaumeeb commentedon Aug 25, 2020
I just tested with dask and distributed 2.22.0 and jobqueue 0.7.1, and it works.
You don't want to use this flag in this case, or your jobs will never terminate normally, they will be killed by the job scheduler due to walltime. What you want is your jobs ending before the walltime limit, so only
--lifetime.Did you tested this with the code above, or your own code?
riedel commentedon Oct 11, 2020
What is the correct way to evict a job from the schedulers point of view? Is SIGTERM enough for a worker to correctly terminate and transfer its memory, after dask/distributed#2844 gets merged?
Does gracefull shutdown mean, that memory gets moved?
I agree that workers ideally terminate one after another, there should be a way to spin up replacements well in time or choose staggered walltimes, since my problem was that all workers had approximately the same wall time and there would have been no way to gracefully handle the situation. What is the current policy here and what would be a sensible policy? It does not make sense to transfer memory and tasks to the worker that dies next I guess. What would be the idea how to handle it?
It seems to me that adapt could have the tendency to kill the youngest jobs first, since they do not carry too much data. Will specifying lifetime take care of this? Or is this implicitely handled by adapt, because an empty new worker is spun up, that is an ideal target?
guillaumeeb commentedon Jan 23, 2021
@riedel sorry for the delay...
Just submitted a merge request to clarify things here and close this issue.
From Dask-jobqueue perspective, just use
--lifetimeoption as explained above. This will trigger a gracefull shutdown.Use
--lifetime-staggeroption.Hmm, I guess there is no correct answer to this right now. The solution here probably won't work well on worker with a heavy memory load.
I don't think that. The first started worker will be killed first (with some uncertainties due to
--lifetime-stagger). But here we've got no choice, this is a job queueing system walltime problem, these workers would be killed anyway.Not handled by adapt, but I guess the Scheduler has some logics on reafecting tasks and memory, and it will probably aim the youngest and free workers for this.