Process nice/priority on linux

Hi, I just noticed that my Slicer sets itself to a nice value of 19 on linux.
(I noticed this because I let a colleague run some jobs on my desktop.)
What is going on? Is there any way to run it at nice = 0?

Setting background processing priority to low was added 13 years ago, to make GUI more responsive during CLI execution. On Windows, only the processing thread priority is decreased, which is correct behavior. However, on Linux&Mac setpriority function is used, which decreases priority of the entire process.

Could you try if replacing setpriority by pthread_setschedparam works better? Or maybe process prioritization could be removed for Linux&Mac.

What do you experience as a result of running at nice(19)?

Thank you Andras. I was certainly curious about why this decision was made.

What I noticed was launch time. With all cores busy at nice=0, application launch took several minutes.

If I understand your idea, it would be to nice the CLI threads only, and not the UI thread. But I am not sure where this would go. As per your link, I tried changing this in vtkSlicerApplicationLogic::ProcessingThreaderCallback, but it had no effect; the main Slicer thread still runs at nice 19. (Below is my test code.)

  int policy;
  struct sched_param priority;
  int ret;
  ret = pthread_getschedparam (pthread_self(), &policy, &priority);
  priority.sched_priority = 20;
  ret = pthread_setschedparam (pthread_self(), policy, &priority);
  (void)ret; // unused variable

Anyway, might not be worth the effort, because multi-user computers are less common these days.

Does the process priority remain default if you remove priority setting completely? (remove both setpriority calls from vtkSlicerApplicationLogic, I donā€™t think there is any other place where process priority is changed)

Curiously, it does not. I did a quick grep through the Slicer code, and also the CTK app launcher code, and did not find any other obvious location that setpriority() or nice() is called.

As this is not a high priority for me, we may postpone this investigation. But Iā€™m happy to continue if any other user runs into a problem.

1 Like

Hi,

I would also like to have the classic medium priority for SlicerAppReal.
I have the expected behaviour if I set priority to 0 in vtkSlicerApplicationLogic::ProcessingThreaderCallback.

It seems there is a solution to decrease the priority of the processing thread on Linux:

Do you think it would be possible to use this code in vtkSlicerApplicationLogic::ProcessingThreaderCallback ?

Best regards

Thank you for investigating this. Could you submit a pull request to https://github.com/slicer/slicer with all the changes that fixes the priorities for you?

Does this make a difference on modern multicore systems? I did some quick testing with renice-ing Slicer on macOS (even to -20) and I donā€™t see much difference in loading speeds for a large volume, for example.

Hi Andras,

Thanks for this quick reply.
I tried to do a pull request using this code https://stackoverflow.com/a/10876787/1643726 but here is the issue:

This code runsā€¦ but it does not change the priority of the thread because the scheduling policy is SCHED_OTHER which does not allow to change the priority. We could change the scheduling policy before changing thread priority but it requires root privileges and it can be quite dangerous: https://stackoverflow.com/a/3663250/1643726

So here is a pull request which just removes the code responsible of the VERY LOW priority:

But it should not be necessary to merge this branch: until now I donā€™t have problems caused by the VERY LOW priority of SlicerAppReal, so we should keep it if it fixed the UI performances in the pastā€¦

Best regards