The ray processes has low priority

1. Severity of the issue: (select one)
None: I’m just curious or want clarification.
Low: Annoying but doesn’t hinder my work.
Medium: Significantly affects my productivity but can find a workaround.
High: Completely blocks me.

2. Environment:

  • Ray version: 2.44.1
  • Python version: 3.10.12
  • OS: Ubuntu2204
  • Cloud/Infrastructure: Local machine
  • Other libs/tools (if relevant):

3. What happened vs. what you expected:

  • Expected: The process of my workload should have a normal nice value (0) and priority
  • Actual: htop say that the process is low-priority and has a nice value of 15

Here is the code of test.py, which is started using “./test.py”

#!/usr/bin/python3

import ray

ray.init(address='auto')

@ray.remote(num_cpus=32)
class Job:

    def wait(self):
        res = 0
        while True:
            res+=1

#get the commandline arg (app) and run on remote
job = Job.remote()
ray.get(job.wait.remote())

The screenshot of processes of ray, every ray::IDLE has a nice value of 15. I think the ray::IDLE whose CPU usage is 100 is the one that actually running my ray actor

Hi there ISDHN welcome to the Ray community! I think this is Ray’s default behavior of setting a lower priority for idle worker processes. This is done to ensure that active tasks have higher priority access to CPU resources :slight_smile: I think you can edit it to be from 15 to 0 though if you really want to, although I’m not sure if that will potentially have ramifications for performance / resource management. I think you will need to set the nice value via the os nice() function in Python.

class Job:
    def __init__(self):
        # Set the nice value to 0 for this process
        os.nice(0)

Let me know if that works!

Some relevant reading as well:

Thanks, @christina ! However, what really confuse me is that the worker process which is actively execute my task still has a ni value of 15 and is shown as ray::IDLE in htop, leading to insufficient resource for my task.

Besides, in the circumstance that it’s a ray::Job.wait executing my tasks, the ray::Job.wait process also has a ni value of 15, showing in the screenshot below.

What should I do to make my task has a normal prority to get enough resource?

os.nice(0) didn’t work for me, I think it because thate the fuctioin of os.nice(val) is to increase nice value by val rather than set nice value to val. Besides, as a normal user, I can’t decrease the nice value of a process. It’s the root’s privilege to decrease it.

Hi! Yeah sorry this is my first time working with nice values :sweat_smile: okay, I looked around in our Discourse and GH issues, and it seems this person was able to change their nice value here: Setting Ray worker niceness - #2 by lassefschmidt Would this be helpful for your use case?

Thanks! This really help me work out!

1 Like

Yay!! I’m glad! Let me know if there’s anything else I can help ya with and hope you like using Ray :smile: