Skip to content

stuck tasks that never complete when running on many SLURM nodes #5078

Closed

Description

@grapesmoker

I apologize in advance for not being able to provide a minimal working example. I hope it will be clear why that doesn't seem possible.

I'm running into an issue that running my job on a SLURM cluster. The job itself consists of a single function that takes several matrices, masks one with the other, and does a count of the values in the result; it gives the right answer and the function itself is not a problem. There are about 5,000,000 of these matrix pairs, so the context here is just the same function being executed in parallel many, many times. This seems to work fine when I have 4 nodes and run 32 workers per node with 4 threads per worker (each node has 1TB of RAM and 128 cores, and the function itself is not memory-intensive).

I start my scheduler locally on my workstation (which is on the same network as the cluster) by just running dask-scheduler and I start my workers by running:

srun dask-worker tcp://10.128.47.56:8786 --nthreads 4 --nprocs 32 --nanny --death-timeout 60 --protocol tcp://

The problem occurs when I try to increase the number of nodes, which I want to do because processing all these files takes a long time. So, let's say I acquire an allocation for 8 nodes instead of 4 and run my computations. At some point during the execution of the tasks I encounter the following message:

distributed.client - WARNING - Couldn't gather 1 keys, rescheduling {'compute_counts_distributed-b75da36f71347d615938c87aeaa86f0d': ('tcp://10.250.145.243:33063',)}

This message appears to be issued when the status of the task is given as "error" but I cannot locate any errors in the logs; the computations are all identical and there is even try/except in the function being called, so the error should not even surface even if there is one, but there's nothing there. If I navigate to the web interface and head over to "Info" I find the following:

Screen Shot 2021-07-15 at 9 11 14 PM

This worker (and there might be more than one, only one error popped up on this particular run) never completes its tasks. It just sits there and does nothing. Trying to call up the call stacks yield the message: Task not actively running. It may be finished or not yet started. The transition log for other queued tasks on this worker looks like the below:

Screen Shot 2021-07-15 at 9 04 19 PM

Once this happens, the following errors appear in the scheduler log:

distributed.scheduler - ERROR - Couldn't gather keys {'compute_counts_distributed-b75da36f71347d615938c87aeaa86f0d': ['tcp://10.250.145.243:33063']}
 state: ['memory'] workers: ['tcp://10.250.145.243:33063']
NoneType: None
distributed.scheduler - INFO - Remove worker <WorkerState 'tcp://10.250.145.243:33063', name: tcp://10.250.145.243:33063, memory: 1, processing: 15>
distributed.core - INFO - Removing comms to tcp://10.250.145.243:33063
distributed.scheduler - ERROR - Workers don't have promised key: ['tcp://10.250.145.243:33063'], compute_counts_distributed-b75da36f71347d615938c87a
eaa86f0d
NoneType: None
distributed.scheduler - INFO - Unexpected worker completed task, likely due to work stealing.  Expected: <WorkerState 'tcp://10.250.145.190:34085',
name: tcp://10.250.145.190:34085, memory: 6, processing: 11>, Got: <WorkerState 'tcp://10.250.145.243:33063', name: tcp://10.250.145.243:33063, memo
ry: 0, processing: 0>, Key: compute_counts_distributed-d8ca0dfdf1edc8361359cc8cc05d7748
distributed.scheduler - INFO - Unexpected worker completed task, likely due to work stealing.  Expected: <WorkerState 'tcp://10.250.145.191:35357',
name: tcp://10.250.145.191:35357, memory: 4, processing: 14>, Got: <WorkerState 'tcp://10.250.145.243:33063', name: tcp://10.250.145.243:33063, memo
ry: 0, processing: 0>, Key: compute_counts_distributed-b75da36f71347d615938c87aeaa86f0d
distributed.utils - ERROR - 'compute_counts_distributed-ef200fb6a8d6ec2828bc896fe8fe701b'
Traceback (most recent call last):
  File "/mnt/home/jvinokurov/Development/humanbase-pipeline/venv/lib/python3.7/site-packages/distributed/utils.py", line 638, in log_errors
    yield
  File "/mnt/home/jvinokurov/Development/humanbase-pipeline/venv/lib/python3.7/site-packages/distributed/scheduler.py", line 4115, in add_worker
    typename=types[key],
KeyError: 'compute_counts_distributed-ef200fb6a8d6ec2828bc896fe8fe701b'
distributed.core - ERROR - Exception while handling op register-worker
Traceback (most recent call last):
  File "/mnt/home/jvinokurov/Development/humanbase-pipeline/venv/lib/python3.7/site-packages/distributed/core.py", line 502, in handle_comm
    result = await result
  File "/mnt/home/jvinokurov/Development/humanbase-pipeline/venv/lib/python3.7/site-packages/distributed/scheduler.py", line 4115, in add_worker
    typename=types[key],
KeyError: 'compute_counts_distributed-ef200fb6a8d6ec2828bc896fe8fe701b'
distributed.scheduler - INFO - Unexpected worker completed task, likely due to work stealing.  Expected: <WorkerState 'tcp://10.250.145.190:32969', name: tcp://10.250.145.190:32969, memory: 4, processing: 9>, Got: <WorkerState 'tcp://10.250.145.243:33063', name: tcp://10.250.145.243:33063, memory: 0, processing: 8>, Key: compute_counts_distributed-ef200fb6a8d6ec2828bc896fe8fe701b
distributed.scheduler - INFO - Unexpected worker completed task, likely due to work stealing.  Expected: <WorkerState 'tcp://10.250.145.190:37861', name: tcp://10.250.145.190:37861, memory: 8, processing: 9>, Got: <WorkerState 'tcp://10.250.145.243:33063', name: tcp://10.250.145.243:33063, memory: 0, processing: 8>, Key: compute_counts_distributed-124990a80a23f8070e30232104d7e879
distributed.scheduler - INFO - Unexpected worker completed task, likely due to work stealing.  Expected: <WorkerState 'tcp://10.250.145.190:35819', name: tcp://10.250.145.190:35819, memory: 11, processing: 5>, Got: <WorkerState 'tcp://10.250.145.243:33063', name: tcp://10.250.145.243:33063, memory: 0, processing: 8>, Key: compute_counts_distributed-8232949c799c449c95798cca58a37789
distributed.scheduler - INFO - Unexpected worker completed task, likely due to work stealing.  Expected: <WorkerState 'tcp://10.250.145.191:35357', name: tcp://10.250.145.191:35357, memory: 15, processing: 2>, Got: <WorkerState 'tcp://10.250.145.243:33063', name: tcp://10.250.145.243:33063, memory: 0, processing: 8>, Key: compute_counts_distributed-9900c7d7207bcc08c9c014ed0ed57316
distributed.scheduler - INFO - Unexpected worker completed task, likely due to work stealing.  Expected: <WorkerState 'tcp://10.250.145.190:34419', name: tcp://10.250.145.190:34419, memory: 14, processing: 2>, Got: <WorkerState 'tcp://10.250.145.243:33063', name: tcp://10.250.145.243:33063, memory: 0, processing: 8>, Key: compute_counts_distributed-75d79e9ec100dd167cc2d5e8dd266460

Out of perhaps thousands of tasks, it seems that this happens a single-digit number of times. I find it hard to understand what is causing this error, outside some general notion that this is being caused by a race condition and is possibly related to work stealing. I have tried disabling work-stealing when running the scheduler, and I have also tried submitting the tasks via map rather than submit, but the error keeps cropping up. I have also tried setting the worker time-to-live to something reasonable so that the workers would get terminated and their tasks reassigned, but that doesn't seem to happen. Varying the number of workers and threads also does not help. The problem goes away again when I drop down to 4 nodes, which, alas, would take something on the order of a week to run, rather than a weekend.

Environment:

  • Dask version: 2021.7.0
  • Python version: 3.7
  • Operating System: Linux 64bit
  • Install method (conda, pip, source): pip

Activity

  1. grapesmoker commented on Jul 16, 2021

    @grapesmoker
    Author

    Brief addendum: I can kill the workers by setting the TTL (I realized after posting that I was setting the value incorrectly by making it a number rather than a string e.g. '15s') but this just ends up killing my job entirely and so is obviously not a good solution.

  2. fjetter commented on Jul 16, 2021

    @fjetter
    Member

    Thanks for the report. This indeed looks like a race condition. Does this happen towards or even at the very end of the computation?

    From what I understand so far

    1. Worker disconnects while scheduler is trying to gather data. The scheduler is typically only gathering data from workers if a future / computation result is requested by the client but the client cannot / is not allowed to connect to workers directly. This may be the case for the SLURM cluster, idk
    2. If this happens, the worker is typically removed from circulation but not closed. This should give the worker a chance to reconnect but allows the scheduler to deal with the possible situation that the worker in fact died. So far expected behaviour
    3. Worker tries to reconnect and while doing so, the KeyError is raised. This KeyError is a bit weird but I think I should be able to reconstruct this in a minimal example. Will need to try out
    4. This KeyError then effectively aborts the reconnect of the worker. the worker is waiting for a reply from the scheduler like "glad to have you back" or "we don't want your help anymore, please close" but that never happens due to the exception.
    5. The worker also never heartbeats anymore since it's stuck waiting for the schedulers reply which will never come. this is why the worker shows up red in the above screenshot.

    while all of this is not great and we'll need to fix it, I would expect the cluster to "recover" from this by rescheduling everything.

  3. grapesmoker commented on Jul 16, 2021

    @grapesmoker
    Author

    This seems to crop up near the beginning of the computation, although not in any consistent fashion. I would say that I typically see it within a minute of kicking off the job. As for connecting to workers directly, I don't believe SLURM imposes any restrictions on that, as it's only responsible for resource allocation.

  4. fjetter commented on Jul 19, 2021

    @fjetter
    Member

    Can you sketch out what kind of computations you are running? are you using a dask collection or plain futures? are you collecting results often?

  5. grapesmoker commented on Jul 20, 2021

    @grapesmoker
    Author

    Hi, sorry, I meant to respond earlier. I'll post the setup and the actual computation below.

    Here's the setup that submits all the tasks:

        for work_chunk in chunked(work, batch_size):
            futures = []
            for context_pair, data_pair in work_chunk:
                
                futures.append(client.submit(
                    grani_counts.compute_counts_distributed,
                    data_pair[0], data_pair[1],
                    context_pair[0], context_pair[1],
                    labels, retries=10
                ))
    
            for future, result in as_completed(futures, with_results=True):
                for dm_key, context_counts in result.items():
                    counts[dm_key].update(context_counts)

    The function compute_counts_distributed is what does the actual work. Here is that function:

    def compute_counts_distributed(data_matrix_file, data_positive_file,
                                   context_matrix_file, context_mask_file,
                                   labels):
    
        counts = defaultdict(dict)
    
        try:
            data_matrix = xr.open_dataarray(data_matrix_file, engine='h5netcdf')
            context_matrix = xr.open_dataarray(context_matrix_file, engine='h5netcdf')
            mask = xr.open_dataarray(context_mask_file, engine='h5netcdf')
            positives = xr.open_dataarray(data_positive_file, engine='h5netcdf')
        
            positives = positives.where(context_matrix).fillna(Coannotation.negative)
            negatives = data_matrix.where(mask == Coannotation.none).fillna(Coannotation.negative)
    
            pos_labels, pos_counts = np.unique(positives, return_counts=True)
            neg_labels, neg_counts = np.unique(negatives, return_counts=True)
    
            pos_counts = {int(k): int(v / 2) for k, v in zip(pos_labels, pos_counts) if int(k) >= 0}
            neg_counts = {int(k): int(v / 2) for k, v in zip(neg_labels, neg_counts) if int(k) >= 0}
    
            for label in labels:
                if label not in pos_counts:
                    pos_counts[int(label)] = 0
                if label not in neg_counts:
                    neg_counts[int(label)] = 0
    
            counts[data_matrix.name][context_matrix.name] = {'positives': pos_counts, 'negatives': neg_counts}
            
            return counts
        except Exception as ex:
            logger.error(f'could not compute counts for data {data_matrix_file} in context {context_matrix_file}: {ex}')
            return {}

    Here Coannotation is just an enum that is either 1, 0, or -1.

    As you can see, I collect the results after every batch_size has been processed; in my case I was setting it to 32768 (number chosen so as to be "large" and because each node has 128 cores, so that the node count divides the workload). And of course these are just plain futures, not dask collections.

  6. fjetter commented on Jul 20, 2021

    @fjetter
    Member

    Thanks for sharing.

    The for future, result in as_completed(futures, with_results=True): piece of the "controller code" is what I was looking for. This fetches the results of futures as soon as they are done which explains why we're seeing the error pop up in this section of the code.

    For "standard" / simple scheduling, this only happens at the very end, hence my question about result collection.

  7. fjetter commented on Aug 4, 2021

    @fjetter
    Member

    Closed by #5103

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