def remote_worker_caller(executor: ActorPool, sleep_time: int, number_invokes: int): start = time.time() [ executor.submit(lambda a, v: a.computation.remote(v), sleep_time) for n in range(number_invokes) ] starttime = time.time() - start while (executor.has_next()): executor.get_next() return starttime, time.time() - start
def test_multiple_returns(init): @ray.remote class Foo(object): @ray.method(num_returns=2) def bar(self): return 1, 2 pool = ActorPool([Foo.remote() for _ in range(2)]) for _ in range(4): pool.submit(lambda a, v: a.bar.remote(), None) while pool.has_next(): assert pool.get_next(timeout=None) == [1, 2]
def test_get_next_unordered(init): @ray.remote class MyActor: def __init__(self): pass def f(self, x): return x + 1 def double(self, x): return 2 * x actors = [MyActor.remote() for _ in range(4)] pool = ActorPool(actors) total = [] for i in range(5): pool.submit(lambda a, v: a.f.remote(v), i) while pool.has_next(): total += [pool.get_next_unordered()] assert all(elem in [1, 2, 3, 4, 5] for elem in total)