快捷搜索:   服务器  PHP  安全  IIS  linux 安全

CENTOS/DEBIAN强制开启CPU睿频 开启CPU高性能模式 低端独服提高性能方法

一般服务器的CPU都支持自动睿频,而服务器的CPU一般默认运行于ondemand模式,会有中断开销,睿频的时候提升下降也是有额外的开销,特别是对于一些低端cpu比如C2350,C2338,N2800这些低价独服的CPU,影响更大。

模式说明:

performance         运行于最大频率
powersave         运行于最小频率
userspace         运行于用户指定的频率
ondemand         按需快速动态调整CPU频率, 一有cpu计算量的任务,就会立即达到最大频率运行,空闲时间增加就降低频率
conservative         按需快速动态调整CPU频率, 比 ondemand 的调整更保守
schedutil         基于调度程序调整 CPU 频率

所以我们需要将CPU调整到performance模式,也就是一直以最大频率运行。

Centos7

# yum install -y cpupowerutils
# cpupower frequency-info
# cat /proc/cpuinfo
#  cpupower frequency-set -g performance


设置之前

  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: 798 MHz - 1.86 GHz
  available frequency steps:  1.86 GHz, 1.60 GHz, 1.33 GHz, 1.06 GHz, 798 MHz
  available cpufreq governors: conservative userspace powersave ondemand performance schedutil
  current policy: frequency should be within 798 MHz and 1.86 GHz.
                  The governor "conservative" may decide which speed to use
                  within this range.
  current CPU frequency: 798 MHz (asserted by call to hardware)
  boost state support:
    Supported: no
    Active: no




设置之后


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: 798 MHz - 1.86 GHz
  available frequency steps:  1.86 GHz, 1.60 GHz, 1.33 GHz, 1.06 GHz, 798 MHz
  available cpufreq governors: conservative userspace powersave ondemand performance schedutil
  current policy: frequency should be within 798 MHz and 1.86 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency: 1.86 GHz (asserted by call to hardware)
  boost state support:
    Supported: no
    Active: no


也可以不安装cpupowerutils而使用系统的设置项目,直接创建一个udev规则
/etc/udev/rules.d/50-scaling-governor.rules

SUBSYSTEM=="module", ACTION=="add", KERNEL=="acpi_cpufreq", RUN+=" /bin/sh -c '
        echo performance > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ' "


注意SUBSYSTEM=="module"和KERNEL=="acpi_cpufreq"这个要根据你的CPU实际情况来


Debian
apt install cpufrequtils

编辑 /etc/default/cpufrequtils 如不存在则创建,

添加 GOVERNOR="performance"

systemctl restart cpufrequtils

您可能还会对下面的文章感兴趣: