cpu压测
常用的对CPU进行压测是通过计算圆周率让CPU高负荷运作,以达到考验CPU计算能力与稳定性的目的。下面介绍两种对CPU进行压测的方法:
第一种:bc计算圆周率
root@master01:~/image# echo "scale=5; 4*a(1)" | bc -l -q
3.14156
第二种:Super PI 计算圆周率小数点后n位所需要的时间
Super PI是利用CPU的浮点运算能力来计算出圆周率π的。
[root@server51 ~]# wget http://linux-wiki.cn/archieve/super_pi.tar.gz
[root@server51 ~]# tar -zxvf super_pi.tar.gz
pi
super_pi
Readme.txt
然后直接运行./super_pi 20
[root@server51 ~]# ./super_pi 20
./super_pi: ./pi: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
出现这个报错,解决办法:
[root@server51 ~]# yum install glibc.i686
然后再运行:
[root@server51 ~]# ./super_pi 20
Version 2.0 of the super_pi for Linux OS
Fortran source program was translated into C program with version 19981204 of
f2c, then generated C source program was optimized manually.
pgcc 3.2-3 with compile option of "-fast -tp px -Mbuiltin -Minline=size:1000 -Mnoframe -Mnobounds -Mcache_align -Mdalign -Mnoreentrant" was used for the
compilation.
------ Started super_pi run : Fri Dec 29 18:48:43 CST 2017
Start of PI calculation up to 1048576 decimal digits
End of initialization. Time= 0.234 Sec.
I= 1 L= 0 Time= 0.672 Sec.
I= 2 L= 0 Time= 0.810 Sec.
= 3 L= 1 Time= 0.882 Sec.
I= 4 L= 2 Time= 0.792 Sec.
I= 5 L= 5 Time= 0.780 Sec.
I= 6 L= 10 Time= 0.798 Sec.
I= 7 L= 21 Time= 0.875 Sec.
I= 8 L= 43 Time= 0.787 Sec.
I= 9 L= 87 Time= 0.770 Sec.
I=10 L= 174 Time= 0.838 Sec.
I=11 L= 349 Time= 0.830 Sec.
I=12 L= 698 Time= 0.800 Sec.
I=13 L= 1396 Time= 0.766 Sec.
I=14 L= 2794 Time= 0.911 Sec.
I=15 L= 5588 Time= 0.785 Sec.
I=16 L= 11176 Time= 0.778 Sec.
I=17 L= 22353 Time= 0.762 Sec.
I=18 L= 44707 Time= 0.802 Sec.
I=19 L= 89415 Time= 0.687 Sec.
End of main loop
End of calculation. Time= 15.967 Sec.
End of data output. Time= 0.081 Sec.
Total calculation(I/O) time= 16.048( 0.746) Sec.
------ Ended super_pi run : Fri Dec 29 18:49:00 CST 2017
现在来解释一下这条命令到底干了什么:
是计算圆周率小数点后2的20次方位。如果换成执行:./super_pi 30 就是计算圆周率小数点后2的30次方位。
输出的是检测的时间,计算的位数越多,检测时间越长,对CPU的考验也越大。
通常一般情况下可以选择104万位(2的20次方)的运算,如果要求较高则可以选择419万位(2的22次方)的运算。如果CPU能够在最高的3355万位(2的25方)的检测中通过,则该CPU将能够在非常苛刻的环境下稳定运行。
可以结合zabbix监控CPU的剩余时间来判断是否通过检测:
zabbix (3.4.2)添加监控项,触发器,让CPU使用超过85%就报警