Last active
October 3, 2021 16:29
-
-
Save browny/0f1f46885f15bdd115fc979d6724166d to your computer and use it in GitHub Desktop.
Run distributed load testing based on GCP and vegeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: bash vegeta.sh <rate> <duration> | |
ACTION="GET http://google.com" | |
DURATION=${2:-5s} | |
RATE=${1:-10} | |
SLAVE_INSTANCES=$(gcloud compute instances list | grep vegeta- | awk '{print $1}') | |
SSH_ARGS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" | |
# --- run cmd on all slave instances in parallel --- | |
SLAVE_INSTANCES_STR=$(echo "$SLAVE_INSTANCES" | paste -sd "," -) | |
echo Run on $SLAVE_INSTANCES_STR | |
SSH_CMD="echo ${ACTION} | vegeta attack -rate=${RATE} -duration=${DURATION} \ | |
-timeout=3s -workers=${RATE} > result.bin" | |
PDSH_SSH_ARGS_APPEND="-q ${SSH_ARGS}" \ | |
pdsh -R ssh -b -w ${SLAVE_INSTANCES_STR} ${SSH_CMD} | |
# --- collect results --- | |
SLAVE_INSTANCES_STR=$(echo "$SLAVE_INSTANCES" | paste -sd ";" -) | |
IFS=';' read -r -a MACHINES <<< "$SLAVE_INSTANCES_STR" | |
for m in "${MACHINES[@]}" | |
do | |
echo fetch from ${m} | |
scp -q ${SSH_ARGS} ${m}:~/result.bin ${m}.bin & | |
done | |
wait | |
# --- report --- | |
RESULT_BINS=$(ls -l | grep vegeta- | awk '{print $NF}' | paste -sd "," -) | |
vegeta report -inputs="${RESULT_BINS}" | |
# --- clean --- | |
rm -rf *.bin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment