18_Linux固态硬盘读写性能测试脚本(fio)
18_Linux 固态硬盘读写性能测试脚本(fio)
18.1、配置⽂件
{
"para_ssd": {
"ssd_cpu": {
"cpu_enable": 0,
"core_num": 3,
"time_num": 1,
"time_unit": "d"
},
"ssd_cycle": 3,
"ssd_dd": {
"dd_bs": "M",
"dd_init": 500,
"dd_step": 50,
"dd_fins": 500
},
"ssd_fio": {
"fio_bs": 128,
"fio_direct": 1,
"fio_iodepth": 1,
"fio_ioengine": "libaio",
"fio_runtime": 60,
"fio_size": "500M"
},
"ssd_mem": {
"mem_enable": 0,
"mem_proportion": 0.95,
"mem_total": 1840
},
"ssd_png": {
"display_interval": 20,
"add_yrange": 50,
"set_ytics": 20
},
linux怎么读光盘"ssd_mounted": "/opt/blackbox/data",
"ssd_temp": "25C",
"ssd_type": "/dev/nvme0n1"
}
}
18.2、测试脚本
#!/bin/bash
function ssd_function_template()
{
{
fio -ioengine=${fio_ioengine} -bs=$1KB -direct=${fio_direct} -thread -rw=$2 -filename=${ssd_type} -name="BS-$1KB-$2-test" -iodepth=${fio_iodepth} -runtime=${fio_runtime} -size=${fio_size} -group_reporting
} |tee /tmp/ssd_$2.log
grep $3 /tmp/ssd_$2.log |grep runt >> ${dir_path}/ssd_$2_$1.log
}
function ssd_function()
{
ssd_function_template $1 "read" "read"
ssd_function_template $1 "randread" "read"
ssd_function_template $1 "write" "write"
ssd_function_template $1 "randwrite" "write"
}
function result_ssd_template()
{
local ssd_log=$1
if [ -f "${ssd_log}" ]
then
sed -i 's/=/,/g' ${ssd_log}
sed -i 's/KB\/s/,KB\/s/' ${ssd_log}
local log_bw=/tmp/bw_$2.log
local bw_sum=0
local bw_avg=0
{
awk -F ',' '{print $4}' ${ssd_log} |awk -F '.' '{print $1}'
} > ${log_bw}
local count_line=$(wc -l ${log_bw} |awk '{print $1}')
while read line
do
let bw_sum=bw_sum+$line
done < ${log_bw}
let bw_avg=$bw_sum/$count_line
local log_iops=/tmp/iops_$2.log
local iops_sum=0
local iops_avg=0
{
awk -F ',' '{print $7}' ${ssd_log}
} > ${log_iops}
local count_line=$(wc -l ${log_iops} |awk '{print $1}')
while read line1
do
let iops_sum=iops_sum+$line1
done < ${log_iops}
let iops_avg=$iops_sum/$count_line
echo "$1,bw_avg,$bw_avg KB/S,iops_avg,$iops_avg"
fi
}
function result_ssd()
{
{
result_ssd_template "${dir_path}/ssd_read_$1.log" "read"
result_ssd_template "${dir_path}/ssd_randread_$1.log" "randread"
result_ssd_template "${dir_path}/ssd_write_$1.log" "write"
result_ssd_template "${dir_path}/ssd_randwrite_$1.log" "randwrite"
echo
} |tee -a ${dir_path}/ssd_result.log
cat ${dir_path}/ssd_result.log >> ${source_path}/log/ssd_result.log
}
function ssd_size_setting()
{
if [ "${mem_enable}" -eq 1 ]
then
local bigfile=${ssd_path}/bigfile
[ -f "${bigfile}" ] && rm ${bigfile}
local mem_total=$(jq -r '.para_ssd._total' config.json)
local mem_threshold=$(jq -r '.para_ssd._proportion' config.json) local mem_actual_per=$(df /dev/nvme0n1 |awk '{print $5}'|tail -1)
local mem_actual=0.$(echo "$mem_actual_per" |awk -F "%" '{print $1}')
local mem_compare=$(echo "${mem_actual} < ${mem_threshold}" |bc)
if [ "${mem_compare}" -eq 1 ]
then
local mem_diff=$(echo "${mem_threshold} - ${mem_actual}" |bc)
local mem_diff_size=$(echo "${mem_total} * ${mem_diff}" |bc)
fallocate -l ${mem_diff_size}G ${ssd_path}/bigfile
fi
fi
mem_actual_use=$(df /dev/nvme0n1 |awk '{print $5}'|tail -1)
}
function ssd_depend_package()
{
which bc > /dev/null
if [ "$?" -ne 0 ]
then
local platform=$(uname -m)
if [ "${platform}" == "armv7l" ]
then
dpkg -i ${source_path}/lib/deb_package/bb_bc/bc_1.06.95-9build1_armhf.deb fi
fi
}
function ssd_config_check()
{
# ssd type and ssd mount path detection
if [ -b "${ssd_type}" ]
then
local mounted_path=$(df -h |grep "${ssd_type}" |awk '{print $6}')
if [ -d "${mounted_path}" ]
then
umount -l ${mounted_path}
fi
else
printf "${source_path}/config.json \"para_ssd.ssd_type\" error or not exist\n"
exit 1
fi
}
function ssd_cpu_stress()
{
# cpu N core stress
if [ "${cpu_enable}" -eq 1 ]
then
local cpu_time_num=$(jq -r ".para_ssd.ssd_cpu.time_num" ${source_path}/config.json) local cpu_
time_unit=$(jq -r ".para_ssd.ssd_cpu.time_unit" ${source_path}/config.json) stress-ng -c ${cpu_num} -t ${cpu_time_num}${cpu_time_unit}
fi
}
function ssd_cpu_stress_ctrlc()
{
local pid_stress=$(pgrep stress-ng)
local pid_num=$(echo "${pid_stress}" |wc -l)
if [ "${pid_num}" -gt 0 ]
then
local platform=$(uname -m)
if [ "${platform}" == "armv7l" ]
then
for i in $(echo "$pid_stress")
do
kill -9 $i
done
elif [ "${platform}" == "aarch64" ]
then
sudo killall stress-ng &> ${c_d_null}
fi
fi
printf "$$\n" |xargs kill -9
}
function ssd_test_condition()
{
cat <<-eof
[$(date "+%T")] platform : $(uname -m)
[$(date "+%T")] ssd type : ${ssd_type}
[$(date "+%T")] cpu enable : ${cpu_enable}
[$(date "+%T")] cpu num : ${cpu_num}00%
[$(date "+%T")] mem enable : ${mem_enable}
[$(date "+%T")] mem use : ${mem_actual_use}
[$(date "+%T")] fio bs : ${fio_bs}KB
[$(date "+%T")] fio direct : ${fio_direct}
[$(date "+%T")] fio iodepth : ${fio_iodepth}
[$(date "+%T")] fio ioengine: ${fio_ioengine}
[$(date "+%T")] fio runtime : ${fio_runtime}
[$(date "+%T")] fio size : ${fio_size}
[$(date "+%T")] test temp : ${ssd_temp}
eof
sleep 2
}
function ssd_png_set()
{
which gnuplot > /dev/null
if [ "$?" -eq 0 ]
then
echo "
set terminal png size 1280,720
set output \"${dir_path}/ssd_speed_fio.png\"
set border lc rgb \"orange\"
set multiplot layout 1,2
set grid x,y lc rgb \"orange\"
set datafile sep ','
set key box reverse
set xlabel \"${fio_bs}KB\" font \",15\"
set xrange [-1:$ssd_cycle]
set ytics $ssd_png_ytics
set origin 0,0
set title \"FIO Sequential \($ssd_type\)\n\(Temp: $ssd_temp; CPU: $cpu_enable-$cpu_num; Disk-Use: $mem_actual_use\)\" font \",16\" set ylabel \"KB/s\" font \",15\"
plot \"$dir_path/ssd_read_$1.log\" u 4 smooth csplines w l lc 1 lw 2 t \"Read\",\
\"$dir_path/ssd_write_$1.log\" u 4 smooth csplines w l lc 6 lw 2 t \"Write\"
set origin 0.5,0
set title \"FIO Random \($ssd_type\)\n\(Temp: $ssd_temp; CPU: $cpu_enable-$cpu_num; Disk-Use: $mem_actual_use\)\" font \",16\" set ylabel \"IOps\" font \",15\"
plot \"$dir_path/ssd_randread_$1.log\" u 7 smooth csplines w l lc 1 lw 2 t \"Read\",\
\"$dir_path/ssd_randwrite_$1.log\" u 7 smooth csplines w l lc 6 lw 2 t \"Write\" " |gnuplot
fi
}
function ssd_stress_excute()
{
for ((i=1;i<=${ssd_cycle};i++))
do
ssd_function ${fio_bs} && echo
done
result_ssd ${fio_bs}
ssd_png_set ${fio_bs}
}
function main()
{
local source_path=$(pwd)
local c_d_null=/dev/null
local c_d_zero=/dev/zero
local cpu_enable=$(jq -r ".para_ssd.ssd_cpu.cpu_enable" ${source_path}/config.json)
local cpu_num=$(jq -r ".para_ssd._num" ${source_path}/config.json)
local fio_bs=$(jq -r ".para_ssd.ssd_fio.fio_bs" ${source_path}/config.json)
local fio_direct=$(jq -r ".para_ssd.ssd_fio.fio_direct" ${source_path}/config.json)
local fio_iodepth=$(jq -r ".para_ssd.ssd_fio.fio_iodepth" ${source_path}/config.json)
local fio_ioengine=$(jq -r ".para_ssd.ssd_fio.fio_ioengine" ${source_path}/config.json)
local fio_runtime=$(jq -r ".para_ssd.ssd_fio.fio_runtime" ${source_path}/config.json)
local fio_size=$(jq -r ".para_ssd.ssd_fio.fio_size" ${source_path}/config.json)
local mem_enable=$(jq -r ".para_ssd._enable" ${source_path}/config.json)
local ssd_cycle=$(jq -r ".para_ssd.ssd_cycle" ${source_path}/config.json)
local ssd_path=$(jq -r ".para_ssd.ssd_mounted" ${source_path}/config.json)
local ssd_temp=$(jq -r ".para_ssd.ssd_temp" ${source_path}/config.json)
local ssd_type=$(jq -r ".para_ssd.ssd_type" ${source_path}/config.json)
local dir_date=$(date "+%Y-%m-%d-%H-%M-%S")
local dir_path=${source_path}/log/ssd_speed_${fio_bs}kb_cpu_${cpu_enable}_${cpu_num}00/${dir_date} trap "ssd_cpu_stress_ctrlc" HUP INT QUIT
trap "ssd_cpu_stress_ctrlc" EXIT
[ ! -d ${dir_path} ] && mkdir -p ${dir_path}
ssd_config_check
ssd_depend_package
ssd_size_setting
ssd_test_condition
ssd_cpu_stress &
ssd_stress_excute
}
main
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论