Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is ray thread safe?

Tags:

python

ray

Assume that a ray actor is defined as below

@ray.remote
class Buffer:
    def __init__(self):
        self.memory = np.zeros(10)

    def modify_data(self, indices, values):
        self.memory[indices] = values

    def sample(self, size):
        indices = np.random.randint(0, 10, size)
        return self.memory[indices]

Is it thread-safe to have other actors call methods of Buffer without any lock?

like image 448
Maybe Avatar asked Dec 24 '19 06:12

Maybe


People also ask

Is time function thread-safe?

The POSIX spec says time is required to be thread safe, and so it is.

Is ZipFile thread-safe?

No, it is not thread-safe in that sense. If you're appending to the same zip file, you'd need a lock there, or the file contents could get scrambled. If you're appending to different zip files, using separate ZipFile() objects, then you're fine.

Is Addrange thread-safe C#?

No it is not thread-safe.


1 Answers

Yes; by default, only one method will execute on a Ray actor at a time. Ordering from concurrent calls is not guaranteed.

With Ray 0.8, you'll be able to set ActorClass.options(max_concurrency=N) to override this serial execution guarantee.

like image 70
richliaw Avatar answered Sep 26 '22 05:09

richliaw