查看当前 CPU 性能模式 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor # 调整设置为 performance 模式,进行验证 cpupower 为保证服务性能应选用 performance 模式,将 CPU 频率固定工作在其支持的最高运行频率上,从而获取最佳的性能,一般都是默认 powersave,可以通过 cpupower frequency-set system/cpu/cpu0/cpufreq/scaling_governor # 查看当前 CPU 使用频率 cat /proc/cpuinfo | grep -i "cpu mhz" # 综合查看方式 cpupower frequency-info # 设置为 performance 模式 cpupower frequency-set -g performance # 注意:如果使用 cpupower frequency-set
2、定位软件处理效率低的问题,即队列的包没有及时处理掉导致了拥塞 首先、检查CPU运行模式,cpupower frequency-info 如果当前运行在powersave模式下,可以将其修改为performance ,提升CPU频率,cpupower frequency-set -g performance。
systemd-journald systemctl stop systemd-journald.socket 关闭rsyslog /usr/sbin/rsyslogd -n 3 机器电源策略 首先对齐电源策略: cpupower
下面让我们先来检查一下: $ cpupower frequency-info analyzing CPU 0: driver: intel_pstate CPUs which run at the 如下所示: $ cpupower frequency-info analyzing CPU 0: driver: acpi-cpufreq CPUs which run at the same hardware 要完成设置,请使用管理员权限运行以下命令: cpupower frequency-set -g performance cpupower frequency-set --min 2300000 --max 2300000 如果你没有 cpupower,可使用以下命令安装: sudo apt-get install linux-tools-common linux-header-`uname -r` -y
cpupower frequency-info --policy analyzing CPU 0: Unable to determine current policy 如果是虚拟机或者云主机,则不需要调整 cat >> /etc/systemd/system/cpupower.service << EOF [Unit] Description=CPU performance [Service] Type =oneshot ExecStart=/usr/bin/cpupower frequency-set --governor performance [Install] WantedBy=multi-user.target
rwxr-xr-x 1 root root 3118 Oct 19 23:20 check-kabi -rw-r--r-- 1 root root 150 Oct 19 23:20 cpupower.config -rw-r--r-- 1 root root 294 Oct 19 23:20 cpupower.service -rw-r--r-- 1 root root 0 Oct 19
可以针对每个核心做调整: echo performance > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor 或者通过 CPU 工具进行调整: cpupower 3)部分硬件可能不支持,调整会出现如下错误: [root@CENTOS7-1 ~]# cpupower frequency-set -g performance Setting cpu: 0 Error
700000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed 3、CPUFreq 的性能测试和调优 Linux 3.1 以后的内核已经将 cpupower-utils 工具集放入内核的tools/power/cpupower 目录中,该工具集当中的 cpufreq-bench 工具可以帮助工程师分析采用 CPUFreq 后对系统性能的影响。
/home/tidb/tidb-ansible ansible-playbook -i hosts.ini deploy_ntp.yml -u tidb -b 目标机器上调整cpufreq # 查看cpupower 调节模式,目前虚拟机不支持,调节10服务器cpupower cpupower frequency-info --governors analyzing CPU 0: available cpufreq governors: Not Available # 配置cpufreq调节模式 cpupower frequency-set --governor performance 目标机器上添加数据盘ext4
home/tidb/tidb-ansible 3 ansible-playbook -i hosts.ini deploy_ntp.yml -u tidb -b 目标机器上调整cpufreq 1 # 查看cpupower 调节模式,目前虚拟机不支持,调节10服务器cpupower 2 cpupower frequency-info --governors 3 analyzing CPU 0: 4 available cpufreq governors: Not Available 5 # 配置cpufreq调节模式 6 cpupower frequency-set --governor performance 目标机器上添加数据盘
不用多说,我知道这台机器不是开发者的通常配置,所以为了使测试尽量逼真,我将 CPU 固定在了其最小的时钟频率上: # 使用调频器的 performance 调速器来更改最大运行频率 sudo cpupower frequency-set -g performance # 将最大频率设定为 CPU 的最低值:1.2GHz sudo cpupower frequency-set -u 1.2GHz 为了准备所有的远程缓存文件
700000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed 3、CPUFreq 的性能测试和调优 Linux 3.1 以后的内核已经将 cpupower-utils 工具集放入内核的tools/power/cpupower 目录中,该工具集当中的 cpufreq-bench 工具可以帮助工程师分析采用 CPUFreq 后对系统性能的影响。
centos-kpatch.x509 │ ├── centos-ldup.x509 │ ├── centossecureboot001.crt │ ├── check-kabi │ ├── cpupower.config │ ├── cpupower.service │ ├── H3Linux_patches │ ├── H3Linux_patches.tar.gz │ ├── kernel-alt-5.10.38
DNS-SD Stack brandbot.service loaded inactive dead Flexible Branding Service cpupower.service
┌──[root@liruilongs.github.io]-[/sys/devices/system/cpu/cpu0] └─$ cpupower frequency-set -g ondemand 查frequency-info信息,发现调频的信息都没有 ┌──[root@liruilongs.github.io]-[/sys/devices/system/cpu/cpu0] └─$ cpupower
如果你是Linux系统的,可以尝试用cpupower frequency-info命令查看一下。可能展示是结果是powersave(节能模式)、performance(性能模式)或其他模式。
service /usr/lib/systemd/system/systemd-quotacheck.service /usr/lib/systemd/system/cpupower.service
CPU 性能模式调整 部分环境下 CPU 运行在节能模式,该模式下性能表现将会不稳定,延迟会出现明显增加,建议使用 CPU 的性能模式获得更稳定的性能表现: cpupower frequency-set
uid 116 188 2150 242 26298 30 35 396 442 496 546 641 767 885 cgroups uid_cpupower
After=systemd-sysctl.service network.target dbus.service Requires=dbus.service polkit.service Conflicts=cpupower.service After=systemd-sysctl.service network.target dbus.service Requires=dbus.service polkit.service Conflicts=cpupower.service