Skip to content

Dask hangs in random moment, hard to reproduce #2866

Closed

Description

@michcio1234

I have quite a big dask graph to compute. It operates on multiple parquet files from s3, processes the data and saves the result to local disk. The problem is, the process can stop in a random moment.
I'm not sure what causes it, so I don't know if I should submit the issue here or in distributed repo.

Setup:

  • AWS EC2 machine with 64 cores and 500 GB of RAM

  • docker container running dask-scheduler

  • docker container running dask-worker [scheduler-address] --nprocs 64 --memory-limit 0.3

  • docker container running python code, connecting to the scheduler

  • Python 3.5

  • dask 0.15.2 (same thing happens with newer version)

  • distributed 1.18.3 (same thing happens with newer version)

  • tornado 4.5.2

  • fastparquet 0.1.2

When the computation starts, I can see progress bars in scheduler dashboard. Everything seems to be fine, tasks are being computed, until suddenly everything stops. CPU usage drops to almost zero, progress bars stop, worker's bokeh page stops responding. When I restart the whole process, it will most probably stop again, but in totally different moment. I couldn't find any rule on when the progress stops.

I would love to include a minimum example, but I have no idea what causes this behaviour. As I said, it may happen in different moments, so I can't even tell whether it's beginning or end of my pipeline. So, I don't know how to reproduce it.

I tried looking at logs. When the computations stop, there's no sign of anything going wrong either in worker or scheduler. After almost 1 hour of doing nothing, last lines from worker and scheduler look like this:

dask-scheduler    | 2017-11-05T18:16:56.929566066Z distributed.scheduler - INFO - Starting worker compute stream, tcp://172.19.0.4:37075
dask-scheduler    | 2017-11-05T18:16:56.932564278Z distributed.scheduler - INFO - Register tcp://172.19.0.4:58982
dask-scheduler    | 2017-11-05T18:16:56.933666514Z distributed.scheduler - INFO - Register tcp://172.19.0.4:41864
dask-scheduler    | 2017-11-05T18:16:56.935390112Z distributed.scheduler - INFO - Register tcp://172.19.0.4:57315
dask-scheduler    | 2017-11-05T18:16:56.937407410Z distributed.scheduler - INFO - Register tcp://172.19.0.4:33051
dask-scheduler    | 2017-11-05T18:16:56.939018686Z distributed.scheduler - INFO - Register tcp://172.19.0.4:39833
dask-scheduler    | 2017-11-05T18:16:56.940121438Z distributed.scheduler - INFO - Register tcp://172.19.0.4:59492
dask-scheduler    | 2017-11-05T18:16:56.940805054Z distributed.scheduler - INFO - Starting worker compute stream, tcp://172.19.0.4:58982
dask-scheduler    | 2017-11-05T18:16:56.941496080Z distributed.scheduler - INFO - Starting worker compute stream, tcp://172.19.0.4:41864
dask-scheduler    | 2017-11-05T18:16:56.941522107Z distributed.scheduler - INFO - Starting worker compute stream, tcp://172.19.0.4:57315
dask-scheduler    | 2017-11-05T18:16:56.942195523Z distributed.scheduler - INFO - Starting worker compute stream, tcp://172.19.0.4:59492
dask-scheduler    | 2017-11-05T18:16:56.942201960Z distributed.scheduler - INFO - Starting worker compute stream, tcp://172.19.0.4:33051
dask-scheduler    | 2017-11-05T18:16:56.942719202Z distributed.scheduler - INFO - Starting worker compute stream, tcp://172.19.0.4:39833
dask-scheduler    | 2017-11-05T18:16:56.951637056Z distributed.scheduler - INFO - Register tcp://172.19.0.4:38661
dask-scheduler    | 2017-11-05T18:16:56.952947498Z distributed.scheduler - INFO - Starting worker compute stream, tcp://172.19.0.4:38661
dask-scheduler    | 2017-11-05T18:16:56.957188880Z distributed.scheduler - INFO - Register tcp://172.19.0.4:40078
dask-scheduler    | 2017-11-05T18:16:56.958534533Z distributed.scheduler - INFO - Starting worker compute stream, tcp://172.19.0.4:40078
dask-scheduler    | 2017-11-05T18:16:57.202564703Z distributed.scheduler - INFO - Receive client connection: Client-82484af4-c255-11e7-8082-0242ac130005
dask-scheduler    | 2017-11-05T18:19:44.344417691Z distributed.core - WARNING - Event loop was unresponsive for 1.05s.  This is often caused by long-running GIL-holding functions or moving large chunks of data. This can cause timeouts and instability.
dask-scheduler    | 2017-11-05T18:20:08.078638857Z distributed.core - WARNING - Event loop was unresponsive for 23.08s.  This is often caused by long-running GIL-holding functions or moving large chunks of data. This can cause timeouts and instability.
dask-worker_1     | 2017-11-05T18:21:32.362563969Z distributed.worker - DEBUG - future state: ('read-parquet-b2c5abe77c11876195eb6a77738d1492', 19) - RUNNING
dask-worker_1     | 2017-11-05T18:21:32.362579815Z distributed.worker - DEBUG - Execute key: ('concat-7075105cf1c6acffe24d76c23229da72', 4361) worker: tcp://172.19.0.4:53559
dask-worker_1     | 2017-11-05T18:21:32.393695151Z distributed.worker - DEBUG - Deleted 1 keys
dask-worker_1     | 2017-11-05T18:21:32.394078549Z distributed.worker - DEBUG - Deleted 1 keys
dask-worker_1     | 2017-11-05T18:21:32.394140791Z distributed.worker - DEBUG - Send compute response to scheduler: ('dropna-de531fe104bb0718a633ac3ba57e44c9', 4505), {'thread': 140187946239744, 'status': 'OK', 'op': 'task-finished', 'type': <class 'pandas.core.frame.DataFrame'>, 'key': "('dropna-de531fe104bb0718a633ac3ba57e44c9', 4505)", 'stop': 1509906092.38893, 'start': 1509906091.7096455, 'nbytes': 347313008}
dask-worker_1     | 2017-11-05T18:21:32.395095639Z distributed.worker - DEBUG - Execute key: ('astype-fa084f475d61990b4586d370bacd818e', 4324) worker: tcp://172.19.0.4:44932
dask-worker_1     | 2017-11-05T18:21:32.401399080Z distributed.worker - DEBUG - Send compute response to scheduler: ('assign-1d9eb7afe69be0e3579b6a8be9c6b291', 4455), {'thread': 140187945977600, 'status': 'OK', 'op': 'task-finished', 'type': <class 'pandas.core.frame.DataFrame'>, 'key': "('assign-1d9eb7afe69be0e3579b6a8be9c6b291', 4455)", 'stop': 1509906092.3977563, 'start': 1509906092.1396115, 'nbytes': 322818495}
dask-worker_1     | 2017-11-05T18:21:32.402049239Z distributed.worker - DEBUG - Execute key: ('astype-fa084f475d61990b4586d370bacd818e', 4398) worker: tcp://172.19.0.4:59993
dask-worker_1     | 2017-11-05T18:21:32.431883216Z distributed.worker - DEBUG - Send compute response to scheduler: ('read-parquet-b2c5abe77c11876195eb6a77738d1492', 19), {'thread': 140187923695360, 'status': 'OK', 'op': 'task-finished', 'type': <class 'pandas.core.frame.DataFrame'>, 'key': "('read-parquet-b2c5abe77c11876195eb6a77738d1492', 19)", 'stop': 1509906092.4114537, 'start': 1509906079.2736945, 'nbytes': 365677731}
dask-worker_1     | 2017-11-05T18:21:32.433350396Z distributed.worker - DEBUG - Execute key: ('astype-867f8e9773a47c02dc913a3001779e23', 4419) worker: tcp://172.19.0.4:47891
dask-worker_1     | 2017-11-05T18:21:32.433365801Z distributed.worker - DEBUG - Send compute response to scheduler: ('astype-955e0ccfc224ca95aa0211b2986fc390', 4434), {'thread': 140187922646784, 'status': 'OK', 'op': 'task-finished', 'type': <class 'pandas.core.series.Series'>, 'key': "('astype-955e0ccfc224ca95aa0211b2986fc390', 4434)", 'stop': 1509906092.4325304, 'start': 1509906092.3020687, 'nbytes': 4140533}
dask-worker_1     | 2017-11-05T18:21:32.434231696Z distributed.worker - DEBUG - Execute key: ('getitem-936f98cb941dae846251947cdf358006', 4388) worker: tcp://172.19.0.4:38661
dask-worker_1     | 2017-11-05T18:21:32.435753372Z distributed.worker - DEBUG - Send compute response to scheduler: ('getitem-936f98cb941dae846251947cdf358006', 4388), {'thread': 140187922646784, 'status': 'OK', 'op': 'task-finished', 'type': <class 'pandas.core.series.Series'>, 'key': "('getitem-936f98cb941dae846251947cdf358006', 4388)", 'stop': 1509906092.4348502, 'start': 1509906092.4345806, 'nbytes': 56286028}
dask-worker_1     | 2017-11-05T18:21:32.436108651Z distributed.worker - DEBUG - Execute key: ('assign-7e08af70bcc5505618642c0209ce5970', 4339) worker: tcp://172.19.0.4:38661
dask-worker_1     | 2017-11-05T18:21:32.438114434Z distributed.worker - DEBUG - Deleted 1 keys
dask-worker_1     | 2017-11-05T18:21:32.456848909Z distributed.worker - DEBUG - Send compute response to scheduler: ('concat-7075105cf1c6acffe24d76c23229da72', 4273), {'thread': 140187923957504, 'status': 'OK', 'op': 'task-finished', 'type': <class 'pandas.core.frame.DataFrame'>, 'key': "('concat-7075105cf1c6acffe24d76c23229da72', 4273)", 'stop': 1509906092.3513696, 'start': 1509906092.1742594, 'nbytes': 362452000}
dask-worker_1     | 2017-11-05T18:21:32.458012439Z distributed.worker - DEBUG - Execute key: ('getitem-8e7fcdbbeeef95f9da75ec0adbd9adc3', 4477) worker: tcp://172.19.0.4:48040
dask-worker_1     | 2017-11-05T18:21:32.458026177Z distributed.worker - DEBUG - future state: ('read-parquet-248809b98a4a58f4cebbf22d9fc05dfe', 47) - RUNNING
dask-worker_1     | 2017-11-05T18:21:32.461667639Z distributed.worker - DEBUG - Send compute response to scheduler: ('getitem-8e7fcdbbeeef95f9da75ec0adbd9adc3', 4477), {'thread': 140187923957504, 'status': 'OK', 'op': 'task-finished', 'type': <class 'pandas.core.series.Series'>, 'key': "('getitem-8e7fcdbbeeef95f9da75ec0adbd9adc3', 4477)", 'stop': 1509906092.4587786, 'start': 1509906092.458351, 'nbytes': 35910430}
dask-worker_1     | 2017-11-05T18:21:32.462353208Z distributed.worker - DEBUG - Execute key: ('concat-7075105cf1c6acffe24d76c23229da72', 4422) worker: tcp://172.19.0.4:48040

Here you can see the whole logs:
worker.log
scheduler.log

After I kill the client, following lines appear:
worker_clientKilled.log
scheduler_clientKilled.log

Output from the client is like:

distributed.comm.tcp - DEBUG - Setting TCP keepalive: nprobes=10, idle=10, interval=2
distributed.comm.tcp - DEBUG - Setting TCP user timeout: 30000 ms
distributed.comm.tcp - DEBUG - Setting TCP keepalive: nprobes=10, idle=10, interval=2
distributed.comm.tcp - DEBUG - Setting TCP user timeout: 30000 ms
distributed.client - DEBUG - Started scheduling coroutines. Synchronized
distributed.client - DEBUG - Waiting on futures to clear before gather
<here it hangs forever and I have to kill it>

I will be grateful for any help with debugging this issue.

Activity

  1. mrocklin commented on Nov 6, 2017

    @mrocklin
    Member

    2017-11-05T18:20:08.078638857Z distributed.core - WARNING - Event loop was unresponsive for 23.08s. This is often caused by long-running GIL-holding functions or moving large chunks of data. This can cause timeouts and instability.

    This is odd. My first guess would be that you're trying to move a large amount of data from workers to the client, such as might be caused by calling df.compute() on a very large result.

    Alternatively, you might want to check the memory and CPU use of the scheduler to make sure that it isn't becoming overwhelmed. This is available on the System tab of the diagnostic dashboard.

  2. michcio1234 commented on Nov 6, 2017

    @michcio1234
    Author

    Thank you for your response.
    All docker containers run on the same machine. CPU and memory usage of this machine are low when this happens.
    Very large result may be the case here, but I guess it's not the problem, as today I got the same issue on a much smaller dataframe.

  3. mrocklin commented on Nov 6, 2017

    @mrocklin
    Member

    Something is causing the scheduler to become unresponsive for 20 seconds. All the scheduler does is accept messages and pass bytes around.

    Another option is if your graph were well above a million tasks large then I can imagine it slowing down while waiting setting up the new tasks, but even in that case I would expect the hang to occur before execution began. Other than that no common causes come to mind.

  4. mrocklin commented on Nov 6, 2017

    @mrocklin
    Member

    Although as always if you're able to provide a simple reproducible example that is similar to your problem then it becomes much easier to diagnose things. I appreciate that this can be quite challenging to produce though.

  5. caseyjlaw commented on Nov 13, 2017

    @caseyjlaw

    FWIW, I have seen behavior like this when I misconfigure the memory limit of my worker. In my case, I had a heterogeneous cluster, but set the memory limit to the largest value available over all workers.

  6. michcio1234 commented on Nov 14, 2017

    @michcio1234
    Author

    Thank you @caseyjlaw for your comment. I specify memory limit as fraction and tried to lower it to avoid memory errors.
    It's a bit unclear to me: is --memory-limit set per process? If I have --nprocs 10, should I also set --memory-limit 0.1?

  7. caseyjlaw commented on Nov 14, 2017

    @caseyjlaw

    I've been a bit unclear on this, too. It is set per worker and the worker can have multiple cores. But it isn't clear how to me how the scheduler considers memory per core.

  8. michcio1234 commented on Nov 15, 2017

    @michcio1234
    Author

    To give some more light on the issue, it doesn't seem to happen when I use LocalCluster instead of scheduler and worker in different docker containers.

  9. mrocklin commented on Nov 15, 2017

    @mrocklin
    Member

    --memory-limit does get divided per process.

    FWIW in production I rarely use the --nprocs keyword just to avoid ambiguities like this. Instead I typically start many dask-worker processes. There is no performance change here, I just find it to be simpler overall.

  10. caseyjlaw commented on Nov 15, 2017

    @caseyjlaw

    I've migrated toward using the "resources" argument to manage memory available to submitted tasks. It seemed like the standard memory estimationt of some of my tasks were too low. (I can't reproduce it well enough to submit an issue.)
    Caveat: My work flow uses lots of numba, numpy, and other GIL-releasing functions, so threading works well for me.

  11. ebo commented on Apr 10, 2018

    @ebo

    I've bumped into this again also. At first I thought I was doing something stupid, but now I am beginning to think there is something amiss...

    The following code:

    from dask.distributed import Client
    client = Client(memory_limit=4e9, processes=False)
    client
    with rasterio.open(infile, 'r') as src:
        with rasterio.open(outfile, 'w', **src.profile) as dst:
                for i in range(src.count):
                    dst.write(ds.variable.data[i].compute(), i+1)
    

    Which is a little contrived, but has the structure of a per-band process I will need to deal with later. While it is computing, I get the following errors rather consistently:

    /home/jldavid3/anaconda3/envs/pangeo/lib/python3.6/site-packages/rasterio/init.py:160: FutureWarning: GDAL-style transforms are deprecated and will not be supported in Rasterio 1.0.
    transform = guard_transform(transform)
    distributed.core - WARNING - Event loop was unresponsive in Scheduler for 3.10s. This is often caused by long-running GIL-holding functions or moving large chunks of data. This can cause timeouts and instability.
    distributed.core - WARNING - Event loop was unresponsive in Worker for 3.11s. This is often caused by long-running GIL-holding functions or moving large chunks of data. This can cause timeouts and instability.

    Oddly enough, I get slightly different number of errors every time I run, and sometimes I get other errors such as:

    /home/jldavid3/anaconda3/envs/pangeo/lib/python3.6/site-packages/bokeh/core/json_encoder.py:80: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.

    but I do not get these all the time. I also tried replacing "compute" with "persist", and I get the same behavio just later..

    I will try upgrading, rebooting and starting everything out clean and see if this persists.

  12. mrocklin commented on Apr 12, 2018

    @mrocklin
    Member

    Those are just warnings. Things should evaluate fine.

    Do we know if rasterio releases the GIL? It might be worth asking upstream.

  13. mrocklin commented on Oct 24, 2018

    @mrocklin
    Member

    Conversation seems to have died here so I'm going to close. Happy to reopen if things start up again.

    For others who come along, some common causes for an unresponsive cluster:

    1. Your software versions are mismatched
    2. You are sending a lot of data in the task graph itself. It's always wiser to load data as part of a task, rather than to include large local objects directly in function calls.
    3. Your own code has some sort of deadlock in it unrelated to dask

    Common things you can do to check what is wrong

    1. call client.get_versions(check=True)
    2. Look at the dashboard to see how workers are doing
    3. Look at the call stacks of your worker threads to see what they're spending time on with client.call_stack()
  14. rainwoodman commented on Dec 13, 2018

    @rainwoodman
    Contributor

    I ran into random hangs too; but my case was pretty clear what is happening:

    • dask pauses worker under memory pressure.
    • there is only one active worker with remaining work and it is under memory pressure.

    I am not sure how to recover from this. I tried to kill the hanging worker but it seems to fail my entire job calculation. Would be nice if the scheduler knows how to kill a hanging worker and reschedule the jobs.

    I suspect the problem is because one of the library I use has pretty bad leaks; even when dask reports there is nothing in memory, the worker's memory usage is still huge after a task graph is computed.

  15. rainwoodman commented on Dec 13, 2018

    @rainwoodman
    Contributor

    Here is why. I have two types of tasks: compute and IO-write. IO-write tasks are much slower than compute tasks. each compute task is followed by an IO-write task. There is no dependence between different IO-write task / compute tasks.

    dask tries to hold the result from the computing tasks in memory as it runs through as many of them quickly. It then realizes memory is used up, and dask pauses the workers. Sometimes the memory is used up so quickly that before the work actually pauses, it already uses too much memory and the scheduler starts to issue kills.

    The IO-write tasks, which reduces memory usage never gets called because

    The scheduler should prioritize tasks that depend on objects that reduces memory usage. I suppose there is no easy way to notify the scheduler a task will reduce memory usage. Perhaps I can fiddle with the priority of the IO tasks.

  16. rainwoodman commented on Dec 13, 2018

    @rainwoodman
    Contributor

    dask.compute(priority=10) does not seem to set the priority of the tasks:

    From the web interface I still see those jobs set with priority of -10 : (-10, 1, 35)

  17. rainwoodman commented on Dec 14, 2018

    @rainwoodman
    Contributor

    Since an entire graph is submitted by dask.compute(), specifying the priority with dask.compute() will not help: IO and compute are on the same graph, and receive the same priority.

    I suggest we add a way of controlling priority of dask objects as they are created, e.g.

    da.from_array(...., priority=-10) # reading gets the lowest priority
    da.map_blocks(..., priority=10) # writing gets the highest priority
    
  18. mrocklin commented on Dec 18, 2018

    @mrocklin
    Member
  19. rainwoodman commented on Dec 19, 2018

    @rainwoodman
    Contributor
  20. rusiano commented on Jul 17, 2019

    @rusiano

    I am experiencing the very same issue and I do not understand how can i solve it.

    Just to give a bit of context: I have a big file in S3 that I already partitioned in 500 .csv.gz files of size around 1MB (compressed). Now I have a transformation function that given an integer loads the i-th partition in memory in a pandas.DataFrame, transforms it and then writes it at a new location in S3 (using boto3), in chunks of 10e4 rows at a time (so the I/O is within the function, it is not a separate task). It returns 0 if everything is ok, -1 otherwise. I am running it on an AWS EC2 instance with 4 cores with 64GB RAM.

    Since each partition is independent from the others, I use dask to parallelize their transformation.
    Now the code looks a bit like:

    with Client() as client:
        tran_ops = [dask.delayed(func)(i) for i in range(500)]
        tran_op = client.compute(dask.delayed(sum)(tran_ops))
        if client.gather(tran_op) != 0:
            print('nay')
        else:
            print('yay')
    

    I also tried to split the 500-items list in sub-lists of 100 elements and compute them consecutively like so

    for j in range(5):
        start = j*100
        stop = start + 100
        tran_ops = [dask.delayed(func)(i) for i in range(start, stop)]
        tran_op = client.compute(dask.delayed(sum)(tran_ops))
        if client.gather(tran_op) != 0:
            print('nay')
            break
        print('yay')
    

    In both cases transformation hangs for 2 hours giving no sign of life whatsoever and then resumes normally and completes the transformation with no errors. Funny enough, in the former scenario the transformation goes on for around 25mins and transforms around 60-80% of the partitions before the break and the remaining 40-20% after; in the latter the transformation interrupts after 10mins when only 10-20% of the partitions have been processed and then goes on with the remaining 90-80% without further breaks.

    I understand that this may be due to GIL-holding functions and processing of large chunks of data but:

    • I have not very clear what GIL really is and which will be the GIL-holding function here; I read that pandas, numpy, etc. release the GIL, so maybe boto3?
    • large chunk is like saying big data, what's big here?
  21. rainwoodman commented on Jul 19, 2019

    @rainwoodman
    Contributor
  22. rusiano commented on Jul 19, 2019

    @rusiano

    No. When I monitored the whole process through the UI it executed 473 tasks before interrupting and it happened that only one worker got stucked when it had 27 task left, while the others went on with theirs until they finished.
    Speaking about the color, I saw the bars turning red-ish (I say "ish" because I use a dark theme that slightly changes the color) when they where about to finish, like with 5 tasks left or less, while the one that got stucked I remember it being coloured in green. However, I do not remember if the other workers have been green for a while, too (for example when having less than 50 tasks).

  23. chrisroat commented on Dec 23, 2020

    @chrisroat
    Contributor

    I have often had similar bogdown issues, with the scheduler giving GIL warnings. I'm using dask-gateway and launched two graphs of ~10k tasks each. The bulk of the processing that its currently doing are ~4k tasks that take 5-10 minutes each. Not a lot for the scheduler to do! But still the scheduler ie pegged 100% cpu! The memory is at 1.9GiB, bandwidth at ~2MiB/s, and # file descriptors at ~1900. The logs are littered with "Event loop was unresponsive in Scheduler for 5.04s. This is often caused by long-running GIL-holding functions or moving large chunks of data. This can cause timeouts and instability.".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions