linux--服务器降频

问题

        这两天在排查一个问题,服务器上同一段代码的性能不稳定,运行时间时长时段,差别很大;

        排查的第一步,将耗时不稳定的代码优化后(使用多线程),运行时间任然忽长忽段;

        排查的第二步,将耗时不稳定的代码,在调用时,连续跑N次,观察现象,时间很稳定,运行都很短;

        排查的第三步,在服务接受到请求后,开始N次任务,每个任务的那段代码,运行稳定,时间很短;

        排查的第四步,在N次任务中夹杂sleep(200),运行时间任然忽长忽段;

        怀疑是服务器主频的问题,修改服务器主频模式后,确实可以运行稳定了;

修改服务器主频

        安装cpufrequtils

root@ubuntu:~# apt-get install cpufrequtils

         根据博客设置服务的CPU模式linux cpu开启性能模式_252371713的博客-CSDN博客_linux高性能模式今天我们的一台数据库服务器,业务研发反馈tp999会不时的彪高,我们查询了各种指标,发现网络重传比较高,同事cpu的load比较高,但是统一宿主机上其他的docker没有重传,因此不是网卡的问题,通过dmesg,发现有cpu降频的相关日志。发现是cpu降频引起的。 查看,系统设置的是非高性能模式。需要设置成高性能模式。相关日志如下:perf: interrupt took too long (166702 > 165147), lowering kernel.perf_event_max_samphttps://blog.csdn.net/wangy_abcsdf2/article/details/106611935

         查看CPU当前主频

root@ubuntu:~# cat /proc/cpuinfo | grep MHz|uniq

        创建cpufrequtils文件,并设置为performance模式;

        cpufrequtils文件内,输入“GOVERNOR="performance"”

root@ubuntu:~# vim /etc/default/cpufrequtils
root@ubuntu:~# systemctl restart cpufrequtils

powersave 节能调速器,CPU以最低频运行
userspace 用户空间调速器。以用户设置的cpu频率运行
conservative  保守调速器。动根据需求进行升/降频
ondemand  随需应变调速器。默认的方式,自动根据需求进行升/降频。
performance

性能调速器,CPU以最大频率运行

         

cpufrequtils | Blog·Tanky WooTanky Woo's Blog, focus on Python, Linux, Gentoo, Mac OS, Vim, Open Source and so on.https://blog.tankywoo.com/2014/05/26/cpufrequtils.html        查看CPU信息

root@ubuntu:~# cpufreq-info
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to [email protected], please.
analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 0.97 ms.
  hardware limits: 800 MHz - 5.00 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 800 MHz and 5.00 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency is 800 MHz (asserted by call to hardware).

        使用cpupower设定

cpupower调整CPU主频 - 裸睡的猪 - 博客园https://www.cnblogs.com/ggzhangxiaochao/p/13948483.html

        增加定时任务,7:30后开启性能模式;17:30后开启节能模式;

        在/etc/crontab文件内,追加下面内容:

30 17 * * * root cpupower -c all frequency-set -g powersave
30 7 * * * root cpupower -c all frequency-set -g performance

         具体的crontab定时任务的使用,参见下文:

每天一个linux命令(50):crontab命令 - peida - 博客园循环运行的例行性计划任务,linux系统则是由 cron (crond) 这个系统服务来控制的。Linux 系统上面原本就有非常多的计划性工作,因此这个系统服务是默认启动的。另外, 由于使用者自己也可https://www.cnblogs.com/peida/archive/2013/01/08/2850483.html

猜你喜欢

转载自blog.csdn.net/liushao1031177/article/details/123652365