Pros and Cons of passing ObjectRefs in a container

Hi guys,

I would like to ask you about Pros and Cons of passing ObjectRefs in a container (for instance, in a list) to a remote function. Especially, how does it affect the performance if we run it in a cluster?

Thanks in advance!

@sangcho, can you give some thoughts on this, please?

When the object ref is passed into a remote function, ray.get is automatically (implicitly) called.

@ray.remote
def f(ref):
    print(ref) # It prints the numpy array, not the ref

ref = ray.put(np.ones(1024*1024, dtype=np.unit8))
ray.get(f.remote(ref))

But if you pass references within a list, ray.get is not implicitly called.

@ray.remote
def f(ref):
    print(ref) # It prints a [ref], and ray.get is not called until you explicitly call it.
    print(ray.get(ref)) # This is the numpy array.
 
ref = ray.put(np.ones(1024*1024, dtype=np.unit8))
ray.get(f.remote([ref]))

Regarding performance, there’s nothing I am aware of that can impact the performance. If you pass the ref within a container, you can control memory a bit better (since you can obtain objects from the plasma store only when you really need it), but with zero-copy read, it wouldn’t be a big deal in many cases.

1 Like

@sangcho , yes, that is true. However, is that an issue for ray in a cluster if we pass a list of ObjectRefs in a remote function? I mean in that case ray won’t have enough information for better scheduling and placement. Is it right?

That’s a good question! Ray doesn’t use the object store memory information for scheduling (we are planning to do, but even after that, it won’t be a too big deal). I cannot think of any bad implication of this except that ray.get could take more time (but scheduling could be faster, so it is complemented)

@sangcho , to summarize, there is nothing bad if we pass a list of ObjectRefs to a remote function. The drawback is that ray.get can take more time. If I am not correct or there is something to add, please, let me know.

To be clear, my answer is there’s nothing that I am aware of that can impact the performance. But what you said sounds right to me.

@sangcho , okay, thank you!

1 Like