Skip to content

Instantly share code, notes, and snippets.

@patsanch
Forked from jddonovan/stress-test.sh
Created March 31, 2018 01:08
Show Gist options
  • Save patsanch/a8a03a901aec4d8d50c791abd5576a80 to your computer and use it in GitHub Desktop.
Save patsanch/a8a03a901aec4d8d50c791abd5576a80 to your computer and use it in GitHub Desktop.

Revisions

  1. @jddonovan jddonovan revised this gist Mar 27, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions stress-test.sh
    Original file line number Diff line number Diff line change
    @@ -17,10 +17,10 @@ Params:
    Defaults to localhost:8080
    -c conccurency: how many process to spawn
    Defaults to 1
    Defaults to 4
    -r number of requests per process
    Defaults to 10
    Defaults to 100
    -h show this help text
    @@ -60,7 +60,7 @@ shift $((OPTIND-1))
    #### Main

    for i in `seq 1 $CONCURRENCY`; do
    curl -s "$ADDRESS?[1-$REQUESTS]" & pidlist="$pidlist $!"
    curl --silent --output /dev/null -s "$ADDRESS?[1-$REQUESTS]" & pidlist="$pidlist $!"
    done

    # Execute and wait
  2. Ciro S. Costa created this gist Jul 9, 2015.
    79 changes: 79 additions & 0 deletions stress-test.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    #!/bin/bash

    #### Default Configuration

    CONCURRENCY=4
    REQUESTS=100
    ADDRESS="http://localhost:8080/"

    show_help() {
    cat << EOF
    Naive Stress Test with cURL.
    Usage: ./stress-test.sh [-a ADDRESS] [-c CONCURRENCY] [-r REQUESTS]
    Params:
    -a address to be tested.
    Defaults to localhost:8080
    -c conccurency: how many process to spawn
    Defaults to 1
    -r number of requests per process
    Defaults to 10
    -h show this help text
    Example:
    $ ./stress-test.sh -c 4 -p 100 (400 requests to localhost:8080)
    EOF
    }


    #### CLI

    while getopts ":a:c:r:h" opt; do
    case $opt in
    a)
    ADDRESS=$OPTARG
    ;;
    c)
    CONCURRENCY=$OPTARG
    ;;
    r)
    REQUESTS=$OPTARG
    ;;
    h)
    show_help
    exit 0
    ;;
    \?)
    show_help >&2
    echo "Invalid argument: $OPTARG" &2
    exit 1
    ;;
    esac
    done

    shift $((OPTIND-1))

    #### Main

    for i in `seq 1 $CONCURRENCY`; do
    curl -s "$ADDRESS?[1-$REQUESTS]" & pidlist="$pidlist $!"
    done

    # Execute and wait
    FAIL=0
    for job in $pidlist; do
    echo $job
    wait $job || let "FAIL += 1"
    done

    # Verify if any failed
    if [ "$FAIL" -eq 0 ]; then
    echo "SUCCESS!"
    else
    echo "Failed Requests: ($FAIL)"
    fi