May 26, 2016

Load Test And Performance Test on Squid Proxy Server

Subject:  Shell Script based test tool for Squid Proxy Server


In my endeavour to achieve the best performance  from squid proxy server and for doing a load test, created a shell script tool. The script uses Apache HTTP Server Benchmarking tool.  Basically this script shall best run on
  • Bash version 4.3.0 & above. This is because the same script observed some syntax error in bash ver. 3.1.17. 
  • Apache HTTP Server Benchmarking tool version 2.3 and above. The option -r [ - Don't exit on socket receive errors] was missing in version below 2.3,
Named it as LinTool
  1 #!/bin/bash
  2 #
  3 #
  4 BlackBg='\033[40m'
  5 echo -e "\n$BlackBg\e[1;92mLinTool - A Network Traffic based Load Test and Performance based test tool for Proxy Server \e[0m\n\e[0m "
  6 #functions
  7 PreCond ()
  8 {
  9    if type ab > /dev/null 2>&1
 10       then
 11            echo -ne '  Checking compatibility .....                     (33%)\r';
 12            sleep 1;
 13            echo -ne '  Checking compatibility .............             (66%)\r';
 14            sleep 1;
 15            echo -ne '  Checking compatibility ....................... [ \e[0;32mOK\e[0m ]   (100%)\r';
 16            echo -ne '\n';
 17            echo -e "\n " ;
 18            return 0;
 19        else
 20            echo -ne '  Checking compatibility .....                     (33%)\r';
 21            sleep 1;
 22            echo -ne '  Checking compatibility .............             (66%)\r';
 23            sleep 1;
 24            echo -ne '  Checking compatibility ....................... [ \e[0;31mFailed\e[0m ]   (100%)\r';
 25            echo -ne '\n';
 26            echo -e >&2 "\n\e[1;95m  Alert:- To run this script install the  "Apache HTTP Server Benchmarking Tool" package.\n  Please install the pre-requisite and     the execute the script.\n  LinTool Aborted...!!!\n\e[0m";
 27            exit;
 28    fi;
 29 }
 30 RequestNumber ()
 31 {
 32    read -p  "^[[34m  Enter Number of requests to perform for the benchmarking session: `echo $'\n  => '` ^[[0m  " Req;
 33    if  ! [[ "$Req" =~ ^[0-9]+$ ]];
 34         then
 35            echo -e "\n\e[1;31m  Invalid Value:- Enter only Numeric Integers.\n  Please re-enter or CTRL+C to quit.\n\e[0m";
 36            RequestNumber;
 37         else
 38            # 0 = true
 39            return 0;
 40    fi;
 41 }
 42 ConcurrentNumber ()
 43 {
 44    read -p  " ^[[34m  Enter Number of multiple Concurrent requests to perform at a time: `echo $'\n  => '` ^[[0m "  Con;
 45    if  [[ "$Con" =~ ^[0-9]+$ ]];
 46         then
 47             if (( $Req < $Con  ));
 48                 then
 49                     echo -e "\n\e[1;31m  Invalid Value:- Number of multiple concurrent request must be less than Number of Requests to perform.\n  Please re-enter o    r CTRL+C to quit.\n\e[0m";
 50                     ConcurrentNumber;
 51                  else
 52                     return 0;
 53             fi;
 54          else
 55              echo -e "\n\e[1;31m  Invalid Value:- Enter only Numeric Integers.\n  Please re-enter or CTRL+C to quit.\n\e[0m";
 56              ConcurrentNumber;
 57          fi;
 58 }
 59 Domains ()
 60 {
 61    read -p " ^[[34m  Enter a vallid domain in the format www.somedomain.com: `echo $'\n  => '` ^[[0m " DM;
 62    domreg1='^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,})';
 63    ipreg1='(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])';
 64    if ! [[ "$DM" =~ $domreg1 || "$DM" =~ $ipreg1 ]];
 65         then
 66            echo -e "\n\e[1;31m  Invalid Value:- Not a valid Domain name. Domain format [www.somedomain.com]\n  Please re-enter or CTRL+C to quit.\n\e[0m";
 67            Domains;
 68         else
 69            return 0;
 70    fi;
 71 }
 72
 73 ProxyPort ()
 74 {
 75    read -p "^[[34m  Enter Proxy IP & Port [IP:PORT]: `echo $'\n  => '` ^[[0m " PP;
 76    if ! [[ "$PP" =~ ^[0-9]{1,3}[.]{1}[0-9]{1,3}[.]{1}[0-9]{1,3}[.]{1}[0-9]{1,3}[\:]{1}[1-9]{3,}$ ]];
 77         then
 78           echo -e "\n\e[1;31m  Invalid Value:- Enter the Proxy and Port to access the internet. Format [IP:PORT].\n  Please re-enter or CTRL+C to quit.\n\e[0m";
 79           ProxyPort;
 80     else
 81           read  -p "^[[34m  Does your proxy require Authentication? [Y/N]: ^[[0m" response;
 82           respreg='^([yY][eE][sS]|[yY])$';
 83           if [[ "$response" =~ $respreg ]];
 84              then
 85                  read -p  "^[[34m  Enter User Name: ^[[0m" username;
 86                  echo -n "^[[34m  Password: ^[[0m" ;
 87                  read -s password;
 88                  echo -e "\n ";
 89                  return 1;
 90              else
 91                  echo -e "\n ";
 92                  return 0;
 93           fi;
 94                         fi;
 95 }
 96 #main
 97 if PreCond $0;
 98    then
 99       if RequestNumber $0;
100          then
101             if ConcurrentNumber $0;
102                then
103                   if Domains $0;
104                      then
105                         if ProxyPort $0;
106                         LEN=$(echo $DM |
107                         awk -F/ '{print $2}' |
108                         while read STR ; do expr  "${STR}" : '.*';
109                         done ;)
110                            then
111                               if [[ $LEN == 0 ]];
112                                  then
113                                      ab  -q -S -r -X $PP -n $Req -c $Con http://$DM/;
114                                  else
115                                      ab  -q -S -r -X $PP -n $Req -c $Con http://$DM;
116                               fi;
117                            else
118                               if [[ $LEN == 0 ]];
119                                  then
120                                     ab -q -S -P $username:$password -r -X $PP -n $Req -c $Con http://$DM/;
121                                  else
122                                     ab -q -S -P $username:$password -r -X $PP -n $Req -c $Con http://$DM;
123                               fi;
124                         fi;
125                   fi;
126             fi;
127       fi;
128 fi;
I hope this does helps the community....