mirror of
https://github.com/wassname/ray.git
synced 2026-07-08 22:07:19 +08:00
Support concurrent Actor calls in Ray (#6053)
This commit is contained in:
+35
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user