summaryrefslogtreecommitdiff
path: root/forkload
blob: 65365b12beabd8156c9cb3682bfa0d8516aa6066 (plain)
    1 #!/usr/bin/env bash
    2 #
    3 # Forkload performs rudimentary load testing on remote web applications
    4 # Copyright (C) 2014  Aaron Ball
    5 # 
    6 # This program is free software: you can redistribute it and/or modify
    7 # it under the terms of the GNU General Public License as published by
    8 # the Free Software Foundation, either version 3 of the License, or
    9 # (at your option) any later version.
   10 # 
   11 # This program is distributed in the hope that it will be useful,
   12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 # GNU General Public License for more details.
   15 # 
   16 # You should have received a copy of the GNU General Public License
   17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
   18 #
   19 
   20 function get_help {
   21   echo "
   22 The forkload script provides rudimentary load testing for web applications
   23 (anything accessible through curl). This currently tests from a single system,
   24 so a significant bottleneck will occur due to the fact that a load test is
   25 running off of a single nic. As such, Forkload is intended for small scale load
   26 tests (tens to the low hundreds of clients, depending on your nic and the
   27 infrastructure between the testing agent and the destination).
   28 
   29 Arguments:
   30  -d,--dest     Destination to test on
   31  -o,--output   File to output the load test results to (default: forkload.out)
   32  -c,--clients  Number of virtual clients to test with (default: 1)
   33  -h,--help     Prints this help text
   34  "
   35 }
   36 
   37 function main {
   38   argv=(${@})
   39 
   40   out="forkload.out"
   41   clients=1
   42   dest=""
   43 
   44   # Parse arguments
   45   for (( i = 0; i < ${#argv[*]}; i++ )); do
   46     val=${argv[$i]}
   47     if [[ ${val} == "-h" || ${val} == "--help" ]]; then
   48       echo -e "$(get_help)"
   49       exit 0
   50     elif [[ ${val} == "-o" || ${val} == "--output" ]]; then
   51       i=$((i+1))
   52       out=${argv[$i]}
   53     elif [[ ${val} == "-c" || ${val} == "--clients" ]]; then
   54       i=$((i+1))
   55       clients=${argv[$i]}
   56     elif [[ ${val} == "-d" || ${val} == "--dest" ]]; then
   57       i=$((i+1))
   58       dest=${argv[$i]}
   59     fi
   60   done
   61   
   62   # Verify needed variables
   63   if [[ -z ${dest} ]]; then
   64     echo -e "\nPlease specify a destination URL to test (-d,--dest)."
   65     echo -e "See the help text (-h,--help) for more details.\n"
   66     exit
   67   fi
   68 
   69 
   70   # Clean up the out file
   71   :> ${out}
   72 
   73   for (( i = 0; i < ${clients}; i++ )); do
   74     echo "Client ${i}";
   75     # Fork, time the page download
   76     { ( time curl -s ${dest} > /dev/null & ) } 2>> ${out}
   77   done
   78 }
   79 
   80 main "${@}"

Generated by cgit