How to Cache Objects in the Object Store?

How severe does this issue affect your experience of using Ray?

  • High: It blocks me to complete my task.

I’m trying to cache objects in the cluster for use between Serve calls and things aren’t working. I’m bumping up against the limits of my mental model of how things work. Hopefully someone can explain the best way of doing things.

The approach I thought would work would be to create a long-lived actor with some get() and put() methods (plus ttl, etc.). When I get the objects out I’m getting ObjectRef’s instead of the objects, so clearly something’s wrong. Some questions I have:

  • Do I need the cache actor to have the data or can I just pass it a reference to the data? The data could be large, so if it’s on another machine, it would be best to just pass a reference. For example, can I call ray.put() in the task doing the computation and pass the returned ObjectRef to the cache actor to keep the data alive?
  • Is there a way to have the later computation occur on the same machine as where the data was cached?
  • I noticed the _owner parameter on ray.put() (and the experimental disclaimer). Is this relevant to this? Is there an example of how this works?

Or maybe I’m going about this all wrong and there’s a better way?

Thanks in advance!

@brian before the owner problem is fixed, _owner is what you need to make it work.

Check the test case here for some refs test_object_assign_owner.py - ray-project/ray - Sourcegraph

Basically, get an actor created, when you put, you just put and assign the owner. If later you want to retrieve it, you need to store the obj ref in the actor too.

  • Do I need the cache actor to have the data or can I just pass it a reference to the data? The data could be large, so if it’s on another machine, it would be best to just pass a reference. For example, can I call ray.put() in the task doing the computation and pass the returned ObjectRef to the cache actor to keep the data alive?

Pass ref is correct.

  • Is there a way to have the later computation occur on the same machine as where the data was cached?

This depends on the scheduling algorithm, data locality should be covered, but I don’t think it’ll
always run as your expection. Scheduling policy is something maybe you should check Scheduling — Ray 2.8.0

  • I noticed the _owner parameter on ray.put() (and the experimental disclaimer). Is this relevant to this? Is there an example of how this works?

When owner died, the object will be lost, in this case, you will like to make the actor the owner of the object.