ray icon indicating copy to clipboard operation
ray copied to clipboard

Ray cluster crashes because of limited memory

Open sp608 opened this issue 7 years ago • 4 comments

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04
  • Ray installed from (source or binary): Binary
  • Ray version: 0.7.1
  • Python version: 3.6.3
  • Exact command to reproduce: python3.6 test.py

Describe the problem

I am attempting to analyze a CSV file that is around 200 MB. My main node has 24 GB of free memory at any given time, but when I try to run my python code, redis says that the function is too large when pickled. The code runs fine when I try it on one machine (ray.init()), but crashes the ray process on all servers when I run it with (ray.init(redis_address="10.0.0.20:6379"). This cluster has 300+ cores available so I would like to take advantage of them.

Thanks for your help.

Source code / logs

ray.utils.get_system_memory()

Equals 33671143424 (33 GB)

test.py

import ray
import pandas as pd
import numpy as np
#ray.init(redis_address="10.0.0.20:6379")
ray.init()
df = pd.read_csv('test_case.csv', index_col=0).to_numpy()

@ray.remote
def process_csv():
    for x in df:
        pass

if __name__ == '__main__':
    ray.get(process_csv.remote())

Console output when running on one machine:

2019-08-12 11:33:47,567 INFO node.py:498 -- Process STDOUT and STDERR is being redirected to /tmp/ray/session_2019-08-12_11-33-47_566996_2714/logs.
2019-08-12 11:33:47,671 INFO services.py:409 -- Waiting for redis server at 127.0.0.1:58297 to respond...
2019-08-12 11:33:47,781 INFO services.py:409 -- Waiting for redis server at 127.0.0.1:38537 to respond...
2019-08-12 11:33:47,782 INFO services.py:806 -- Starting Redis shard with 6.73 GB max memory.
2019-08-12 11:33:47,790 INFO node.py:512 -- Process STDOUT and STDERR is being redirected to /tmp/ray/session_2019-08-12_11-33-47_566996_2714/logs.
2019-08-12 11:33:47,791 INFO services.py:1442 -- Starting the Plasma object store with 10.1 GB memory using /dev/shm.
2019-08-12 11:33:51,252 ERROR worker.py:1668 -- Warning: The remote function __main__.process_process has size 200370884 when pickled. It will be stored in Redis, which could cause memory issues. This may mean that its definition uses a large array or other object.

Console output when running on cluster:

2019-08-12 11:38:47,238 ERROR worker.py:1668 -- Warning: The remote function __main__.process_packets has size 200370884 when pickled. It will be stored in Redis, which could cause memory issues. This may mean that its definition uses a large array or other object.
Exception in thread ray_listen_error_messages:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.6/site-packages/ray/worker.py", line 1646, in listen_error_messages_raylet
    msg = worker.error_message_pubsub_client.get_message()
  File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 3283, in get_message
    response = self.parse_response(block=False, timeout=timeout)
  File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 3169, in parse_response
    if not block and not conn.can_read(timeout=timeout):
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 674, in can_read
    return self._parser.can_read(timeout)
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 291, in can_read
    return self._buffer and self._buffer.can_read(timeout)
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 201, in can_read
    raise_on_timeout=False)
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 176, in _read_from_socket
    raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
redis.exceptions.ConnectionError: Connection closed by server.

Exception in thread ray_import_thread:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.6/site-packages/ray/import_thread.py", line 69, in _run
    msg = import_pubsub_client.get_message()
  File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 3283, in get_message
    response = self.parse_response(block=False, timeout=timeout)
  File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 3169, in parse_response
    if not block and not conn.can_read(timeout=timeout):
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 674, in can_read
    return self._parser.can_read(timeout)
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 291, in can_read
    return self._buffer and self._buffer.can_read(timeout)
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 201, in can_read
    raise_on_timeout=False)
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 176, in _read_from_socket
    raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
redis.exceptions.ConnectionError: Connection closed by server.

Exception in thread ray_print_logs:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.6/site-packages/ray/worker.py", line 1544, in print_logs
    msg = pubsub_client.get_message()
  File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 3283, in get_message
    response = self.parse_response(block=False, timeout=timeout)
  File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 3169, in parse_response
    if not block and not conn.can_read(timeout=timeout):
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 674, in can_read
    return self._parser.can_read(timeout)
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 291, in can_read
    return self._buffer and self._buffer.can_read(timeout)
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 201, in can_read
    raise_on_timeout=False)
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 176, in _read_from_socket
    raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
redis.exceptions.ConnectionError: Connection closed by server.

sp608 avatar Aug 12 '19 18:08 sp608

Hi @sp608 thanks for the report. This is because df is a global variable referenced by the function and ray tries to ship it to all workers.

The memory efficient way to do it will be


- df = pd.read_csv('test_case.csv', index_col=0).to_numpy()
+ df_oid = ray.put(pd.read_csv('test_case.csv', index_col=0).to_numpy())

@ray.remote
- def process_csv():
+ def process_csv(df):
    for x in df:
        pass

if __name__ == '__main__':
-     ray.get(process_csv.remote())
+    ray.get(process_csv.remote(df_oid))

In this case, df_oid refers to the single copy inside ray's shared memory object store. Any worker referencing it will use zero-copy read to reduce memory consumption.

Let me know if you are still encountering this issue!

By the way, modin is a distributed dataframe project that runs on ray. It is a drop-in replacement for pandas that runs on a cluster.

simon-mo avatar Aug 14 '19 00:08 simon-mo

Hi @simon-mo, thanks for the response. I tried using the code you wrote and it worked for some file sizes (the largest it works on is ~680MB). However, when I attempt to run the code on a file that is about 4 GB, the program runs for a while as expected, but then outputs Killed, promptly crashing ray on my cluster.

sp608 avatar Aug 14 '19 20:08 sp608

Hi, I'm a bot from the Ray team :)

To help human contributors to focus on more relevant issues, I will automatically add the stale label to issues that have had no activity for more than 4 months.

If there is no further activity in the 14 days, the issue will be closed!

  • If you'd like to keep the issue open, just leave any comment, and the stale label will be removed!
  • If you'd like to get more attention to the issue, please tag one of Ray's contributors.

You can always ask for help on our discussion forum or Ray's public slack channel.

stale[bot] avatar Nov 14 '20 10:11 stale[bot]

Hi again! The issue will be closed because there has been no more activity in the 14 days since the last message.

Please feel free to reopen or open a new issue if you'd still like it to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for opening the issue!

stale[bot] avatar Nov 28 '20 10:11 stale[bot]