Basic direct actor call support in Python (#5991)

This commit is contained in:
Eric Liang
2019-10-28 22:09:04 -07:00
committed by GitHub
parent 4c4342c165
commit b89cac976a
20 changed files with 283 additions and 62 deletions
+45 -11
View File
@@ -15,6 +15,15 @@ class Actor(object):
ray.get([small_value.remote() for _ in range(n)])
@ray.remote
class Client(object):
def __init__(self, server):
self.server = server
def small_value_batch(self, n):
ray.get([self.server.small_value.remote() for _ in range(n)])
@ray.remote
def small_value():
return 0
@@ -54,17 +63,17 @@ def main():
def get_small():
ray.get(value)
timeit("single core get calls", get_small)
timeit("single client get calls", get_small)
def put_small():
ray.put(0)
timeit("single core put calls", put_small)
timeit("single client put calls", put_small)
def put_large():
ray.put(arr)
timeit("single core put gigabytes", put_large, 8 * 0.1)
timeit("single client put gigabytes", put_large, 8 * 0.1)
@ray.remote
def do_put_small():
@@ -74,7 +83,7 @@ def main():
def put_multi_small():
ray.get([do_put_small.remote() for _ in range(10)])
timeit("multi core put calls", put_multi_small, 1000)
timeit("multi client put calls", put_multi_small, 1000)
@ray.remote
def do_put():
@@ -84,17 +93,17 @@ def main():
def put_multi():
ray.get([do_put.remote() for _ in range(10)])
timeit("multi core put gigabytes", put_multi, 10 * 8 * 0.1)
timeit("multi client put gigabytes", put_multi, 10 * 8 * 0.1)
def small_task():
ray.get(small_value.remote())
timeit("single core tasks sync", small_task)
timeit("single client tasks sync", small_task)
def small_task_async():
ray.get([small_value.remote() for _ in range(1000)])
timeit("single core tasks async", small_task_async, 1000)
timeit("single client tasks async", small_task_async, 1000)
n = 10000
m = 4
@@ -104,21 +113,21 @@ def main():
submitted = [a.small_value_batch.remote(n) for a in actors]
ray.get(submitted)
timeit("multi core tasks async", multi_task, n * m)
timeit("multi client tasks async", multi_task, n * m)
a = Actor.remote()
def actor_sync():
ray.get(a.small_value.remote())
timeit("single core actor calls sync", actor_sync)
timeit("single client actor calls sync", actor_sync)
a = Actor.remote()
def actor_async():
ray.get([a.small_value.remote() for _ in range(1000)])
timeit("single core actor calls async", actor_async, 1000)
timeit("single client actor calls async", actor_async, 1000)
n_cpu = multiprocessing.cpu_count() // 2
a = [Actor.remote() for _ in range(n_cpu)]
@@ -130,7 +139,32 @@ def main():
def actor_multi2():
ray.get([work.remote(a) for _ in range(m)])
timeit("multi core actor calls async", actor_multi2, m * n)
timeit("multi client actor calls async", actor_multi2, m * n)
a = Actor._remote(is_direct_call=True)
def actor_sync_direct():
ray.get(a.small_value.remote())
timeit("single client direct actor calls sync", actor_sync_direct)
a = Actor._remote(is_direct_call=True)
def actor_async_direct():
ray.get([a.small_value.remote() for _ in range(1000)])
timeit("single client direct actor calls async", actor_async_direct, 1000)
n = 5000
n_cpu = multiprocessing.cpu_count() // 2
actors = [Actor._remote(is_direct_call=True) for _ in range(n_cpu)]
clients = [Client.remote(a) for a in actors]
def actor_multi2_direct():
ray.get([c.small_value_batch.remote(n) for c in clients])
timeit("multi client direct actor calls async", actor_multi2_direct,
n * len(clients))
if __name__ == "__main__":