1# this is a quick and dirty script to run a netperf TCP_RR and 2# TCP_STREAM test concurrently to allow one to see the effect of 3# buffer bloat on latency. We assume that netperf has been compiled 4# with demo-mode enabled via ./configure --enable-demo 5 6NETPERF="/usr/local/bin/netperf" 7 8CHUNK=60 9 10# first, start the TCP_RR test 11RR_START=`date +%s` 12echo "Starting netperf TCP_RR at $RR_START" | tee bloat.log 13# a negative value for the demo interval (-D) will cause netperf to 14# make gettimeofday() calls after every transaction. this will result 15# in more accurate demo intervals once the STREAM test kicks-in, but a 16# somewhat lower transaction rate. not unlike enabling histogram 17# mode. 18$NETPERF -H $1 -l 7200 -t TCP_RR -D -0.5 -v 2 -- -r 1 2>&1 > netperf_rr.out & 19 20# sleep CHUNK seconds 21sleep $CHUNK 22 23# now run the TCP_STREAM test 24 25STREAM_START=`date +%s` 26echo "Starting netperf TCP_STREAM test at $STREAM_START" | tee -a bloat.log 27$NETPERF -H $1 -l `expr $CHUNK \* 2` -t TCP_STREAM -D 0.25 -v 2 -- -m 1K 2>&1 > netperf_stream.out 28STREAM_STOP=`date +%s` 29echo "Netperf TCP_STREAM test stopped at $STREAM_STOP" | tee -a bloat.log 30 31# sleep another CHUNK seconds 32sleep $CHUNK 33 34pkill -ALRM netperf 35RR_STOP=`date +%s` 36echo "Netperf TCP_RR test stopped at $RR_STOP" | tee -a bloat.log 37 38RRDTOOL=`which rrdtool` 39if [ $? -ne 0 ] 40then 41 echo "Unable to find rrdtool. You will have to post-process the results by hand" 42 exit 0 43fi 44 45MIN_TIMESTAMP=`grep Interim netperf_rr.out | head -1 | awk '{print int($10)}'` 46MAX_TIMESTAMP=`grep Interim netperf_rr.out | tail -1 | awk '{print int($10)}'` 47MAX_INTERVAL=`grep Interim netperf_rr.out | awk 'BEGIN{max=0.0} ($6 > max) {max = $6}END{print int(max) + 1}'` 48LENGTH=`expr $MAX_TIMESTAMP - $MIN_TIMESTAMP` 49 50$RRDTOOL create netperf_rr.rrd --step 1 --start $MIN_TIMESTAMP \ 51 DS:tps:GAUGE:$MAX_INTERVAL:U:U RRA:AVERAGE:0.5:1:$LENGTH 52 53# now fill it 54awk -v rrdtool=$RRDTOOL '($1 == "Interim"){printf("%s update netperf_rr.rrd %.3f:%f\n",rrdtool,$10,$3)}' netperf_rr.out | sh 55 56# now post process the tcp_stream test. we could use STREAM_START and 57# STREAM_STOP but these will be just a bit more accurate 58STREAM_MIN_TIMESTAMP=`grep Interim netperf_stream.out | head -1 | awk '{print int($10)}'` 59STREAM_MAX_TIMESTAMP=`grep Interim netperf_stream.out | tail -1 | awk '{print int($10)}'` 60STREAM_MAX_INTERVAL=`grep Interim netperf_stream.out | awk 'BEGIN{max=0.0} ($6 > max) {max = $6}END{print int(max) + 1}'` 61STREAM_LENGTH=`expr $STREAM_MAX_TIMESTAMP - $STREAM_MIN_TIMESTAMP` 62 63$RRDTOOL create netperf_stream.rrd --step 1 --start $STREAM_MIN_TIMESTAMP \ 64 DS:mbps:GAUGE:$STREAM_MAX_INTERVAL:U:U RRA:AVERAGE:0.5:1:$STREAM_LENGTH 65 66# now fill it 67awk -v rrdtool=$RRDTOOL '($1 == "Interim"){printf("%s update netperf_stream.rrd %.3f:%f\n",rrdtool,$10,$3)}' netperf_stream.out | sh 68 69 70# now graph it. we want to make sure the chart is at least 800 pixels 71# wide, and has enough pixels for every data point 72 73WIDTH=$LENGTH 74if [ $WIDTH -lt 800 ] 75then 76 WIDTH=800 77fi 78 79SIZE="-w $WIDTH -h 400" 80 81# we want to find the scaling factor for the throughput, with the goal 82# being that latency can go to the top of the charts and throughput 83# will go half-way up 84 85MAXLATMAXBPS=`$RRDTOOL graph /dev/null \ 86 --start $MIN_TIMESTAMP --end $MAX_TIMESTAMP \ 87 DEF:trans=netperf_rr.rrd:tps:AVERAGE \ 88 CDEF:latency=1.0,trans,/ \ 89 VDEF:maxlatency=latency,MAXIMUM \ 90 DEF:mbps=netperf_stream.rrd:mbps:AVERAGE \ 91 CDEF:bps=mbps,2000000,\* \ 92 VDEF:maxbps=bps,MAXIMUM \ 93 PRINT:maxlatency:"%.20lf" \ 94 PRINT:maxbps:"%.20lf" | sed 1d` 95 96# should I check the completion status of the previous command? 97# probably :) 98 99SCALE=`echo $MAXLATMAXBPS | awk '{print $2/$1}'` 100 101$RRDTOOL graph bloat.svg --imgformat SVG \ 102 $SIZE \ 103 --lower-limit 0 \ 104 --start $MIN_TIMESTAMP --end $MAX_TIMESTAMP \ 105 -t "Effect of bulk transfer on latency to $1" \ 106 -v "Seconds" \ 107 --right-axis $SCALE:0 \ 108 --right-axis-label "Bits per Second" \ 109 DEF:trans=netperf_rr.rrd:tps:AVERAGE \ 110 CDEF:latency=1.0,trans,/ \ 111 LINE2:latency#00FF0080:"TCP_RR Latency" \ 112 DEF:mbps=netperf_stream.rrd:mbps:AVERAGE \ 113 CDEF:bps=mbps,1000000,\* \ 114 CDEF:sbps=bps,$SCALE,/ \ 115 LINE2:sbps#0000FFF0:"TCP_STREAM Throughput" \ 116 VRULE:${STREAM_START}#FF000080:"TCP_STREAM start" \ 117 VRULE:${STREAM_STOP}#00000080:"TCP_STREAM stop" \ 118 --x-grid SECOND:10:SECOND:60:SECOND:60:0:%X 119