Skip to content

Instantly share code, notes, and snippets.

@bigomega
Created March 3, 2016 11:03
Show Gist options
  • Save bigomega/4de7dbc395be0e0f33b4 to your computer and use it in GitHub Desktop.
Save bigomega/4de7dbc395be0e0f33b4 to your computer and use it in GitHub Desktop.
A simple bash script to do load (performance) testing of a web service
max="$1"
date
echo "url: $2
rate: $max calls / second"
START=$(date +%s);
get () {
curl -s -v "$1" 2>&1 | tr '\r\n' '\\n' | awk -v date="$(date +'%r')" '{print $0"\n-----", date}' >> /tmp/perf-test.log
}
while true
do
echo $(($(date +%s) - START)) | awk '{print int($1/60)":"int($1%60)}'
sleep 1
for i in `seq 1 $max`
do
get $2 &
done
done
@amousa1968
Copy link

Hello,
I'm trying to test the script and get error see below
$ ./load-test.sh http://google.com

@MParvin
Copy link

MParvin commented Oct 27, 2018

Hello,
I'm trying to test the script and get error see below
$ ./load-test.sh http://google.com

* max=http://google.com

* date
  Tue, Apr 17, 2018 12:17:45 AM

* echo 'url:
  rate: http://google.com calls / second'
  url:
  rate: http://google.com calls / second
  ++ date +%s

* START=1523949465

* true

* awk '{print int($1/60)":"int($1%60)}'
  ++ date +%s

* echo 0
  0:0

* sleep 1
  ++ seq 1 http://google.com
  seq: invalid floating point argument: ‘[http://google.com’](http://google.com%E2%80%99)
  Try 'seq --help' for more information.

* true

* awk '{print int($1/60)":"int($1%60)}'
  ++ date +%s

* echo 1
  0:1

* sleep 1
  ++ seq 1 http://google.com
  can you advise what is wrong?

Your syntax is wrong
Enter max test count before URL
./load-test.sh 100 http://google.com

@sr2ds
Copy link

sr2ds commented Mar 13, 2019

@MParvin and @amousa1968

Test this way:
curl -L https://goo.gl/S1Dc3R | bash -s 20 "http://server.com/api"

Ref: https://medium.com/@bigomega/simple-load-testing-script-in-bash-a8c5a4968dc7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment