测试从应用到DB的准确的网络延迟
最近几大云厂商把底层的基础设施包装起来后,通过Ping等很难知道真正的网络延迟了,因为通过ping还没到db都返回了,如何知道从应用到db的真正网络延迟呢?
用我的脚本
#!/bin/bash m=1 db_port=$1 db_port=$2 db_user=$3 db_pass=$4 echo "">res.txt t_start=`mysql -h ${db_port} -P ${db_port} -u ${db_user} -p${db_pass} -N -e"select REPLACE(unix_timestamp(current_timestamp(3)),'.','')"` for (( i=1; i < 1000; i++ )) do { time mysql -h ${db_port} -P ${db_port} -u ${db_user} -p${db_pass} -N -e"select 1" > /dev/null ; } 2>> res.txt let "m++" done t_end=`mysql -h ${db_port} -P ${db_port} -u ${db_user} -p${db_pass} -N -e"select REPLACE(unix_timestamp(current_timestamp(3)),'.','')"` t_diff=`expr ${t_end} - ${t_start}` echo "execute "${t_diff}" milliseconds!" awk -F"m" '/real/{print $2}' res.txt | awk '{sum+=$1} END {print "real_Sum=",sum/NR}' awk -F"m" '/user/{print $2}' res.txt | awk '{sum+=$1} END {print "user_Sum=",sum/NR}' awk -F"m" '/sys/{print $2}' res.txt | awk '{sum+=$1} END {print "sys_Sum=",sum/NR}'