Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the max. #of simultaneous actors allowed inside python script

I have a remote class like (using ray API)

@ray.remote
class className
   ....

And I want to start 60 or more instances of this class and let them do some work simultaneously.

However, I can't start more than 50 instances of this class at the same time.

How can I change the max. number of threads allowed at any given time from inside of the python script?

like image 277
Our Avatar asked Sep 12 '25 14:09

Our


1 Answers

I believe you need to use Custom Resources. I put a few links of interest below:

  • Specifying required resources
  • Resources with actors
  • Resources keyword argument in the API reference

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.

like image 155
Patol75 Avatar answered Sep 14 '25 04:09

Patol75