I’m working on a ksh performance script. It takes the following options:
– i (interval time)
– p (messages per interval)
– t (total messages)
So for example: “script -i 1 -p 2 -t 10” means 2 messages per second to a maximum of 10.
This is working, but the script does not yet equally spread the messages over the given interval time. In this example the script should execute the second command after 0.5 seconds, not before.
Is it possible to do this easily?
In short, this is what I have so far:
typeset -i i=0
typeset -i n=0
while [ $i -lt $TOTAAL ]; do
while [ $n -lt $PERINT ]; do
# execute this command
n=$((n+1))
done
i=`expr $i + $PERINT`
# Reset n
n=0
# Wait interval time
sleep $INTERVAL
done
-i: $INTERVAL is an integer (0, 1, 2…) and not calculated in any way. I have done input checks to prevent input the script does not expect.
-t: $TOTAAL
-p: $PERINT
According to serverfault question 340838 Aix 5.3 ships with a separate ksh93 binary in /usr/bin/ksh93.
This will have subsecond
sleepand floating point arithmetic. Watch out for fence-post errors, when calculating the interval.