# Many actors writing to one object

**URL:** <https://discuss.ray.io/t/many-actors-writing-to-one-object/2112>\
**Category:** Ray Core\
**Created:** [May 10, 2021, 4:54am UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112 "2021-05-10T04:54:47Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![psytron](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@psytron](https://discuss.ray.io/u/psytron)\
**Post date:** [May 10, 2021, 4:54am UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/1 "2021-05-10T04:54:47Z")

</div>

I would like to have a basic object which all actor classes can write and read. What is best way to do that?

---

<div class="post-metadata">

**Author:** ![rliaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rliaw/32/24_2.png) [@rliaw](https://discuss.ray.io/u/rliaw)\
**Post date:** [May 12, 2021, 11:49pm UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/2 "2021-05-12T23:49:55Z")

</div>

Probably the easiest way here is to just create a new Actor that the other actors will communicate with.

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [May 13, 2021, 6:32am UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/3 "2021-05-13T06:32:48Z")

</div>

Yeah using actor for global variables is the way to go right now ([Ray Design Patterns - Google Docs](https://docs.google.com/document/d/167rnnDFIVRhHhK4mznEIemOtj63IOhtIPvSYaPgI4Fg/edit#heading=h.eg7m6lz2y48u)). Note that plasma store objects are “immutable”, so you are not able to write to the object.

---

<div class="post-metadata">

**Author:** ![psytron](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@psytron](https://discuss.ray.io/u/psytron)\
**Post date:** [May 16, 2021, 11:59pm UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/4 "2021-05-16T23:59:13Z")

</div>

Is this the fastest most-realtime method of communication between actors?

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [May 17, 2021, 7:43am UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/5 "2021-05-17T07:43:49Z")

</div>

Can you elaborate your question a little bit? I don’t think I understood!

---

<div class="post-metadata">

**Author:** ![psytron](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@psytron](https://discuss.ray.io/u/psytron)\
**Post date:** [May 17, 2021, 10:56pm UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/6 "2021-05-17T22:56:18Z")

</div>

Lets say you wanted to have several Ray actors running forever collecting data, and writing the data to a globally available pandas DataFrame which all actors can see and modify

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [May 17, 2021, 11:12pm UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/7 "2021-05-17T23:12:57Z")

</div>

ah I understand that part. What do you mean by `fastest most-realtime method of communication between actors?` Are you asking me if using an actor for the global object is the fastest way to achieve it?

---

<div class="post-metadata">

**Author:** ![psytron](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@psytron](https://discuss.ray.io/u/psytron)\
**Post date:** [May 17, 2021, 11:19pm UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/8 "2021-05-17T23:19:31Z")

</div>

Yes @sangcho. The fastest way Actors can collaborate to build a pandas data-frame that all Actors can access in real-time

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [May 18, 2021, 3:13am UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/9 "2021-05-18T03:13:24Z")

</div>

Hmm if your goal is to modify one shared object among many actors, probably yes in Ray. It is typically not an easy task to modify shared object among many processes since it requires a global lock. If you’d like further optimization you can consider partitioning your data into multiple actors with the expense of get performance (since you need to reduce partitions).

---

<div class="post-metadata">

**Author:** ![psytron](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@psytron](https://discuss.ray.io/u/psytron)\
**Post date:** [May 18, 2021, 3:14am UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/10 "2021-05-18T03:14:51Z")

</div>

ray.get( self.globalActor.get\_df.remote() )  
returns a new data frame every time it is called.  
How can I leverage the “zero-copy” stuff to ensure high speed connection to GlobalActor which has the shared data frame ?

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [May 18, 2021, 3:21am UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/11 "2021-05-18T03:21:27Z")

</div>

If you use this approach, you shouldn’t return the whole dataframe from the actor, but it should return partial data (by adding methods).

> How can I leverage the “zero-copy” stuff to ensure high speed connection to GlobalActor which has the shared data frame ?

This is not trivial with the current Ray support because zero-copy is used for ray objects, and ray objects are immutable. If you’d like to do this, you need to make this object mutable (which is technically possible, but not recommended by us. I remember there’s a flag you can tweak), and then should have a global lock among actors (and it will only work in a single node). You can probably implement a naive global lock using actors as well. [[ray] How to write into numpy arrays in shared memory with Ray? · Issue #6507 · ray-project/ray · GitHub](https://github.com/ray-project/ray/issues/6507#issuecomment-566883219) Note that this is not a recommended solution because it can behave wieldy.

---

<div class="post-metadata">

**Author:** ![psytron](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@psytron](https://discuss.ray.io/u/psytron)\
**Post date:** [May 19, 2021, 3:29am UTC](https://discuss.ray.io/t/many-actors-writing-to-one-object/2112/12 "2021-05-19T03:29:53Z")

</div>

Thank You @sangcho !
