How to define a multiprocess safe shared object class in ray? should I use lock
?
Sorry, I don’t get what you mean here. Could you give more details? For example, why do you think it’s causing anything difference in ray?
Ray objects are immutable, so you don’t need to think about “shared writing to one object”. If you’d like to modify objects in place, you can use an actor instead. For example, put the object to the actor, and write actor methods to modify them
Does this mean the function (to update an actor local variable) of an Actor A
in a ray can only be called by one another actor B
?
even if there are two other actors (B
and C
) are trying to concurrently invoke the A’s internal value update it will be scheduled to be conducted sequentially by ray so that there is no data consistency issue.
Yes, all actor methods are run sequentially. No race condition in this case.
A couple more things to note;
- If the actor method is invoked by the same caller, the ordering is guaranteed by Ray.
- When you “get” the modified object, I recommend you to implement returning the parts of objects instead of returning the whole object. The zero copy read might not work in this case.