射线线程安全吗?
Is ray thread safe?
假设一个ray演员定义如下
@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]
让其他参与者在没有任何锁的情况下调用 Buffer
的方法是否线程安全?
是;默认情况下,一次只会在一个 Ray actor 上执行一个方法。不保证从并发调用中排序。
使用 Ray 0.8,您将能够设置 ActorClass.options(max_concurrency=N)
来覆盖此串行执行保证。
假设一个ray演员定义如下
@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]
让其他参与者在没有任何锁的情况下调用 Buffer
的方法是否线程安全?
是;默认情况下,一次只会在一个 Ray actor 上执行一个方法。不保证从并发调用中排序。
使用 Ray 0.8,您将能够设置 ActorClass.options(max_concurrency=N)
来覆盖此串行执行保证。