Taskset is a CPU adjustment tool that can assign system tasks to the specified CPU this article takes nodejs as an example of the first step, query the nodejs process pgrepnode1927719283 step 2, lock the CPUtaskset-pc019277 (where 0 represents CPU0, and so on) taskset-pc119283 step 3, get it done! A small script is provided to automatically bind nodejs processes. assume that there are four nodes and the CPU is quad-core.
Taskset is a CPU adjustment tool that can allocate system tasks to a specified CPU.
This document takes nodejs as an example.
Step 1: query the nodejs process
pgrep node1927719283
Step 2: Lock the CPU
Taskset-pc 0 19277 (0 indicates CPU0, and so on) taskset-pc 1 19283
Step 3: Get it done!
A small script can be attached to automatically bind nodejs processes. assume that there are four nodes, and the CPU is quad-core.
#!/usr/bin/env bashset-enode_porcess=`pgrep node|wc-l`if[$node_process -eq0 ];thenecho“nodejs process not found”exit1elsenode1=`pgrep node |sort|tr-s "\n"" "|awk'{print $1}'`node2=`pgrep node |sort|tr-s "\n"" "|awk'{print $2}'`node3=`pgrep node |sort|tr-s "\n"" "|awk'{print $3}'`node4=`pgrep node |sort|tr-s "\n"" "|awk'{print $4}'`taskset -pc 0 $node1taskset -pc 1 $node2taskset -pc 2 $node3taskset -pc 3 $node4fi
This article is from the "Purple_Grape blog", please be sure to keep this source http://purplegrape.blog.51cto.com/1330104/1252197