How to achieve processor affinity in containers?
If your system supports SMP (Symmetric multiprocessing) with some combination of multiple physical CPUs, CPU cores, and logical CPUs, you can assign Docker Containers to specific CPU resources.
Example Commands for CPU affinity with Docker Containers
The examples shown here cover the assignment of the mycontainer Docker Container to specific CPU resources when the containers are created with the docker run command. When running commands, you must substitute your Docker Container name and CPU component numbers to suit your environment.
This command will assign the mycontainer Docker Container to the first CPU (CPU0):
# docker run --cpuset 0 /bin/bash mycontainer
Multiple CPUs can be specified. This command will assign the mycontainer Docker Container to CPU 0 and 1:
# docker run --cpuset 0,1 /bin/bash mycontainer
A range of CPUs can be specified. This command will assign the mycontainer Docker Container to CPU 0, 1 and 2:
# docker run --cpuset 0-2 /bin/bash mycontainer
barrymac
Updated on September 18, 2022Comments
-
barrymac over 1 year
I see with kubernetes it's possible to set node affinity for certain workloads. I'm wondering if there are any facilities in the various container technologies, such as docker, rocket etc that allow you to pin processes to cores? or if this is even possible in multitenant environments? Perhaps it would imply a bare metal setup?
-
Ijaz Ahmad over 5 yearsWelcome , you may find more information from docker documentation and kubernetes docs