Skip to content

Commit

Permalink
docs(nice): Improve the docs around thread priorities (#4281)
Browse files Browse the repository at this point in the history
The old comment was wrong, the new one is correct and adds some
informational links.
  • Loading branch information
Dav1dde authored Nov 22, 2024
1 parent 7f43f6f commit f0026ca
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions relay-server/src/utils/thread_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,18 @@ fn set_current_thread_priority(kind: ThreadKind) {
// Lower priorities cause more favorable scheduling.
// Higher priorities cause less favorable scheduling.
//
// For details see `man setpriority(2)`.
// The relative niceness between threads determines their relative
// priority. The formula to map a nice value to a weight is approximately
// `1024 / (1.25 ^ nice)`.
//
// More information can be found:
// - https://www.kernel.org/doc/Documentation/scheduler/sched-nice-design.txt
// - https://oakbytes.wordpress.com/2012/06/06/linux-scheduler-cfs-and-nice/
// - `man setpriority(2)`
let prio = match kind {
// The default priority needs no change, and defaults to `0`.
ThreadKind::Default => return,
// Set a priority of `10` for worker threads,
// it's just important that this is a higher priority than default.
// Set a priority of `10` for worker threads.
ThreadKind::Worker => 10,
};
if unsafe { libc::setpriority(libc::PRIO_PROCESS, 0, prio) } != 0 {
Expand Down

0 comments on commit f0026ca

Please sign in to comment.