Skip to content

Priority Queue

Priority Queue on Linux Servers

We can set priorities for Linux commands using nice and renice commands and by setting the processes PR (priority value)

There is a more in depth guide for niceness HERE.

Why?

We will sometimes need to update the priority queue for long-running processes that are time sensitive or processes we would prefer to have finish faster.

Nice Values

Nice

nice is a number range from -20 to +19, the lower the higher priority, that determines a processes' priority. This number is set to 0 by default for new processes and all processes with the same priority are grouped together and run sequentially.

You can run a command while setting the nice command.

nice -n niceness-value command args
e.g.
nice -n -20 bin/magento s:s:d -f -j4 en_US en_GB
This would run the standard magento deploy with the highest nice priority.

Renice

We can also adjust niceness value of a pre queued process using the renice command. This can be done using either the process id (PID) or using the user id

  1. Using PID
    renice -n -20 -p 1000
    
  2. Using UID
    renice -n -20 -u root
    

Setting default values

Default nice values can be set in /etc/security/limits.conf

The syntax is:

#<domain> <type> <item> <value>
For nice purposes the headings can be translated to:
<username> <hard|soft> priority <nice value>
e.g. To enforce top priority for ec user:
ec hard priority -20

Addendum

You can get more information on these functions using man.

man nice
man renice

Using HTOP

If when checking processes using HTOP you think that a process is running slowly, you can dynamically update the nice value using HTOP.

To increase the priority you can use F7 to minus the nice value.

Additional Reading

  1. IBM Linux Process Execution Priority
  2. Linux Scheduler