読者です 読者をやめる 読者になる 読者になる

labunix's blog

labunixのラボUnix

yesコマンド版とopenssl版のCPUのストレステストをしてみる。

■yesコマンド版とopenssl版のCPUのストレステストをしてみる。

$ lsb_release -d
Description:	Debian GNU/Linux 8.3 (jessie)

■yesコマンド版CPUのストレステスト

$ cat cpuyes.sh 
#!/bin/bash

CMD="yes"
MAX=$(lscpu | awk '/CPU max MHz/ {print $NF}')
N=$(top -b -n 1 | awk 'BEGIN{n=0}/'${CMD}'/{n+=1}END{print n}')

if [ $N -eq "0" ];then
  awk '/processor/{n+=1}END{print n}' /proc/cpuinfo | \
    seq 1 `xargs` | \
    awk '{print "yes >/dev/null &"}' | \
    sh &
  for n in `seq 1 10`;do 
    N=$(top -b -n 1 | awk 'BEGIN{n=0}/'${CMD}'/{n+=1}END{print n}')
    awk 'BEGIN {printf "S:"}/cpu MHz/{printf "%3.1f,",$NF/'$MAX'*100}' /proc/cpuinfo
    top -b -n 1 | awk 'BEGIN {printf "P:"}/'${CMD}'/{printf "%s,",$(NF-3)}END{printf "\n"}'
    sleep 1
  done
  pkill ${CMD}
fi

■全体の使用率は92.3%を超えない。プロセスは100%となることもある。

$ bash ./cpuyes.sh 
S:92.3,92.3,92.3,92.3,P:96.4,96.4,90.0,90.0,
S:92.3,92.3,92.3,92.3,P:96.6,96.6,96.6,90.2,
S:92.3,92.3,92.3,92.3,P:98.8,98.8,92.7,86.5,
S:92.3,92.3,92.3,92.3,P:91.1,91.1,91.1,91.1,
S:92.3,92.3,92.3,92.3,P:96.6,90.2,90.2,90.2,
S:92.3,92.3,92.3,92.3,P:100.0,94.1,87.8,87.8,
S:92.3,92.3,92.3,92.3,P:96.7,96.7,96.7,96.7,
S:92.3,92.3,92.3,92.3,P:96.6,96.6,96.6,96.6,
S:92.3,92.3,92.3,92.3,P:96.6,96.6,90.2,90.2,
S:92.3,92.3,92.3,92.3,P:96.7,90.2,90.2,90.2,

■openssl版CPUのストレステスト
 RSAのベンチマークのついで。

$ openssl version 
OpenSSL 1.0.1k 8 Jan 2015

■fork元と合わせて5つのopensslプロセスが実行されるスクリプト。

$ cat cpursa.sh 
#!/bin/bash

CMD="openss[l]"
MAX=$(lscpu | awk '/CPU max MHz/ {print $NF}')
N=$(top -b -n 1 | awk 'BEGIN{n=0}/'${CMD}'/{n+=1}END{print n}')

if [ $N -eq "0" ];then
  awk 'BEGIN{n=0}/processor/{n+=1}END{print "openssl speed rsa -multi",n}' /proc/cpuinfo | sh 2>/dev/null & 
  N=1;
  while [ $N -ne 0 ];do 
    N=$(top -b -n 1 | grep openssl | wc -l)
    awk 'BEGIN {printf "S:"}/cpu MHz/{printf "%3.1f,",$NF/'$MAX'*100}' /proc/cpuinfo
    top -b -n 1 | awk 'BEGIN {printf "P:"}/'${CMD}'/{printf "%s,",$(NF-3)}END{printf "\n"}'
    sleep 1
  done
fi

■実行してみる。

$ bash cpursa.sh | tee check.log

■実行結果のログ

$ awk '(!/Forked/&&!/Got:/&&!/compiler:/){print}' check.log 
S:92.3,92.3,92.3,92.3,P:100.0,100.0,89.6,89.6,0.0,
S:92.3,92.3,92.3,92.3,P:96.4,96.4,96.4,90.0,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,96.1,96.1,83.2,0.0,
S:92.3,92.3,92.3,92.3,P:96.4,96.4,96.4,90.0,0.0,
S:92.3,92.3,92.3,92.3,P:97.1,91.0,91.0,78.9,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,100.0,90.0,77.2,0.0,
S:92.3,92.3,92.3,92.3,P:96.3,96.3,96.3,89.9,0.0,
S:92.3,92.3,92.3,92.3,P:99.6,93.4,93.4,68.5,0.0,
S:92.3,92.3,92.3,92.3,P:93.9,93.9,93.9,87.6,0.0,
S:92.3,92.3,92.3,92.3,P:96.3,96.3,96.3,89.9,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,96.3,96.3,89.9,0.0,
S:92.3,92.3,92.3,92.3,P:96.3,96.3,89.9,89.9,0.0,
S:92.3,92.3,92.3,92.3,P:93.7,93.7,93.7,81.2,0.0,
S:92.3,92.3,92.3,92.3,P:92.8,92.8,92.8,86.6,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,96.2,89.8,89.8,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,93.8,93.8,81.3,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,88.7,82.3,82.3,0.0,
S:92.3,92.3,92.3,92.3,P:99.8,93.5,93.5,87.3,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,95.9,95.9,83.1,0.0,
S:92.3,92.3,92.3,92.3,P:96.4,96.4,90.0,90.0,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,95.9,95.9,89.5,0.0,
S:92.3,92.3,92.3,92.3,P:96.4,96.4,96.4,96.4,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,96.2,96.2,89.8,0.0,
S:92.3,92.3,92.3,92.3,P:99.8,93.5,87.3,87.3,0.0,
S:92.3,92.3,92.3,92.3,P:96.2,96.2,89.8,89.8,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,96.2,89.8,77.0,0.0,
S:92.3,92.3,92.3,92.3,P:99.9,93.6,93.6,87.4,0.0,
S:92.3,92.3,92.3,92.3,P:93.3,93.3,87.0,80.8,0.0,
S:92.3,92.3,92.3,92.3,P:96.2,96.2,89.8,89.8,0.0,
S:92.3,92.3,92.3,92.3,P:96.2,96.2,89.8,89.8,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,100.0,93.8,87.5,0.0,
S:92.3,92.3,92.3,92.3,P:93.0,93.0,86.8,86.8,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,98.6,93.1,65.7,0.0,
S:30.8,30.8,30.8,30.8,P:84.1,84.1,84.1,72.9,0.0,
S:92.3,92.3,92.3,92.3,P:96.5,96.5,96.5,90.0,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,100.0,87.6,81.4,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,100.0,94.1,94.1,0.0,
S:30.8,30.8,30.8,30.8,P:92.3,82.0,71.8,61.5,0.0,
S:92.3,92.3,92.3,92.3,P:98.8,92.6,92.6,86.5,0.0,
S:92.3,92.3,92.3,92.3,P:98.3,92.1,86.0,86.0,0.0,
S:30.8,30.8,30.8,30.8,P:99.9,94.4,88.8,66.6,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,96.4,96.4,83.6,0.0,
S:30.8,30.8,30.8,30.8,P:95.2,89.9,74.0,68.8,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,96.4,89.9,83.5,0.0,
S:30.8,30.8,30.8,30.8,P:92.3,86.5,86.5,80.7,0.0,
S:39.7,43.6,41.0,41.0,P:100.0,94.9,94.9,88.6,0.0,
S:92.3,92.3,92.3,92.3,P:96.3,96.3,89.9,89.9,0.0,
S:92.3,92.3,92.3,92.3,P:99.8,93.6,87.3,87.3,0.0,
S:30.8,30.8,30.8,30.8,P:96.3,85.6,80.3,80.3,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,96.5,90.1,90.1,0.0,
S:92.3,92.3,92.3,92.3,P:99.7,93.4,93.4,87.2,0.0,
S:30.8,30.8,30.8,30.8,P:98.8,98.8,82.4,65.9,0.0,
S:92.3,92.3,92.3,92.3,P:94.1,94.1,87.8,87.8,0.0,
S:92.3,92.3,92.3,92.3,P:94.0,94.0,94.0,87.7,0.0,
S:30.8,30.8,30.8,30.8,P:100.0,90.3,84.7,67.7,0.0,
S:92.3,92.3,92.3,92.3,P:100.0,94.0,87.8,87.8,0.0,
OpenSSL 1.0.1k 8 Jan 2015
built on: Mon Feb 29 17:54:55 2016
options:bn(64,64) rc4(16x,int) des(idx,cisc,16,int) aes(partial) blowfish(idx) 
                  sign    verify    sign/s verify/s
rsa  512 bits 0.000036s 0.000003s  27424.3 321428.6
rsa 1024 bits 0.000126s 0.000008s   7965.2 120483.2
rsa 2048 bits 0.001041s 0.000035s    960.7  28815.4
rsa 4096 bits 0.009169s 0.000121s    109.1   8255.2
S:30.8,34.5,30.8,32.8,P: