Home | History | Annotate | Download | only in examples
      1 #!/bin/sh
      2 #
      3 # This script runs a series of netperf tests intended to gather the 
      4 # raw material necessary to arrive at estimates for the cost of
      5 # sending and receiving a TCP segment, the cost of each additional byte
      6 # and the cost of each incremental segment.
      7 # 
      8 # there are a number of data points gathered by this script - it might
      9 # run for a considerable length of time.
     10 #
     11 # rick jones 4/99
     12 #
     13 # teach it about processor affinity and the TCP_MSS test
     14 # rick jones 2007-11-08
     15 #
     16 
     17 if [ $# -gt 2 ]; then
     18   echo "try again, correctly -> packet_byte_script hostname [CPU]"
     19   exit 1
     20 fi
     21 
     22 if [ $# -eq 0 ]; then
     23   echo "try again, correctly -> packet_byte_script hostname [CPU]"
     24   exit 1
     25 fi
     26 
     27 # where is netperf
     28 NETPERF_DIR=${NETPERF_DIR:=/opt/netperf2/bin}
     29 
     30 
     31 # at what port will netserver be waiting? If you decide to run
     32 # netserver at a differnet port than the default of 12865, then set
     33 # the value of NETPERF_PORT apropriately
     34 # NETPERF_PORT="-p some_other_portnum"
     35 NETPERF_PORT=${NETPERF_PORT:=""}
     36 
     37 
     38 # The test length in seconds
     39 NETPERF_TIME=${NETPERF_TIME:=30}
     40 
     41 # How accurate we want the estimate of performance: 
     42 #      maximum and minimum test iterations (-i)
     43 #      confidence level (99 or 95) and interval (percent)
     44 NETPERF_STATS=${NETPERF_STATS:="-i 30,3 -I 99,5"}
     45 
     46 # The socket sizes that we will be testing - using -1 will let it 
     47 # be the system default.
     48 NETPERF_SKTS=${NETPERF_SKTS:="-1"}
     49 
     50 # The CPU affinity to be applied
     51 NETPERF_AFFINITY=${NETPERF_AFFINITY:=""}
     52 
     53 # NETPERF_CMD is an amalgam of previous variables
     54 NETPERF_CMD="${NETPERF_DIR}/netperf ${NETPERF_AFFINITY}"
     55 
     56 # if there are two parms, parm one it the hostname and parm two will
     57 # be a CPU indicator. actually, anything as a second parm will cause
     58 # the CPU to be measured, but we will "advertise" it should be "CPU"
     59 
     60 if [ $# -eq 2 ]; then
     61   REM_HOST=$1
     62   LOC_CPU="-c"
     63   REM_CPU="-C"
     64 fi
     65 
     66 if [ $# -eq 1 ]; then
     67   REM_HOST=$1
     68 fi
     69 
     70 MSS=`$NETPERF_CMD -H $REM_HOST -t TCP_MSS -P 0 -v 0`
     71 
     72 # The request,response sizes that we will be using. The netperf
     73 # command parser will treat "1" the same as "1,1" - I use 1,1 to
     74 # remember that it is "request,response"
     75 
     76 # start at one and multiply by two on our way to the MSS
     77 bar=1
     78 while [ $bar -lt $MSS ]
     79 do
     80  NETPERF_REQS="${NETPERF_REQS} $bar"
     81  bar=`expr $bar \* 2`
     82 done
     83 
     84 # and now multiples of the mss and that plus one
     85 for i in 1 2 3
     86 do
     87  bar=`expr $MSS \* $i`
     88  NETPERF_REQS="${NETPERF_REQS} $bar"
     89  NETPERF_REQS="${NETPERF_REQS} `expr $bar + 1`"
     90 done
     91 
     92 bar=1
     93 while [ $bar -lt $MSS ]
     94 do
     95   NETPERF_RESP="${NETPERF_RESP} $bar"
     96   bar=`expr $bar \* 2`
     97 done
     98 
     99 for i in 1 2 3
    100 do
    101  bar=`expr $MSS \* $i`
    102  NETPERF_RESP="${NETPERF_RESP} $bar"
    103  NETPERF_RESP="${NETPERF_RESP} `expr $bar + 1`"
    104 done
    105 
    106 
    107 
    108 # If we are measuring CPU utilization, then we can save beaucoup
    109 # time by saving the results of the CPU calibration and passing
    110 # them in during the real tests. So, we execute the new CPU "tests"
    111 # of netperf and put the values into shell vars.
    112 case $LOC_CPU in
    113 \-c) LOC_RATE=`$NETPERF_CMD $PORT -t LOC_CPU`;;
    114 *) LOC_RATE=""
    115 esac
    116 
    117 case $REM_CPU in
    118 \-C) REM_RATE=`$NETPERF_CMD $PORT -t REM_CPU -H $REM_HOST`;;
    119 *) REM_RATE=""
    120 esac
    121 
    122 # This disables header display
    123 NO_HDR="-P 0"
    124 NO_HDR=""
    125 
    126 for SOCKET_SIZE in $NETPERF_SKTS
    127  do
    128   echo
    129   echo ------------------------------------------------------
    130   echo Testing with the following command line:
    131   # we echo the command line for cut and paste to th database
    132   echo $NETPERF_CMD $NETPERF_PORT -l $NETPERF_TIME -H $REM_HOST -t TCP_RR \
    133        $LOC_CPU $LOC_RATE $REM_CPU $REM_RATE $NETPERF_STATS --\
    134        -s $SOCKET_SIZE -S $SOCKET_SIZE
    135   echo
    136   echo and these settings for send sizes $NETPERF_REQS
    137   echo
    138 
    139   for REQ in $NETPERF_REQS
    140   do
    141    # since we have the confidence interval stuff, we do not
    142    # need to repeat a test multiple times from the shell
    143    $NETPERF_CMD $NETPERF_PORT -l $NETPERF_TIME -H $REM_HOST $NO_HDR \
    144    -t TCP_RR $LOC_CPU $LOC_RATE $REM_CPU $REM_RATE $NETPERF_STATS --\
    145    -r ${REQ},1 -s $SOCKET_SIZE -S $SOCKET_SIZE
    146    NO_HDR="-P 0"
    147   done
    148   echo
    149   echo ------------------------------------------------------
    150   NO_HDR=""
    151   echo Testing with the following command line:
    152   # we echo the command line for cut and paste to th database
    153   echo $NETPERF_CMD $NETPERF_PORT -l $NETPERF_TIME -H $REM_HOST -t TCP_RR \
    154        $LOC_CPU $LOC_RATE $REM_CPU $REM_RATE $NETPERF_STATS --\
    155        -s $SOCKET_SIZE -S $SOCKET_SIZE
    156   echo and these settings for response sizes $NETPERF_RESP
    157   echo
    158   for RESP in $NETPERF_RESP
    159    do
    160    # since we have the confidence interval stuff, we do not
    161    # need to repeat a test multiple times from the shell
    162    $NETPERF_CMD $PORT -l $NETPERF_TIME -H $REM_HOST $NO_HDR \
    163    -t TCP_RR $LOC_CPU $LOC_RATE $REM_CPU $REM_RATE $NETPERF_STATS --\
    164    -r 1,${RESP} -s $SOCKET_SIZE -S $SOCKET_SIZE
    165    NO_HDR="-P 0"
    166  done
    167   echo
    168   echo ------------------------------------------------------
    169   NO_HDR=""
    170   echo Testing with the following command line:
    171   # we echo the command line for cut and paste to th database
    172   echo $NETPERF_CMD $NETPERF_PORT -l $NETPERF_TIME -H $REM_HOST -t TCP_STREAM\
    173        $LOC_CPU $LOC_RATE $REM_CPU $REM_RATE $NETPERF_STATS --\
    174        -s $SOCKET_SIZE -S $SOCKET_SIZE
    175   echo and these settings for response sizes $NETPERF_RESP
    176   echo
    177   for REQ in $NETPERF_REQS
    178    do
    179    # since we have the confidence interval stuff, we do not
    180    # need to repeat a test multiple times from the shell
    181    $NETPERF_CMD $PORT -l $NETPERF_TIME -H $REM_HOST $NO_HDR \
    182    -t TCP_STREAM $LOC_CPU $LOC_RATE $REM_CPU $REM_RATE $NETPERF_STATS --\
    183    -m ${REQ} -s $SOCKET_SIZE -S $SOCKET_SIZE -D
    184    NO_HDR="-P 0"
    185  done
    186 done
    187 
    188 # The test length in seconds for the CRR test, which needs to be
    189 #    longer for a connect/request/response test
    190 
    191 NETPERF_CRR_TIME=${NETPERF_CRR_TIME:=120}
    192 
    193 # now we do the TCP_CRR test
    194 echo
    195 echo ------------------------------------------------------
    196 echo $NETPERF_CMD $NETPERF_PORT -l $NETPERF_CRR_TIME -H $REM_HOST -t TCP_CRR\
    197        $LOC_CPU $LOC_RATE $REM_CPU $REM_RATE $NETPERF_STATS --\
    198        -s $SOCKET_SIZE -S $SOCKET_SIZE
    199 echo
    200 $NETPERF_CMD $NETPERF_PORT -l $NETPERF_CRR_TIME -H $REM_HOST -t TCP_CRR\
    201        $LOC_CPU $LOC_RATE $REM_CPU $REM_RATE $NETPERF_STATS --\
    202        -s $SOCKET_SIZE -S $SOCKET_SIZE
    203