CPU 动态节能技术用于降低服务器功耗,通过选择系统空闲状态不同的电源管理策 略,可以实现不同程度降低服务器功耗,更低的功耗策略意味着 CPU 唤醒更慢对性能 影响更大。对于对时延和性能要求高的应用,建议关闭 CPU 的动态调节功能,禁止 CPU 休眠,并把 CPU 频率固定到最高。通常建议在服务器 BIOS 中修改电源管理为 Performance,如果发现 CPU 模式为 conservative 或者 powersave,可以使用 cpupower 设置 CPU Performance 模式,效果也是相当显著的。
CPU 优化建议使用 cpupower 设置 CPU Performance 模式
2019 年 01 月 18 日 - 初稿
阅读原文 - https://wsgzao.github.io/post/cpupower/
扩展阅读
CPU frequency scaling - https://wiki.archlinux.org/index.php/CPU_frequency_scaling
cpufreq 是一个动态调整 cpu 频率的模块,系统启动时生成一个文件夹 /sys/devices/system/cpu/cpu0/cpufreq/,里面有几个文件,其中 scaling_min_freq 代表最低频率,scaling_max_freq 代表最高频率,scalin_governor 代表 cpu 频率调整模式,用它来控制 CPU 频率。
cd /sys/devices/system/cpu/cpu0/cpufreq/
affected_cpus
bios_limit
cpuinfo_cur_freq
cpuinfo_max_freq
cpuinfo_min_freq
cpuinfo_transition_latency
freqdomain_cpus
related_cpus
scaling_available_frequencies
scaling_available_governors
scaling_cur_freq
scaling_driver
scaling_governor
scaling_max_freq
scaling_min_freq
scaling_setspeed
# 查看当前的调节器
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
conservative
# 查看频率信息
cpupower frequency-info
analyzing CPU 0:
driver: acpi-cpufreq
CPUs which run at the same hardware frequency: 0
CPUs which need to have their frequency coordinated by software: 0
maximum transition latency: 10.0 us
hardware limits: 800 MHz - 2.10 GHz
available frequency steps: 2.10 GHz, 2.10 GHz, 2.00 GHz, 1.90 GHz, 1.80 GHz, 1.70 GHz, 1.60 GHz, 1.50 GHz, 1.40 GHz, 1.30 GHz, 1.20 GHz, 1.10 GHz, 1000 MHz, 900 MHz, 800 MHz
available cpufreq governors: conservative userspace powersave ondemand performance
current policy: frequency should be within 800 MHz and 2.10 GHz.
The governor "performance" may decide which speed to use
within this range.
current CPU frequency: Unable to call hardware
current CPU frequency: 2.10 GHz (asserted by call to kernel)
boost state support:
Supported: yes
Active: yes
从 conservative 或者 powersave 切换到 performance 的效果还是杠杠的
# CentOS 安装 kernel-tools
yum install kernel-tools
# Ubuntu 安装 CPU 模式无图形化切换器
apt install cpufrequtils
# cpupower 设置 performance
cpupower frequency-set -g performance
# 查看当前的调节器
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
performance