连续并发调用http接口
#!/bin/bash rm -rf time.txt diftime.txt shanpao_time.txt for((i=0;i<2;i++)) #循环2次 do { for((j=0;j<3;j++)) #每次并发3个 do { begintime=`date +%s` #当前时间 echo $i$j `date +'%Y%m%d %H:%M:%S' -d @$begintime` 'begin' >> time.txt curl -d "longitude=117.961&latitude=24.6039&minRange=500&maxRange=300000&maxDistance=5000&cityName=厦门市" http://192.168.34.133:8090/queryRoadBookIdByRange.do endtime=`date +%s` echo $i$j `date +'%Y%m%d %H:%M:%S' -d @$endtime` 'end' >> time.txt diftime=$(($endtime - $begintime)) echo $i$j $diftime >> diftime.txt }& done } done
求响应时间 最大值、最小值、平均值
#!/bin/bash # 平均值 cat diftime.txt|awk '{sum+=$2} END {print "Average=", sum/NR}' >> shanpao_time.txt # 最大值 awk 'BEGIN {max = 0} {if ($2+0 > max+0) max=$2} END {print "Max=", max}' diftime.txt >> shanpao_time.txt # 最小值 awk 'BEGIN {min = 65536} {if ($2+0 < min+0) min=$2} END {print "Min=", min}' diftime.txt >> shanpao_time.txt
【结果】