对软件进行 性能测试,需要写一个脚本来作驱动。 基本要求如下: (1)每秒钟能并发M次; (2)可以连续不断地执行N秒; #需要并发执行的脚本 driver.pl #每秒并发执行M次的脚本 MperSec.ksh #! /usr/bin/ksh # usage: MperSec.ksh M MperSec= # is how many times per second time{ for ((i=1;i<=$MperSec;i++)) do driver.pl & # & means let the script run in background done wait } #连续执行N秒的脚本 NSecs.ksh #! /usr/bin/ksh #usage: NSecs.ksh N M NSecs= MperSecond= for ((i=1;i<=$NSecs;i++)) do MperSec.ksh& # & means let the script run in background sleep 1 done #How to invoke the whole test process NSecs.ksh 7200 6 |tee test.log
#----------------经过测试的版本---------------------------------- # Solaris 9 ksh #! /usr/bin/ksh # usage: MperSec.ksh M MperSec="" # is how many times per second function func { i=1 while [ "$i" -lt "$MperSec" ] do driver.pl & # & means let the script run in background i=$(($i+1)) done wait } time func #(time func) 2>&1|awk '/real/{print }'
#! /usr/bin/ksh # usage: MperSec.ksh M MperSec="" # is how many times per second function func { i=1 while [ "$i" -lt "$MperSec" ] do ipqueryClient.pl & # & means let the script run in background i=$(($i+1)) done wait } time func #(time func) 2>&1|awk '/real/{print }'
#------------改进方向---------------------- 如果让这些driver.pl在一秒内均匀的触发而不是一下子M个全在后台起来
参考: #-------------------------------------------------------------------------------- start=$(date +%s) dd if=/dev/hdisk2 of=/dev/null bs=8k count=10000 & dd if=/dev/hdisk2 of=/dev/null bs=8k count=10000 & . . . wait end=$(date +%s) echo $(($end-$start))
只能算到秒
#-------------------------------------------------------------------------------- time { dd if=/dev/hdisk2 of=/dev/null bs=8k count=10000 & dd if=/dev/hdisk2 of=/dev/null bs=8k count=10000 & . . . wait ; }
#-------------------------------------------------------------------------------- linux下用proc信息手工计算 单位是 1/100秒
| 代码: | #!/bin/bash start=$(awk '{print }' /proc/$$/stat) dd if=/dev/hdisk2 of=/dev/null bs=8k count=10000 & dd if=/dev/hdisk2 of=/dev/null bs=8k count=10000 & . . . wait sleep 3 & end=$(awk '{print }' /proc/$!/stat) echo $(($end-$start)) kill -9 $!
|
|