mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-22 07:38:12 +08:00
Adds cpu affinity for the workers. Courtesy of the optional psutil module.
This commit is contained in:
@@ -132,6 +132,49 @@ of the cache connection you want to use::
|
||||
.. tip::
|
||||
Django Q uses your `SECRET_KEY` to encrypt task packages and prevent task crossover. So make sure you have it set up in your Django settings.
|
||||
|
||||
cpu_affinity
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Sets the number of processor each worker can use. This does not affect auxiliary process like the sentinel or monitor and is only useful for tweaking the performance of very high traffic clusters.
|
||||
The default is to use all available processors for all workers. The affinity number has to be higher than zero and less than the total number of processors to have any effect::
|
||||
|
||||
# processor affinity example.
|
||||
|
||||
4 processors, 4 workers, cpu_affinity: 1
|
||||
|
||||
worker 1 cpu [0]
|
||||
worker 2 cpu [1]
|
||||
worker 3 cpu [2]
|
||||
worker 4 cpu [3]
|
||||
|
||||
4 processors, 4 workers, cpu_affinity: 2
|
||||
|
||||
worker 1 cpu [0, 1]
|
||||
worker 2 cpu [2, 3]
|
||||
worker 3 cpu [0, 1]
|
||||
worker 4 cpu [2, 3]
|
||||
|
||||
8 processors, 8 workers, cpu_affinity: 3
|
||||
|
||||
worker 1 cpu [0, 1, 2]
|
||||
worker 2 cpu [3, 4, 5]
|
||||
worker 3 cpu [6, 7, 0]
|
||||
worker 4 cpu [1, 2, 3]
|
||||
worker 5 cpu [4, 5, 6]
|
||||
worker 6 cpu [7, 0, 1]
|
||||
worker 7 cpu [2, 3, 4]
|
||||
worker 8 cpu [5, 6, 7]
|
||||
|
||||
|
||||
In some cases, setting the cpu affinity for your workers can lead to performance improvements, especially if the load is high and consists of many repeating small tasks.
|
||||
Start with an affinity of 1 and work your way up. You will have to experiment with what works best for you.
|
||||
Usually a low affinity number has the most effect. Which could be positive or negative depending on your particular project.
|
||||
|
||||
.. note::
|
||||
|
||||
The `cpu_affinity` setting requires the optional `psutil <https://github.com/giampaolo/psutil>`__ module by Giampaolo Rodola'.
|
||||
You can install it with `pip install psutil`.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user