How Do I Set vCPU Affinity for Processes Using taskset?
Scenarios
Command taskset allows you to set vCPU affinity for processes running on an ECS to optimize vCPU utilization.
Scenarios
The operations described in this section apply to ECSs running CentOS and EulerOS.
Procedure
- Run the following command to query the information about the vCPUs of the ECS:
The key vCPU parameters are as follows:
- processor specifies the sequence number of a vCPU.
- cpu cores specifies the number of cores of each vCPU.
- Run the following command to check the status of a process, for example, test.sh with PID 23989:
ps aux | grep test.sh
- Run the following command to query the vCPU that process test.sh is running on:
taskset -p PID
For example, run taskset -p 23989.
The returned value is 1 in hexadecimal notation, which is 0001 in binary notation. Each 1 corresponds to a vCPU. 1 indicates that the process runs on the 0th vCPU.
- Run the following command to assign the second vCPU (vCPU 1) to the process:
For example, run taskset -pc 1 23989.
The vCPU ID starts from 0. vCPU 1 indicates the second vCPU. After the proceeding command is executed, test.sh is bound to vCPU 1.
You can also run the following command to bind the process to vCPU 1 at startup:
taskset -c 1 ./test.sh&
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot