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
Computation deadlocks due to worker rapidly running out of memory instead of spilling #6110
We could confirm that version 2022.1.1 is not affected by this but it appears that all follow up versions might be affected (haven't tested all of them, can definitely confirm for 2022.4.0)
On Tue, Apr 12, 2022 at 10:20 AM Florian Jetter ***@***.***> wrote:
The below script is pretty reliably triggering deadlocks. I'm sure this
can be reduced further but I haven't had time to do so, yet.
import coiled.v2from distributed import Clientcluster = coiled.v2.Cluster(
n_workers=20
)client = Client(cluster)
from distributed import Clientfrom dask.datasets import timeseriesddf = timeseries(
"2020",
"2025",
partition_freq='2w',
)ddf2 = timeseries(
"2020",
"2023",
partition_freq='2w',
)def slowident(df):
import random
import time
time.sleep(random.randint(1, 5))
return df
while True:
client.restart()
demo1 = ddf.map_partitions(slowident)
(demo1.x + demo1.y).mean().compute()
demo2 = ddf.merge(ddf2)
demo2 = demo2.map_partitions(slowident)
(demo2.x + demo2.y).mean().compute()
We could confirm that version 2022.1.1 is *not* affected by this but it
appears that all follow up versions might be affected (haven't tested all
of them, can definitely confirm for 2022.4.0)
—
Reply to this email directly, view it on GitHub
<#6110>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACKZTEFDNKXA5XGISTMBPLVEWIDNANCNFSM5THVRWOQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
I'm currently trying to run this locally without Coiled. I encourage other folks to hop on as well, but I'll at least try to run with this for the rest of the day when I have free time.
I'm also curious about how often this fails. Currently running this locally and not running into anything. I'm wondering how long I should wait before moving up to Coiled.
I'm getting these when running locally, but I suspect that they're due to being unclean on restart
Traceback
Future exception was never retrieved
future: <Future finished exception=CommClosedError("Exception while trying to call remote method 'restart' before comm was established.")>
Traceback (most recent call last):
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 226, in read
frames_nbytes =await stream.read_bytes(fmt_size)
tornado.iostream.StreamClosedError: Stream is closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 864, in send_recv_from_rpc
result =await send_recv(comm=comm, op=key, **kwargs)
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 709, in send_recv
response =await comm.read(deserializers=deserializers)
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 242, in read
convert_stream_closed_error(self, e)
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 150, in convert_stream_closed_errorraise CommClosedError(f"in {obj}: {exc}") from exc
distributed.comm.core.CommClosedError: in <TCP (closed) rpc.restart local=tcp://127.0.0.1:51626 remote=tcp://127.0.0.1:33741>: Stream is closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mrocklin/mambaforge/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
yielded =self.gen.throw(*exc_info) # type:ignore
File "/home/mrocklin/workspace/distributed/distributed/utils.py", line 220, in quietyield task
File "/home/mrocklin/mambaforge/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
value = future.result()
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 867, in send_recv_from_rpcraisetype(e)(
distributed.comm.core.CommClosedError: Exception while trying to call remote method 'restart' before comm was established.
2022-04-12 10:34:22,259 - tornado.application - ERROR - Exception in callback functools.partial(<bound method IOLoop._discard_future_result of <tornado.platform.asyncio.AsyncIOLoop object at 0x7f1dc605be80>>, <Task finished name='Task-33593' coro=<Scheduler.restart() done, defined at /home/mrocklin/workspace/distributed/distributed/scheduler.py:6061> exception=CommClosedError("Exception while trying to call remote method 'restart' before comm was established.")>)
Traceback (most recent call last):
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 226, in read
frames_nbytes =await stream.read_bytes(fmt_size)
tornado.iostream.StreamClosedError: Stream is closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 864, in send_recv_from_rpc
result =await send_recv(comm=comm, op=key, **kwargs)
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 709, in send_recv
response =await comm.read(deserializers=deserializers)
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 242, in read
convert_stream_closed_error(self, e)
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 150, in convert_stream_closed_errorraise CommClosedError(f"in {obj}: {exc}") from exc
distributed.comm.core.CommClosedError: in <TCP (closed) rpc.restart local=tcp://127.0.0.1:51462 remote=tcp://127.0.0.1:35655>: Stream is closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mrocklin/mambaforge/lib/python3.9/site-packages/tornado/ioloop.py", line 741, in _run_callback
ret = callback()
File "/home/mrocklin/mambaforge/lib/python3.9/site-packages/tornado/ioloop.py", line 765, in _discard_future_result
future.result()
File "/home/mrocklin/workspace/distributed/distributed/scheduler.py", line 6116, in restart
resps =await asyncio.wait_for(resps, timeout)
File "/home/mrocklin/mambaforge/lib/python3.9/asyncio/tasks.py", line 481, in wait_forreturn fut.result()
File "/home/mrocklin/workspace/distributed/distributed/utils.py", line 207, in All
result =await tasks.next()
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 867, in send_recv_from_rpcraisetype(e)(
distributed.comm.core.CommClosedError: Exception while trying to call remote method 'restart' before comm was established.
Task exception was never retrieved
future: <Task finished name='Task-33599' coro=<rpc.__getattr__.<locals>.send_recv_from_rpc() done, defined at /home/mrocklin/workspace/distributed/distributed/core.py:855> exception=CommClosedError("Exception while trying to call remote method 'restart' before comm was established.")>
Traceback (most recent call last):
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 226, in read
frames_nbytes =await stream.read_bytes(fmt_size)
tornado.iostream.StreamClosedError: Stream is closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 864, in send_recv_from_rpc
result =await send_recv(comm=comm, op=key, **kwargs)
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 709, in send_recv
response =await comm.read(deserializers=deserializers)
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 242, in read
convert_stream_closed_error(self, e)
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 150, in convert_stream_closed_errorraise CommClosedError(f"in {obj}: {exc}") from exc
distributed.comm.core.CommClosedError: in <TCP (closed) rpc.restart local=tcp://127.0.0.1:50694 remote=tcp://127.0.0.1:35275>: Stream is closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 867, in send_recv_from_rpcraisetype(e)(
distributed.comm.core.CommClosedError: Exception while trying to call remote method 'restart' before comm was established.
Task exception was never retrieved
future: <Task finished name='Task-33600' coro=<rpc.__getattr__.<locals>.send_recv_from_rpc() done, defined at /home/mrocklin/workspace/distributed/distributed/core.py:855> exception=CommClosedError("Exception while trying to call remote method 'restart' before comm was established.")>
Traceback (most recent call last):
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 226, in read
frames_nbytes =await stream.read_bytes(fmt_size)
tornado.iostream.StreamClosedError: Stream is closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 864, in send_recv_from_rpc
result =await send_recv(comm=comm, op=key, **kwargs)
File "/home/mrocklin/workspace/distributed/distributed/core.py", line 709, in send_recv
response =await comm.read(deserializers=deserializers)
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 242, in read
convert_stream_closed_error(self, e)
File "/home/mrocklin/workspace/distributed/distributed/comm/tcp.py", line 150, in convert_stream_closed_errorraise CommClosedError(f"in {obj}: {exc}") from exc
distributed.comm.core.CommClosedError: in <TCP (closed) rpc.restart local=tcp://127.0.0.1:45222 remote=tcp://127.0.0.1:37231>: Stream is closed
The above exception was the direct cause of the following exception:
Shifting back. I'm now running this at scale on Coiled. I'm not yet seeing a deadlock. @fjetter can you say a bit more about how often you ran into this?
We reverted the default environment on coiled so the above will not trigger an issue anymore. With 2022.4.1 it will deadlock within seconds / few minutes
I've tried distributed from main to get #6112. Still deadlocks.
The overall pattern I'm seeing is at least 1 worker which is effectively dead, but hasn't been removed from the scheduler yet.
Other works seem to still want to fetch data from that worker.
In [9]: client.run(lambdadask_worker: [ts.who_hasfortsindask_worker.data_needed], workers=['tls://10.6.0.70:34327'])
Out[9]:
{'tls://10.6.0.70:34327': [{'tls://10.6.12.222:42533'},
{'tls://10.6.12.222:42533'},
{'tls://10.6.12.222:42533'}]}
# notice the `who_has` addresses are all the same, and all reference the unresponsive red worker above
Here are logs (via Coiled) from one of the unresponsive workers:
2022-04-14 18:55:24,233 - distributed.worker - ERROR - Worker stream died during communication: tls://10.6.3.191:45383
Traceback (most recent call last):
File "/opt/conda/envs/coiled/lib/python3.9/site-packages/tornado/iostream.py", line 867, in _read_to_buffer
bytes_read =self.read_from_fd(buf)
File "/opt/conda/envs/coiled/lib/python3.9/site-packages/tornado/iostream.py", line 1592, in read_from_fdreturnself.socket.recv_into(buf, len(buf))
File "/opt/conda/envs/coiled/lib/python3.9/ssl.py", line 1241, in recv_intoreturnself.read(nbytes, buffer)
File "/opt/conda/envs/coiled/lib/python3.9/ssl.py", line 1099, in readreturnself._sslobj.read(len, buffer)
ConnectionResetError: [Errno 104] Connection reset by peer
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/conda/envs/coiled/lib/python3.9/site-packages/distributed/worker.py", line 3019, in gather_dep
response =await get_data_from_worker(
File "/opt/conda/envs/coiled/lib/python3.9/site-packages/distributed/worker.py", line 4320, in get_data_from_workerreturnawait retry_operation(_get_data, operation="get_data_from_worker")
File "/opt/conda/envs/coiled/lib/python3.9/site-packages/distributed/utils_comm.py", line 381, in retry_operationreturnawait retry(
File "/opt/conda/envs/coiled/lib/python3.9/site-packages/distributed/utils_comm.py", line 366, in retryreturnawait coro()
File "/opt/conda/envs/coiled/lib/python3.9/site-packages/distributed/worker.py", line 4300, in _get_data
response =await send_recv(
File "/opt/conda/envs/coiled/lib/python3.9/site-packages/distributed/core.py", line 709, in send_recv
response =await comm.read(deserializers=deserializers)
File "/opt/conda/envs/coiled/lib/python3.9/site-packages/distributed/comm/tcp.py", line 242, in read
convert_stream_closed_error(self, e)
File "/opt/conda/envs/coiled/lib/python3.9/site-packages/distributed/comm/tcp.py", line 148, in convert_stream_closed_errorraise CommClosedError(f"in {obj}: {exc.__class__.__name__}: {exc}") from exc
distributed.comm.core.CommClosedError: in <TLS (closed) Ephemeral Worker->Worker for gather local=tls://10.6.3.169:44316 remote=tls://10.6.3.191:45383>: ConnectionResetError: [Errno 104] Connection reset by peer
2022-04-14 18:56:15,295 - distributed.worker - INFO - Stopping worker at tls://10.6.3.169:43833
2022-04-14 18:56:15,318 - distributed.nanny - INFO - Worker closed
2022-04-14 18:56:16,231 - distributed.worker - INFO - Start worker at: tls://10.6.3.169:40133
2022-04-14 18:56:16,231 - distributed.worker - INFO - Listening to: tls://10.6.3.169:40133
2022-04-14 18:56:16,231 - distributed.worker - INFO - dashboard at: 10.6.3.169:39063
2022-04-14 18:56:16,231 - distributed.worker - INFO - Waiting to connect to: tls://34.221.160.71:8786
2022-04-14 18:56:16,231 - distributed.worker - INFO - -------------------------------------------------
2022-04-14 18:56:16,231 - distributed.worker - INFO - Threads: 2
2022-04-14 18:56:16,233 - distributed.worker - INFO - Memory: 3.78 GiB
2022-04-14 18:56:16,233 - distributed.worker - INFO - Local Directory: /dask-worker-space/worker-c7603wej
2022-04-14 18:56:16,234 - distributed.worker - INFO - -------------------------------------------------
2022-04-14 18:56:16,477 - distributed.worker - WARNING - Mismatched versions found
+-------------+-----------------------+-----------------------+---------------------------------------+
| Package | This Worker | scheduler | workers |
+-------------+-----------------------+-----------------------+---------------------------------------+
| blosc | MISSING | MISSING | {None, 'MISSING'} |
| distributed | 2022.4.0+33.g41ecbca2 | 2022.4.0+33.g41ecbca2 | {'2022.4.0+33.g41ecbca2', '2022.4.0'} |
| python | 3.9.12.final.0 | 3.9.12.final.0 | {'3.9.12.final.0', '3.9.1.final.0'} |
+-------------+-----------------------+-----------------------+---------------------------------------+
2022-04-14 18:56:16,478 - distributed.worker - INFO - Starting Worker plugin coiled-aws-env
2022-04-14 18:56:16,480 - distributed.worker - INFO - Registered to: tls://34.221.160.71:8786
2022-04-14 18:56:16,482 - distributed.worker - INFO - -------------------------------------------------
2022-04-14 18:56:16,483 - distributed.core - INFO - Starting established connection
You'll notice:
Connection to a different worker fails
The worker shuts down for some reason. I don't know why. But the nanny restarts it, and it reconnects.
I'm seeing the nanny-restart for all three unresponsive workers in my most recent run. Other workers don't show that pattern. I feel like the reconnection could have something to do with it.
I'm also confused why the workers seem to think they've reconnected to the scheduler, yet the scheduler still sees their last_seen time as many minutes ago.
I have cluster dumps, but I've found them less useful so far than just poking at things manually.
I'm playing with this. I've gotten only about as far as @gjoseph92 has. I'm seeing the same thing. I don't see any reason why the worker would have restarted, which is also strange. (I'm not seeing the same comm issue)
Also, two quick notes, my recent PRs don't seem to help with this.
If I use m5.large instances (my default type) this problem doesn't occur. My guess is that there is some disk thing happening here. We're running out of space and so failing hard when trying to touch disk. I'm going to aim towards that as a cause and just try to increase visibility along the way.
Good to know. It doesn't seem like we could dump that much data this quickly with this workload. I did throw up a test to see what happens with Disk stops cooperating. We're not graceful here. #6128
I also tried to see what happens when we fail writing, and things were actually ok.
Thanks! (Note that testing this will require tweaking the size of the dataframes to ensure data is still being spilled—don't assume that just because the script works on an i3.large, that NVMe resolves the problem. As @jrbourbeau found, getting this OOM hang to occur is pretty dependent on machine and data size.)
@fjetter for posterity & future searches, could you rename this to "Computation deadlocks due to worker rapidly running out of memory instead of spilling" or something like that, now that we've found a root cause?
However, user code could still allocate memory on its own in a way that causes the machine to lock up (OS failing because it's trying to swap everything to disk).
changed the title [-]Computation deadlocks[/-][+]Computation deadlocks due to worker rapidly running out of memory instead of spilling[/+]on Apr 25, 2022
@fjetter for posterity & future searches, could you rename this to "Computation deadlocks due to worker rapidly running out of memory instead of spilling" or something like that, now that we've found a root cause?
Update here others might find interesting: the lock-up likely is caused by swapping, but not in the way you'd think. It points to #6177 being a very worthwhile thing to do.
#4345 (comment) got my curious: yeah, why isn't the kernel's OOMKiller getting involved here and just killing the Python process that's using too much memory?
I spun up a t3.medium node with Coiled (what we were using here) and SSHd on. First interesting thing: free reports 0B of swap available. So the heap of our Python processes aren't actually going to get swapped out.
ubuntu@ip-10-0-9-34:~$ cat <(</dev/zero head -c 3GiB)<(sleep 10)| tail
# 3GiB goes fine, unsurprisingly.
ubuntu@ip-10-0-9-34:~$ cat <(</dev/zero head -c 4GiB)<(sleep 10)| tail
Killed
# 4GiB is more than the total physically available space. So this also goes well.
ubuntu@ip-10-0-9-34:~$ cat <(</dev/zero head -c 3200MiB)<(sleep 10)| tail
# This has now been unresponsive for 12min!# My SSH connection is still up, but tmux panes are unresponsive.# Clearly this is very locked up, because the 10-sec timeout isn't even working
It turns out the OOMKiller is very conservative and doesn't kill things even when system performance is extremely degraded, so long as there are any pages it can reclaim. And even without a swap partition, the kernel can and will still swap pages to disk if they were on disk to begin with—such as executable code. (See https://askubuntu.com/a/432827 for an explanation.) Really, this just means the kernel is willing to remove almost everything from the disk cache, so executing new instructions in the Python interpreter or any other executables means constantly reloading pages from disk. It's all still running... just really... really... slowly.
But we don't have to worry about the generic case. For dask, we can reasonably expect that the worker process tree is the only thing allocating significant amounts of memory. If we just set hard memory limits at the OS level (#6177) and don't let dask go above 95% of physically available memory (our current default), we should be able to terminate before we get into this thrashing scenario.
And if we don't set hard limits at the OS level (we currently don't), we should have no reason to believe that we'd be able to successfully prevent or recover from this via our application-level memory monitor. Prevention is the only option, because once we get into this state, no userland processes can run effectively.
Whoa, nice find. The cat-sleep example is a super-clear demonstration.
I'm open to thinking about cgroups at the Dask level. If that doesn't work for some reason, we could probably also consider handling this on the Coiled side. A couple of thoughts:
@ntabris would it make sense to direct the OS to treat EBS as swap? (or is this a bad idea / too painful)
We could run the dask-spec process with cgroup limits as well (might as well do this regardless?)
We could run the dask-spec process with cgroup limits as well (might as well do this regardless?)
Coiled actually used to do this (via Docker), but it was removed a while ago so that if you got heterogeneous node sizes, you'd fully use the memory on all of them (why this had to be removed is a bit of a Coiled implementation detail though).
But I think Dask should do this. We already offer a memory limit parameter; this would just be an implementation fix to make it work correctly.
would it make sense to direct the OS to treat EBS as swap? (or is this a bad idea / too painful)
I haven't tried this but it sounds like it's not recommended. In my mind, one big reason to be in the cloud is that it's really easy to scale up if you (say) need more memory. Is there a reason someone would prefer slow disk swap rather than instance with more memory? (Maybe if they only needed swap space very occasionally? Or didn't realize they'd need more memory but don't want their workers to die?)
Just to summarize what I understand. We saw this issue appear in the 2022.4.? release but didn't in 2022.1.1 and we bisected and found #6189 The working theory is that #6189 indeed allows us to spill data faster which helps us to avoid the swap scenario
Maybe#5971? I'd be curious what it looks like setting the env var manually on the cluster (easy with Coiled). I'd be unsurprised to hear it's something else though.
I'm running into a similar issue here where a dask-geopandas computation is 'deadlocking' without error messages. A worker is running out of memory and the deadlocking task is getting shipped around workers. More info here: geopandas/dask-geopandas#197
Ok, it seems unlikely that we're putting that much data that quickly on a
node. It does feel like the worker logic has been interrupted by something
similar though. This will be an interesting hunt. I'll try playing with a
few parameters of the experiment and see if there's a good pattern on when
it occurs. Thanks!
Activity
mrocklin commentedon Apr 12, 2022
martindurant commentedon Apr 12, 2022
Do you have an estimate of what fraction of runs? As @mrocklin says, this script is ideal for a bisect (behind a timeout failure).
mrocklin commentedon Apr 12, 2022
I'm currently trying to run this locally without Coiled. I encourage other folks to hop on as well, but I'll at least try to run with this for the rest of the day when I have free time.
mrocklin commentedon Apr 12, 2022
I'm also curious about how often this fails. Currently running this locally and not running into anything. I'm wondering how long I should wait before moving up to Coiled.
mrocklin commentedon Apr 12, 2022
I'm getting these when running locally, but I suspect that they're due to being unclean on restart
Traceback
mrocklin commentedon Apr 12, 2022
Shifting to #5951 , which seems easier to iterate on
mrocklin commentedon Apr 12, 2022
Shifting back. I'm now running this at scale on Coiled. I'm not yet seeing a deadlock. @fjetter can you say a bit more about how often you ran into this?
fjetter commentedon Apr 13, 2022
We reverted the default environment on coiled so the above will not trigger an issue anymore. With 2022.4.1 it will deadlock within seconds / few minutes
gjoseph92 commentedon Apr 14, 2022
I've been running this on Coiled. It reliably deadlocks within 2-3 iterations.
Script
I've tried distributed from main to get #6112. Still deadlocks.
The overall pattern I'm seeing is at least 1 worker which is effectively dead, but hasn't been removed from the scheduler yet.
Other works seem to still want to fetch data from that worker.
Here are logs (via Coiled) from one of the unresponsive workers:
You'll notice:
I'm seeing the nanny-restart for all three unresponsive workers in my most recent run. Other workers don't show that pattern. I feel like the reconnection could have something to do with it.
I'm also confused why the workers seem to think they've reconnected to the scheduler, yet the scheduler still sees their
last_seentime as many minutes ago.I have cluster dumps, but I've found them less useful so far than just poking at things manually.
mrocklin commentedon Apr 14, 2022
I'm playing with this. I've gotten only about as far as @gjoseph92 has. I'm seeing the same thing. I don't see any reason why the worker would have restarted, which is also strange. (I'm not seeing the same comm issue)
Logs
I see a few things to inspect:
None of these will find the answer, but I think that they're all increase visibility. These are my next steps. I'm also open to other suggestions.
mrocklin commentedon Apr 14, 2022
Also, two quick notes, my recent PRs don't seem to help with this.
If I use m5.large instances (my default type) this problem doesn't occur. My guess is that there is some disk thing happening here. We're running out of space and so failing hard when trying to touch disk. I'm going to aim towards that as a cause and just try to increase visibility along the way.
mrocklin commentedon Apr 14, 2022
cc @ntabris without SSDs Coiled instances have 10GB drives right now. Is that right?
ntabris commentedon Apr 14, 2022
No, prod and staging are still putting 100GB boot (EBS) drives on all instances.
mrocklin commentedon Apr 14, 2022
Good to know. It doesn't seem like we could dump that much data this quickly with this workload. I did throw up a test to see what happens with Disk stops cooperating. We're not graceful here. #6128
I also tried to see what happens when we fail writing, and things were actually ok.
mrocklin commentedon Apr 15, 2022
Oh, I'm being dumb. The closed workers are due to the client.restart command 🤦
37 remaining items
mrocklin commentedon Apr 22, 2022
gjoseph92 commentedon Apr 22, 2022
Thanks! (Note that testing this will require tweaking the size of the dataframes to ensure data is still being spilled—don't assume that just because the script works on an
i3.large, that NVMe resolves the problem. As @jrbourbeau found, getting this OOM hang to occur is pretty dependent on machine and data size.)gjoseph92 commentedon Apr 25, 2022
@fjetter for posterity & future searches, could you rename this to "Computation deadlocks due to worker rapidly running out of memory instead of spilling" or something like that, now that we've found a root cause?
Also, to summarize:
resumedtask #6159[-]Computation deadlocks[/-][+]Computation deadlocks due to worker rapidly running out of memory instead of spilling[/+]mrocklin commentedon Apr 25, 2022
Done
gjoseph92 commentedon Apr 25, 2022
Update here others might find interesting: the lock-up likely is caused by swapping, but not in the way you'd think. It points to #6177 being a very worthwhile thing to do.
#4345 (comment) got my curious: yeah, why isn't the kernel's OOMKiller getting involved here and just killing the Python process that's using too much memory?
I spun up a
t3.mediumnode with Coiled (what we were using here) and SSHd on. First interesting thing:freereports 0B of swap available. So the heap of our Python processes aren't actually going to get swapped out.Let's see what happens when we use up some memory (based on https://unix.stackexchange.com/a/254976).
freeis reporting we have 3.2Gi available between free RAM and purgeable cache pages:It turns out the OOMKiller is very conservative and doesn't kill things even when system performance is extremely degraded, so long as there are any pages it can reclaim. And even without a swap partition, the kernel can and will still swap pages to disk if they were on disk to begin with—such as executable code. (See https://askubuntu.com/a/432827 for an explanation.) Really, this just means the kernel is willing to remove almost everything from the disk cache, so executing new instructions in the Python interpreter or any other executables means constantly reloading pages from disk. It's all still running... just really... really... slowly.
Basically, getting into the "almost all physical memory is used, but not quite all of it" terrain leads to very bad behavior. People complain/rant about this a bit: https://unix.stackexchange.com/questions/373312/oom-killer-doesnt-work-properly-leads-to-a-frozen-os, https://serverfault.com/questions/390623/how-do-i-prevent-linux-from-freezing-when-out-of-memory, etc. There doesn't seem to be a good answer for how to avoid this in linux generically.
But we don't have to worry about the generic case. For dask, we can reasonably expect that the worker process tree is the only thing allocating significant amounts of memory. If we just set hard memory limits at the OS level (#6177) and don't let dask go above 95% of physically available memory (our current default), we should be able to terminate before we get into this thrashing scenario.
And if we don't set hard limits at the OS level (we currently don't), we should have no reason to believe that we'd be able to successfully prevent or recover from this via our application-level memory monitor. Prevention is the only option, because once we get into this state, no userland processes can run effectively.
mrocklin commentedon Apr 25, 2022
Whoa, nice find. The cat-sleep example is a super-clear demonstration.
I'm open to thinking about cgroups at the Dask level. If that doesn't work for some reason, we could probably also consider handling this on the Coiled side. A couple of thoughts:
gjoseph92 commentedon Apr 26, 2022
Coiled actually used to do this (via Docker), but it was removed a while ago so that if you got heterogeneous node sizes, you'd fully use the memory on all of them (why this had to be removed is a bit of a Coiled implementation detail though).
But I think Dask should do this. We already offer a memory limit parameter; this would just be an implementation fix to make it work correctly.
ntabris commentedon Apr 26, 2022
I haven't tried this but it sounds like it's not recommended. In my mind, one big reason to be in the cloud is that it's really easy to scale up if you (say) need more memory. Is there a reason someone would prefer slow disk swap rather than instance with more memory? (Maybe if they only needed swap space very occasionally? Or didn't realize they'd need more memory but don't want their workers to die?)
fjetter commentedon Apr 26, 2022
Great find @gjoseph92 .
Just to summarize what I understand. We saw this issue appear in the 2022.4.? release but didn't in
2022.1.1and we bisected and found #6189 The working theory is that #6189 indeed allows us to spill data faster which helps us to avoid the swap scenariocrusaderky commentedon Apr 27, 2022
I ran the stress test.
Main git tip deadlocks in less than 5 minutes.
#6189 + #6195 have been running for 30 minutes and seem to be stable.
As a side note, that's a lot of unmanaged memory. Screenshot from #6189 + #6195:
Do we understand what it is? Is it because of the shuffle?
gjoseph92 commentedon Apr 27, 2022
Maybe #5971? I'd be curious what it looks like setting the env var manually on the cluster (easy with Coiled). I'd be unsurprised to hear it's something else though.
avriiil commentedon Jun 13, 2022
I'm running into a similar issue here where a dask-geopandas computation is 'deadlocking' without error messages. A worker is running out of memory and the deadlocking task is getting shipped around workers. More info here: geopandas/dask-geopandas#197
mrocklin commentedon Oct 11, 2022