Skip to content

Instantly share code, notes, and snippets.

@brunoluiz
Last active April 3, 2018 20:31
Show Gist options
  • Save brunoluiz/08fde7cbe7b0635c96002cdc9759ecbb to your computer and use it in GitHub Desktop.
Save brunoluiz/08fde7cbe7b0635c96002cdc9759ecbb to your computer and use it in GitHub Desktop.
#!/bin/bash
CURL="/usr/bin/curl"
export LC_ALL=en_US.UTF-8
# Configs
URL="$1"
REQUESTS=$(cat $2)
OUTPUT_PATH="./out"
OUTPUT="$OUTPUT_PATH/results-$(date +%s).csv"
TRIES=1000
SCALE=5
WAIT_REQ=0.5
# Variables
count=1;
total_connect=0
total_start=0
total_time=0
# Create dir if it does not exist
mkdir -p $OUTPUT_PATH;
# Response headers
echo "URL;Request;Response;Connect Time (ms);Start Transfer Time (ms);Total Time (ms)" >> $OUTPUT
for LINE in $REQUESTS;
do
# Stop after the configured number of TRIES
if [ "$count" -gt "$TRIES" ]
then
break
fi
# Execute CURL and print its times
result=`$CURL -H "Host:production-cargo-falcon.omniplat.io" -s -w ";%{time_connect};%{time_starttransfer};%{time_total}" $URL -X POST -d $LINE`
csv_line=$(echo "$URL;$LINE;$result" | tr -d '\n')
echo $csv_line >> $OUTPUT
echo "Progress: $count/$TRIES"
# Accumulate results
count=$((count+1))
# Wait for next request
sleep $WAIT_REQ
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment