调优系统
管理员可以基于多种用例工作负载调整设备设置,优化系统性能。tuned守护进程会利用反应特定工作负载要求的调优配置文件,以动态/静态方式调优。
配置静态调优
tuned守护进程会在服务启动时或选择新的调优配置文件应用系统设置。静态调优会对配置文件中由tuned在运行时应用的预定义kernel参数进行配置。
配置动态调优
tuned监视系统活动,根据运行行为变化调整设置。
[root@workstation ~]# yum install tuned -y
[root@workstation ~]# systemctl enable --now tuned
[root@workstation ~]# systemctl status tuned
● tuned.service - Dynamic System Tuning Daemon
Loaded: loaded (/usr/lib/systemd/system/tuned.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-07-19 10:03:01 EDT; 1min 0s ago
Docs: man:tuned(8)
man:tuned.conf(5)
man:tuned-adm(8)
Main PID: 7507 (tuned)
CGroup: /system.slice/tuned.service
└─7507 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
Jul 19 10:03:00 workstation systemd[1]: Starting Dynamic System Tuning Daemon...
Jul 19 10:03:01 workstation systemd[1]: Started Dynamic System Tuning Daemon.
选择调优配置文件
tuned提供配置文件为:
性能提升型配置文件:
tuned-adm 用于更改tuned守护进程设置。
#确定当前活动调优的配置文件
[root@workstation ~]# tuned-adm active
Current active profile: virtual-guest
#列出可用配置文件
[root@workstation ~]# tuned-adm list
Available profiles:
- balanced - General non-specialized tuned profile
- desktop - Optimize for the desktop use-case
- hpc-compute - Optimize for HPC compute workloads
- latency-performance - Optimize for deterministic performance at the cost of increased power consumption
- network-latency - Optimize for deterministic performance at the cost of increased power consumption, focused on low latency network performance
- network-throughput - Optimize for streaming network throughput, generally only necessary on older CPUs or 40G+ networks
- powersave - Optimize for low power consumption
- throughput-performance - Broadly applicable tuning that provides excellent performance across a variety of common server workloads
- virtual-guest - Optimize for running inside a virtual guest
- virtual-host - Optimize for running KVM guests
Current active profile: virtual-guest
#切换活动配置文件为更符合系统调优要求的其他配置文件
[root@workstation ~]# tuned-adm profile throughput-performance
[root@workstation ~]# tuned-adm active
Current active profile: throughput-performance
#为系统推荐调优配置文件
[root@workstation ~]# tuned-adm recommend
virtual-guest
#回复当前配置文件所作设置更改
[root@workstation ~]# tuned-adm off
[root@workstation ~]# tuned-adm active
No current active profile.
相对优先级
不同进程重要性不同。进程调度程序可以配置为针对不同进程采用不同调度策略。常规系统上运行大都数进程调度策略称为SCHED_OTHER。
由于并非所有进程都同等重要,可以通过策略设置优先级称为进程nice值。对于任何进程,可以组织成40种不同级别的nice值。
nice级别值介于-20(最高)到19(最低)之间。默认情况,进程将继承父进程nice级别,通常为0,nice级别越高,优先级越低。
设置nice级别和权限
为很占CPU资源的进程设置较低的nice级别可能会对同一系统上运行的其他进程的性能造成负面影响,只有root用户可以降低nice级。
Tasks: 101 total, 1 running, 100 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 995896 total, 605916 free, 134648 used, 255332 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 678000 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7893 root 20 0 161880 2192 1556 R 0.7 0.2 0:00.11 top
7703 root 20 0 0 0 0 S 0.3 0.0 0:02.34 kworker/0:0
1 root 20 0 128152 6708 4176 S 0.0 0.7 0:01.66 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.20 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
6 root 20 0 0 0 0 S 0.0 0.0 0:00.42 kworker/u256:0
top命令可通过交互方式查看和管理进程。默认配置显示便于nice级别与优先级两列NI显示进程nice值,PR显示调度优先级
显示nice值
[root@workstation ~]# ps axo pid,comm,nice,cls --sort=-nice
PID COMMAND NI CLS
32 khugepaged 19 TS
31 ksmd 5 TS
1 systemd 0 TS
2 kthreadd 0 TS
3 ksoftirqd/0 0 TS
6 kworker/u256:0 0 TS
7 migration/0 - FF
8 rcu_bh 0 TS
9 rcu_sched 0 TS
11 watchdog/0 - FF
13 kdevtmpfs 0 TS
15 khungtaskd 0 TS
启动具有不同nice级别的进程
#开启一个后台作业
[root@workstation ~]# sha1sum /dev/zero &
[1] 7897
#新进程nice值从0继承(shell进程ni值为0,是作业的父进程)
[root@workstation ~]# ps -o pid,comm,nice 7897
PID COMMAND NI
7897 sha1sum 0
[root@workstation ~]# nice -n 15 top&
[1] 7940
#更改nice值
[root@workstation ~]# ps -o pid,comm,nice 7940
PID COMMAND NI
7940 top 15
[root@workstation ~]# renice -n 19 7940
7940 (process ID) old priority 15, new priority 19