When should I assign more than one cpu to actor since there is GIL

  • Low: It annoys or frustrates me for a moment.

as the title suggests, I have two questions

  1. when is it useful to assign more than one cpu to an actor. since all method of the actor will run within the same process, would it be a waste of resources to assign more than one cpu to an actor( since there is the GIL )?

  2. if num_cpus is not defined for an actor, what is the default behavior? I tried creating an actor and do sth then print out the ray.available_resources and found out that the num of cpus does not reduce. is this a bug?

hi @race this is a great question.

The resource requirements (e.g., CPU, GPU, and custom resources) are serving two purposes:

  • Resource accounting during scheduling: i.e. The task will only run on a machine if there are enough resources available to execute the task.
  • Allocate resources and enforce isolation: Today, this only applies to GPU.
    • i.e. Ray doesn’t prevent your task uses more cores than you required;
    • If specifying GPUs, Ray does provide isolation in forms of visible devices (setting the environment variable CUDA_VISIBLE_DEVICES), but it is the task’s responsibility to actually use the GPUs (e.g., through a deep learning framework like TensorFlow or PyTorch).

You can learn more in this wiki:
https://docs.ray.io/en/master/ray-core/tasks/resources.html

So to your question

  1. when is it useful to assign more than one cpu to an actor. since all method of the actor will run within the same process, would it be a waste of resources to assign more than one cpu to an actor( since there is the GIL )?

Usually, you do that if your actor has background threads running, or you want to control the number of concurrent actors on nodes due to other reasons.

  1. if num_cpus is not defined for an actor, what is the default behavior? I tried creating an actor and do sth then print out the ray.available_resources and found out that the num of cpus does not reduce. is this a bug?

That’s a great observation. Actually today the actor requires the node to have at least 1 cpu to schedule, but it releases the cpu resource after it’s being scheduled.
This behavior is a bit confusing indeed, and we are planning to fix it in the upcoming release.

1 Like