24.3. 使用 tuna 工具调优 CPU
tuna 命令可以管理单个 CPU。通过使用 tuna 工具,您可以执行以下操作:
- 隔离 CPU
- 在指定 CPU 上运行的所有任务都移至下一个可用 CPU。通过将 CPU 从所有线程的关联性掩码中删除来隔离 CPU ,使其不可用。
- 包括 CPU
- 允许任务在指定的 CPU 上运行。
- 恢复 CPU
- 将指定的 CPU 恢复到之前的配置。
先决条件
-
tuna工具已安装。如需更多信息 ,请参阅安装 tuna 工具。
流程
列出所有当前运行的进程:
# ps ax | awk 'BEGIN { ORS="," }{ print $1 }' PID,1,2,3,4,5,6,8,10,11,12,13,14,15,16,17,19在
tuna界面中显示线程列表:# tuna show_threads -t 'thread_list from above cmd'根据您的场景,使用以下命令管理具有以下操作之一的进程的 CPU 关联性:
# tuna [command] --cpus cpu_list-
cpu_list 参数是一个用逗号分开的 CPU 号列表,如--
cpus 0,2。 -
要将特定 CPU 添加到当前的 cpu_list 中,请使用例如
--cpus +0。
-
cpu_list 参数是一个用逗号分开的 CPU 号列表,如--
根据您的场景,执行以下操作之一:
要隔离一个 CPU,请输入:
# tuna isolate --cpus cpu_list要包括一个 CPU,请输入:
# tuna include --cpus cpu_list
要使用具有四个或更多处理器的系统,使所有
ssh线程都在 CPU0和1上运行,以及 CPU2和3中的所有http线程:# tuna move --cpus 0,1 -t ssh*# tuna move --cpus 2,3 -t http\*
验证
通过显示当前配置来验证应用的更改:
# tuna show_threads -t ssh* pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 855 OTHER 0 0,1 23 15 sshd# tuna show_threads -t http\* pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 855 OTHER 0 2,3 23 15 http如需更多信息,请参阅系统中的
/proc/cpuinfo文件和tuna (8)手册页。