Support concurrent Actor calls in Ray (#6053)

This commit is contained in:
Eric Liang
2019-11-04 01:14:35 -08:00
committed by GitHub
parent fbad6f543b
commit 8485304e83
21 changed files with 287 additions and 86 deletions
+35 -1
View File
@@ -326,6 +326,26 @@ class ActorClass(object):
"""
return self._remote(args=args, kwargs=kwargs)
def options(self, **options):
"""Convenience method for creating an actor with options.
Same arguments as Actor._remote(), but returns a wrapped actor class
that a non-underscore .remote() can be called on.
Examples:
# The following two calls are equivalent.
>>> Actor._remote(num_cpus=4, max_concurrency=8, args=[x, y])
>>> Actor.options(num_cpus=4, max_concurrency=8).remote(x, y)
"""
actor_cls = self
class ActorOptionWrapper(object):
def remote(self, *args, **kwargs):
return actor_cls._remote(args=args, kwargs=kwargs, **options)
return ActorOptionWrapper()
def _remote(self,
args=None,
kwargs=None,
@@ -335,6 +355,7 @@ class ActorClass(object):
object_store_memory=None,
resources=None,
is_direct_call=None,
max_concurrency=None,
name=None,
detached=False):
"""Create an actor.
@@ -354,6 +375,8 @@ class ActorClass(object):
resources: The custom resources required by the actor creation
task.
is_direct_call: Use direct actor calls.
max_concurrency: The max number of concurrent calls to allow for
this actor. This only works with direct actor calls.
name: The globally unique name for the actor.
detached: Whether the actor should be kept alive after driver
exits.
@@ -365,6 +388,16 @@ class ActorClass(object):
args = []
if kwargs is None:
kwargs = {}
if is_direct_call is None:
is_direct_call = False
if max_concurrency is None:
max_concurrency = 1
if max_concurrency > 1 and not is_direct_call:
raise ValueError(
"setting max_concurrency requires is_direct_call=True")
if max_concurrency < 1:
raise ValueError("max_concurrency must be >= 1")
worker = ray.worker.get_global_worker()
if worker.mode is None:
@@ -452,7 +485,8 @@ class ActorClass(object):
actor_id = worker.core_worker.create_actor(
function_descriptor.get_function_descriptor_list(),
creation_args, meta.max_reconstructions, resources,
actor_placement_resources, is_direct_call, detached)
actor_placement_resources, is_direct_call, max_concurrency,
detached)
actor_handle = ActorHandle(
actor_id,