I believe you need to use Custom Resources. I put a few links of interest below:
The idea is that you first provide a dictionary to the resources
argument of ray.init
. Each key of the dictionary corresponds to the name you give to a custom resource. The value associated with the key is the maximum resource number available for this specific resource; whichever value you put, you can think of it as representing 100%. It is usually helpful to put values that relate to the execution of specific tasks/actors. For example, in your case, you want to have 50 actors from the same class executing at the same time, so 50 makes the most sense.
ray.init(resources={'Custom': 50})
Now, resources
is also an argument for @ray.remote
. It similarly requires a dictionary, equivalent to the one provided to ray.init
. So let's say you have your class definition:
@ray.remote
class MyClass(object):
# Methods
You can limit the number of Actors concurrently executing for this class by providing a custom resource value which will compare to the one defined in ray.init
. The value must be an integer, except if it is lower than one; dividing the value given in @ray.remote
by the corresponding one in ray.init
and multiplying by 100 gives you the percentage of this custom resource that each task/actor will require. In your case, you want to set a limit of 50 actors, and we set Custom
to 50 in ray.init
. Hence, if each Actor requires a value of Custom
equals to 1, then only 50 Actors will be able to run at the same time.
@ray.remote(resources={'Custom': 1})
class MyClass(object):
# Methods
No more than 50 actors of this class can now concurrently execute.