Skip to content

Instantly share code, notes, and snippets.

@miere
Created November 10, 2022 23:01
Show Gist options
  • Save miere/967c2c9aff00c2c6f360e7516a17f95a to your computer and use it in GitHub Desktop.
Save miere/967c2c9aff00c2c6f360e7516a17f95a to your computer and use it in GitHub Desktop.

Poor's man, Stress Tester

Here's a simplistic stress tester that bursts a given service multiple times in parallel.

Disclaimer: This script was designed to be a stress test tool and must be used with extreme care. Use it at your own discretion but warned that the author won't be responsible for any damage it might cause your targetted service. Therefore, be conservative with the numbers or you might put your services down.

How to install

Copy the below script into your Mac or Linux machine and save it as deny-the-service.sh. (Yeah, you might not have the tools available on your Windows, but you can give it a try if you want.)

#!/bin/sh

# FUNCTIONS
burst() {
  C=0
  while [ $C -lt $1 ]
  do
     curl -s "$2" > /dev/null
     printf '.'
     ((C++))
  done
}

# VARIABLES
MACHINES=${MACHINES:-1}
BURST_SIZE=${BURST_SIZE:-10}
URL=${URL?Variable not set}

# MAIN
echo "Bursting $URL"
echo "It will simulate $MACHINES machines performing $BURST_SIZE requests"
echo "Do you wish to continue? [Ctrl+C to abort, ENTER to continue]"

read

I=0
while [ $I -lt $MACHINES ]; do
    burst $BURST_SIZE $URL &
    ((I++))
done

Open the Terminal and type the following command in the folder in which you saved the file.

chmod +x deny-the-service.sh

Running the script

URL=https://google.com MACHINES=10 BURST_SIZE=100 ./deny-the-service.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment