1

When calling multiple function.remote() with large arguments, there seems to be memory issue.

@ray.remote 
def function(args):
    # do something

args={} # big dictionary 
args=ray.put(args)

[function.remote(args) for _ in range(1000)]

When i ran codes like the above, ram usage kept increasing and memory leak problem occurred. From what i know, "ray.put" method writes "args" to shared memory. Therefore every process consuming the function accesses "args" in shared memory instead of copying args to each process. If it did, memory usage would not increase.

Is there anything i am confused?

2
  • No, ray.put says "store this object in the object store". There will still be 1,000 copies of the object in the object store. Commented Sep 23, 2022 at 5:09
  • @TimRoberts the Ray object store has zero-copy capabilities for numpy arrays/other datatypes supported by arrow. So the question isn't unreasonable. Commented Sep 23, 2022 at 20:29

1 Answer 1

1

Tl;DR

Can you use a numpy array or other arrow-compatible datatype instead of your args dict? dicts will incur a deserialization cost + additional memory in which to store the deserialized value, for every concurrent usage of the value.

Details

Ray's support for zero-copy semantics seems to have been built with numpy + other data types that are supported by apache arrow as first-class citizens. It is technically feasible to add zero-copy support for dict and other types, but Ray would need to subclass these types so that mutations invoke a copy-on-write mechanism. Or, otherwise provide a zero-copy deserialization mechanism from the object store to the python heap. Maybe a good idea to make Ray better :)

Furthermore, Ray doesn't currently have good memoization support. So even if you put two different identical dicts into the object store, you'll get two object references.

If having these features would unblock you, I'd recommend creating a GitHub issue in the Ray repository.

Source: I asked Stephanie Wang, a co-author of the original Ray paper, this question.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. I did not know dictionary data type is not supported to use shared memory and zero-copy deserialization. Therefore, as i understand, if i use my code snippet, "args" will be serialized and then copy to all of the processes. Because of that, memory leak problem occurred

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.