loadtest

Loadtest code
code format="bash"
 * 1) !/usr/bin/bash


 * 1) This script is to tie together the various components to load test
 * 2) different zone configurations using a handy menu
 * 3) Author: Chad Crider

RED="\E[31m" END_RED="\E[0m" BLUE="\E[34m" END_BLUE="\E[0m" BOLD="\033[1m" END_BOLD="\033[0m" UL="\033[4m" END_UL="\033[0m"
 * 1) Foreground colors; define ansi mode

BASEDIR="/export/home/sysvxct" ZONECLONE="/usr/vern/zone.clone.chad" ZONEADMIN="$BASEDIR/zoneadmin.vern.010510" ZONEADM="/usr/sbin/zoneadm" ZONEMGR="/export/home/sysvxct/zonemgr" LOADDIR="$BASEDIR/load" VIRTSIZE="1x1" GOLDEN1FOUND="${RED}${BOLD}NO${END_RED}${END_BOLD}" FILESDIR="/ztools/zones/testing_results/merge_test"
 * 1) Some file locations
 * 1) ZONEFLOGSTATUS="STOPPED"
 * 2) EATMEMORYSTATUS="STOPPED"
 * 1) FILESDIR="/usr/vern/app.response.time/chad"

$ZONEMGR -a halt -n golden1 -F >/dev/null 2>&1 ZONECOUNT=`$ZONEADMIN list | grep gold | wc -l | sed -e 's/ //g'`
 * 1) Halt golden1 so it doesn't get included in the zone count and used for testing

if awk -F= '{print $2}' | awk -F\( '{print $1}'` -ne "0" ; then        echo "You have to be root to use this feature."        sleep 2        display_menu fi
 * 1) Check if user is root

function random_sampling {
 * 1) Function to determine random sampling

COUNT=0 PROG="/usr/vern/app.response.time/sample_zones" SAMPLESIZE="1" if $SAMPLESIZE -eq "0" ; then SAMPLESIZE="1"; fi if  $SAMPLESIZE -gt "2" ; then SAMPLESIZE="2"; fi echo "$SAMPLESIZE zone(s) will be sampled in this run." ESTIMATED_TIME=`echo "$SAMPLESIZE * 10" | bc` echo -e "Estimated time for this run is approx. ${BLUE}$ESTIMATED_TIME${END_BLUE} minutes." echo -e "Proceed? [y/n] \c " read CHOICE if $CHOICE = "y" ; then while $COUNT < $SAMPLESIZE ; do                NUMBER=$(($RANDOM%$ZONECOUNT+1)) $ZONECOUNT -lt 100 && NUMBER=$(printf %02d $NUMBER) $ZONECOUNT -gt 99 && NUMBER=$(printf %03d $NUMBER) ZONE2SAMPLE="gold$NUMBER" echo -e "\nSampling zone $ZONE2SAMPLE. Please be patient." zlogin $ZONE2SAMPLE $PROG
 * 1) Pick random zones to sample
 * 1) SAMPLESIZE=`echo "$ZONECOUNT / 20" | bc`

# See which options were used for this test to construct filename accordingly OUTPUT_FILE=`ls /vm/zones/$ZONE2SAMPLE/root/tmp/app.response.time.*` $CPULOAD = "no" &&  $MEMORYLOAD = "no"  && NEW_OUTPUT_FILE="$OUTPUT_FILE.$ZONECOUNT.zones.baseline.no.loads" $CPULOAD = "yes" &&  $MEMORYLOAD = "no"  && NEW_OUTPUT_FILE="$OUTPUT_FILE.$ZONECOUNT.zones.cpuloadonly" $CPULOAD = "no" &&  $MEMORYLOAD = "yes"  && NEW_OUTPUT_FILE="$OUTPUT_FILE.$ZONECOUNT.zones.memoryloadonly" $CPULOAD = "yes" &&  $MEMORYLOAD = "yes"  && NEW_OUTPUT_FILE="$OUTPUT_FILE.$ZONECOUNT.zones.cpu.and.memory.load"

# Grab the file and move it to /usr/vern/app.response.time/chad/ mv "$OUTPUT_FILE" "$NEW_OUTPUT_FILE" FILE=${NEW_OUTPUT_FILE##*/} mv /vm/zones/$ZONE2SAMPLE/root/tmp/$FILE $FILESDIR/$FILE

let COUNT=COUNT+1 done else display_menu fi }
 * 1) random_sampling

function get_size { echo "Enter new size to use for the master zone golden1." echo "Valid size configs are: 1x1, 1x2, 1x4, 2x2, 2x4, 2x8, 4x4, 4x8, 4x16, 4x32, 8x32, 16x16, 16x32 or 64x64" echo -e "Size to use: \c " read VIRTSIZE if $VIRTSIZE =~ ^[0-9]{1,2}x[0-9]{1,2}$ ; then echo "Valid size given, proceeding..." echo "Creating golden1 as $VIRTSIZE. Please be patient" $ZONEADMIN create -t sparse -z golden1 -s $VIRTSIZE -i 3.24.143.239 -e nxge0 -p /vm/zones else echo "$VIRTSIZE is INVALID. Please select again." echo "" get_size fi }
 * 1) get_size

function check_golden1 { if ! -d /vm/zones/golden1 ; then echo "Required zone golden1 does not exist." echo "This is the master zone that gets cloned." echo -e "Would you like me to create golden1 now? [y/n] \c " read CREATEGOLDEN1 if $CREATEGOLDEN1 = "n" ; then echo "You chose not to create golden1 and this process" echo "cannot continue without it. Exiting." sleep 3 display_menu elif $CREATEGOLDEN1 = "y" ; then echo "golden1 will be built as a $VIRTSIZE." echo -e "Do you wish to customize golden1? [y/n] \c " read CHOICE if $CHOICE = "y" ; then get_size else echo "Creating golden1 as $VIRTSIZE. Please be patient" $ZONEADMIN create -t sparse -z golden1 -s $VIRTSIZE -i 3.24.143.239 -e nxge0 -p /vm/zones display_menu fi       fi else echo -e "Zone golden1 found. Proceeding...\n" GOLDEN1FOUND="Yes" fi }
 * 1) check_golden1

function create_zones {
 * 1) Function to create the zones

echo -e "How many zones do you want to clone? \c " read NUM_ZONES export NUM_ZONES }
 * 1) create_zone

function reset_zones {
 * 1) Function to Halt and Delete all cloned zones

echo "" echo "Zones to be deleted:" $ZONEADM list | grep -v global echo "" if $? -eq "1" ; then # No zones present, kick back to menu echo "No zones present on this system. Exiting." sleep 2 display_menu fi
 * 1) Check if there are any zones present

$ZONEMGR -a only -n "haltall" echo "All zones halted, including golden1."
 * 1) Halt all zones including golden1

echo -e "Do you want to delete ALL zones, including golden1? [y/n] \c " read ANSWER
 * 1) Delete all zones

if $ANSWER = "y" ; then for i in `$ZONEMGR -a list | grep -v NAME | grep -v global | awk '{print $2}'`; do               $ZONEMGR -a del -n $i -F rm -rf /vm/zones/$i echo "Zone $i COMPLETELY removed." done elif $ANSWER = "n" ; then echo -e "Delete clones only and leave golden1? [y/n] \c " read CHOICE if $CHOICE = "y" ; then for i in `$ZONEMGR -a list | grep -v NAME | grep -v global | grep -v golden | awk '{print $2}'`; do                       $ZONEMGR -a del -n $i -F rm -rf /vm/zones/$i echo "Zone $i COMPLETELY removed." done elif $CHOICE = "n" ; then echo "Nothing done. Exiting back to menu" sleep 2 display_menu fi       display_menu else display_menu fi echo "All requested zones have been removed." }
 * 1) reset_zones

function get_file_count { FILE_COUNT=`ls $FILESDIR/$TEST 2>/dev/null | wc -l | sed -e 's/ //g'` if $FILE_COUNT -ne "7" ; then echo "Only $FILE_COUNT files found, should be 7. Testing not done.  Aborting." sleep 1 display_menu fi }
 * 1) Function to get file count
 * 1) get_file_count

function format_data { cd $FILESDIR OUTPUTDIR="/tmp" BASELINE_FILE="baseline.csv" CPULOADONLY_FILE="cpuloadonly.csv" MEMORYLOADONLY_FILE="memoryloadonly.csv" CPUANDMEMORY_FILE="cpuandmemoryload.csv" COMBINED_FILE="$OUTPUTDIR/combined_report.csv" clear echo -e " Choose which test you'd like to prepare a CSV file for:
 * 1) Function to convert finished data to CSV tables

1 )    Baseline 2 )     CPU only 3 )    Memory only 4 )     CPU and Memory 5 )    Combine the 4 previous reports        into one big CSV file

q )    Return to menu

Selection [1-5]: \c " read CHOICE

case "$CHOICE" in       1 )     TEST="*.baseline.*"                get_file_count                paste `ls $TEST | sort -t . -k 6 -n` | tr "\t" "," > $OUTPUTDIR/$BASELINE_FILE                format_data                ;;        2 )     TEST="*.cpuloadonly" get_file_count paste `ls $TEST | sort -n -t. -k 6` | tr "\t" "," > $OUTPUTDIR/$CPULOADONLY_FILE format_data ;;       3 )     TEST="*.memoryloadonly"                get_file_count                paste `ls $TEST | sort -n -t . -k 6` | tr "\t" "," > $OUTPUTDIR/$MEMORYLOADONLY_FILE                format_data                ;;        4 )     TEST="*.cpu.and.memory.*" get_file_count paste `ls $TEST | sort -n -t. -k 6` | tr "\t" "," > $OUTPUTDIR/$CPUANDMEMORY_FILE format_data ;;       5 )     TEST="*.csv"                # See which steps are done/need to bedone                 -e $OUTPUTDIR/$BASELINE_FILE  || echo "Baseline report not run.  Please run step 1 before proceeding."; sleep 1                 -e $OUTPUTDIR/$CPULOADONLY_FILE  || echo "Cpuloadonly report not run.  Please run step 2 before proceeding."; sleep 1                 -e $OUTPUTDIR/$MEMORYLOADONLY_FILE  || echo "Memoryloadonly report not run.  Please run step 3 before proceeding."; sleep 1                 -e $OUTPUTDIR/$CPUANDMEMORY_FILE  || echo "Cpuandmemoryload report not run.  Please run step 4 before proceeding."; sleep 1                # Now make the file                #echo -e "Above data is in the following format:\n\n                -=/ BASELINE /=-                        -=/ CPU Only /=-                        -=/ Memory Only /=-                     -=/ CPU and Memory /=-\n|-10---20-406080100---120||-1020406080100---120||-1020406080100---120||-1020406080100---120|\n" >> $COMBINED_FILE -e $OUTPUTDIR/$BASELINE_FILE &&  -e $OUTPUTDIR/$CPULOADONLY_FILE  &&  -e $OUTPUTDIR/$MEMORYLOADONLY_FILE  &&  -e $OUTPUTDIR/$CPUANDMEMORY_FILE  && echo -e "Below data is in the following format:\n\n                -=/ BASELINE /=-                        -=/ CPU Only /=-                        -=/ Memory Only /=-                     -=/ CPU and Memory /=-\n|-10---20-406080100---120||-1020406080100---120||-1020406080100---120||-1020406080100---120|" > $COMBINED_FILE && paste `ls $OUTPUTDIR/$BASELINE_FILE $OUTPUTDIR/$CPULOADONLY_FILE $OUTPUTDIR/$MEMORYLOADONLY_FILE $OUTPUTDIR/$CPUANDMEMORY_FILE` | tr "\t" "," >> $COMBINED_FILE || format_data #echo -e "\nAbove data is in the following format:\n\nBaseline - CPU Only - Memory Only - CPU and Memory\nWith sample sizes of 10,20,40,60,80,100,120 for each test above" >> $COMBINED_FILE format_data ;;       q )     display_menu;;        * )     echo "Invalid Selection" sleep 1 format_data ;; esac }
 * 1) format_data

function change_output_dir { echo -e "Enter the new output dir (full path): \c " read NEW_FILESDIR -d $NEW_FILESDIR && FILESDIR="$NEW_FILESDIR" || echo "Invalid directory.  Value unchanged."; sleep 1 }
 * 1) Function to change the output directory

function display_menu { ZONECOUNT=`$ZONEADMIN list | grep gold | wc -l | sed -e 's/ //g'`
 * 1) Function to display the menu


 * 1) Check statuses
 * 2) grep "sleep 3600" | grep -v grep`  && EATMEMORYSTATUS="${RED}RUNNING${END_RED}" || EATMEMORYSTATUS="STOPPED"

if -e /tmp/cpuload ; then CPULOAD="yes" ZONEFLOGSTATUS="${RED}RUNNING${END_RED}" else CPULOAD="no" ZONEFLOGSTATUS="STOPPED" fi if -e /tmp/memoryload ; then MEMORYLOAD="yes" EATMEMORYSTATUS="${RED}RUNNING${END_RED}" else MEMORYLOAD="no" EATMEMORYSTATUS="STOPPED" fi
 * 1) See if CPULOAD or MEMORYLOAD were left on and set flags accordingly

clear

echo -e " Zone Clone and Load Test Tool

golden1 zone present:\t\t\t$GOLDEN1FOUND Current # of running zones on system:   $ZONECOUNT Current output directory: $FILESDIR

Please choose an option to continue:

c )    ${UL}${BOLD}C${END_UL}reate clones of zone golden1 h )     ${UL}${BOLD}H${END_UL}alt and Delete all cloned zones b )    ${UL}${BOLD}B${END_UL}oot all Zones p )     Load ${UL}${BOLD}P${END_UL}rocessors (zoneflogcpu) $ZONEFLOGSTATUS m )    Load ${UL}${BOLD}M${END_UL}emory (eatmemory) $EATMEMORYSTATUS r )     ${UL}${BOLD}R${END_UL}eboot all zones t )    Kick off ${UL}${BOLD}T${END_UL}esting o )     Change the ${UL}${BOLD}O${END_UL}utput directory f )    ${UL}${BOLD}F${END_UL}ormat data to CSV tables (one per test)

q)     ${UL}${BOLD}q${END_UL}uit

Selection [c,h,b,p,m,r,t,o,f]: \c " read SELECTION

case "$SELECTION" in       c )                # Create clones of zone golden1                check_golden1                $ZONECLONE $NUM_ZONES                echo "Booting all zones"                $ZONEMGR -a only -n "bootall"                $ZONEMGR -a halt -n golden1 -F >/dev/null 2>&1                display_menu                ;;        h ) # Halt and Delete all cloned zones check_golden1 reset_zones display_menu ;;       b )                # Boot all zones                check_golden1                $ZONEMGR -a only -n "bootall"                display_menu                ;;        p ) # Load Processors check_golden1 if $ZONEFLOGSTATUS = "${RED}RUNNING${END_RED}" ; then echo -e "Stop zoneflogcpu now? [y/n] \c " read CHOICE if $CHOICE = "y" ; then $LOADDIR/zoneflogcpu stop ZONEFLOGSTATUS="STOPPED" CPULOAD="no" rm /tmp/cpuload display_menu else display_menu fi               fi                echo -e "Start zoneflogcpu now? [y/n] \c " read CHOICE if $CHOICE = "y" ; then $LOADDIR/zoneflogcpu -v start ZONEFLOGSTATUS="${RED}RUNNING${END_RED}" CPULOAD="yes" touch /tmp/cpuload display_menu else display_menu fi               ;; m )               # Load Memory                check_golden1                if  grep "sleep 3600" | grep -v grep` ; then                        echo -e "Stop eatmemory on all zones? [y/n] \c "                        read CHOICE                        if  $CHOICE = "y" ; then                                ps -ef | grep sleep | grep -v grep | awk '{print $2}' | xargs kill                                MEMORYLOAD="no"                                EATMEMORYSTATUS="STOPPED"                                rm /tmp/memoryload                                display_menu                        else                                display_menu                        fi                else                        echo -e "Start eatmemory now on all zones? [y/n] \c "                        read CHOICE                        if  $CHOICE = "y" ; then                                $ZONEMGR -a runcmd -n "all" -X "/usr/vern/load/eatmemory &" MEMORYLOAD="yes" EATMEMORYSTATUS="${RED}RUNNING${END_RED}" touch /tmp/memoryload display_menu else display_menu fi               fi                ;; r )               # Reboot all zones                check_golden1                $ZONEMGR -a runcmd -n "all" -X "reboot" -F &                display_menu                ;;        t ) # Kick off testing steps check_golden1 random_sampling display_menu ;;       o )     change_output_dir                display_menu                ;;        f ) # Convert finished data to CSV tables format_data ;;       q )                exit 1;;        * ) echo "Invalid Selection" sleep 1 display_menu;; esac }
 * 1) display_menu

check_golden1 display_menu code
 * 1) Initial check for golden1 before proceeding
 * 1) Display inital menu

eatmemory
code format="bash"
 * 1) !/bin/ksh


 * 1) The following perl command can be used to eat around 20 MB of memory,
 * 2) and to stay that way for an hour; we run a "ps" command to check that
 * 3) it worked,

perl -e '$a = "A" x 500000000; sleep 3600'
 * 1) perl -e '$a = "A" x 10_000_00000; sleep 3600' &


 * 1) ps -o pid,vsz,rss,args -p 2808
 * 2)  PID  VSZ  RSS COMMAND
 * 3) 2808 22440 21104 perl -e $a = "A" x 10_000_000; sleep 3600

code
 * 1) To consume a different number of megabytes, change the "10_000_000"
 * 2) value to half your desired bytes (eg, 50_000_000 will eat around 100 MB).

zoneflogcpu
code format="bash"
 * 1) !/usr/bin/ksh
 * 2) zoneflogcpu - Flog the CPUs in non-global zones. Solaris 10.
 * 3) This generates CPU load in each non-global zone by running
 * 4)  multiple CPU bound perl processes in each.
 * 5) 25-Mar-2005, ver 0.80
 * 6) USAGE: zoneflogcpu { start | stop }
 * 7)    eg,
 * 8)        zoneflogcpu start
 * 9)        zoneflogcpu stop
 * 10) Standard Disclaimer: This is freeware, use at your own risk.
 * 11) 25-Mar-2005   Brendan Gregg   Created this.
 * 1)        zoneflogcpu start
 * 2)        zoneflogcpu stop
 * 3) Standard Disclaimer: This is freeware, use at your own risk.
 * 4) 25-Mar-2005   Brendan Gregg   Created this.
 * 1) Standard Disclaimer: This is freeware, use at your own risk.
 * 2) 25-Mar-2005   Brendan Gregg   Created this.
 * 1) 25-Mar-2005   Brendan Gregg   Created this.

MAX_CPUs=1     # Maximum number of CPUs in a zone. # We run this many processes in each zone.

PATH=/usr/bin:/usr/sbin verbose=0 if "$1" == "-v" ; then shift; verbose=1 fi action="$1" if "$action" == "start" ; then ### Define Start Command cmd="perl -e 'while (1) { \$cpuflog++ }' &" count=$MAX_CPUs elif "$action" == "stop" ; then ### Run Stop Command ps -eo pid,args | awk '/cpuflo[g]/ { print $1 }' | xargs kill if (( verbose == 1 )); then echo "stopped on all zones."; fi       exit 0 else ### Usage echo >&2 "USAGE: $0 { start | stop }" exit 1 fi
 * 1)  Process Arguments
 * 1)  Process Arguments

for zone in `zoneadm list` do if "$zone" = "global" ; then continue; fi        if (( verbose == 1 )); then echo "$zone, \c"; fi        typeset -i num=0 while (( num <= count )); do               zlogin -S $zone "$cmd" num=num+1 done if (( verbose == 1 )); then echo "started."; fi done code
 * 1)  Run Start Commands
 * 1)  Run Start Commands

random.1.sh
code format="bash"
 * 1) !/bin/ksh
 * 2) Cool little script to generate random numbers in shell script:

export INTERVAL=1 export COUNT=1
 * 1) This script generates 64 bit random numbers.
 * 2) To get 32 bit, change count= to 6 and "u8" to "u4"

export LOG=while_loop_test.log

export CTR=0 while [ true ] do if [ ${CTR} -ge ${COUNT} ] then echo "****************************" echo "Read disk log for read I/O" echo "***************************" cat ${LOG} echo "Clean Up" exit fi          n=`dd if=/dev/urandom bs=1 count=8 2>/dev/null | od -t u8 | awk 'NR==1 {print $2}'` echo "Random numner is: $n" echo "#--- write number to disk log" echo "Random numner is: $n" >> ${LOG} echo "#--- write number to log" >> ${LOG}
 * 1)              > ${LOG}

CTR=$(expr ${CTR} + 1) sleep ${INTERVAL} done code

sample_zones
code format="bash"
 * 1) !/usr/bin/bash

BAR_WIDTH=50 BAR_CHAR_START="[" BAR_CHAR_END="]" BAR_CHAR_EMPTY="." BAR_CHAR_FULL="=" BRACKET_CHARS=2 LIMIT=100

DATE=`date +"%m-%d-%Y-%H-%M"` OUTPUT_FILE="app.response.time.test.`uname -n`.$DATE" LOOPS=20 COUNT=1

print_progress_bar {       # Calculate how many characters will be full. let "full_limit = ((($1 - $BRACKET_CHARS) * $2) / $LIMIT)"

# Calculate how many characters will be empty. let "empty_limit = ($1 - $BRACKET_CHARS) - ${full_limit}"

# Prepare the bar. bar_line="${BAR_CHAR_START}" for ((j=0; j<full_limit; j++)); do               bar_line="${bar_line}${BAR_CHAR_FULL}" done

for ((j=0; j<empty_limit; j++)); do               bar_line="${bar_line}${BAR_CHAR_EMPTY}" done

bar_line="${bar_line}${BAR_CHAR_END}"

printf "Processing loop $COUNT of $LOOPS %3d%% %s" $2 ${bar_line} }

MAX_PERCENT=100 let INCREMENTS=$(($MAX_PERCENT / $LOOPS)) START=5 $LOOPS -lt 20 && START=1 for ((i=$START; i<=MAX_PERCENT; i=i+$INCREMENTS)); do       # # ... Or run some other commands ... #               print_progress_bar ${BAR_WIDTH} ${i} echo -en "\r"
 * 1) Here is a sample of code that uses it.

#for i in $(eval echo {1..$LOOPS}); do       #while  $COUNT -le $LOOPS ; do                { time -p /usr/vern/app.response.time/random.1.sh > /dev/null 2>&1; } 2> time.txt cat time.txt | awk '/real/ {print $2}' >> /tmp/$OUTPUT_FILE print_progress_bar ${BAR_WIDTH} ${i} echo -en "\r" let COUNT=COUNT+1 #done done

echo ""

exit code