Stress and stress-race scripts

There have been many versions floating around, let’s keep a central version up to date:

Create the files somewhere in your PATH, personally I have ~/bin, and make them executable.

stress

#!/usr/bin/env bash
set -e

go test -c
PKG=$(basename $(pwd))

# Counter
C=0
START_TIME=$SECONDS

while true ; do 
        C=$((C+1))
        export GOTRACEBACK=all
        export GOMAXPROCS=$[ 1 + $[ RANDOM % 128 ]]
        ./$PKG.test $@ 2>&1
        ELAPSED_TIME=$(($SECONDS - $START_TIME))
        echo "$C successful runs in $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec"   
done

stress-race - same as stress but with -race

#!/usr/bin/env bash
set -e

go test -c -race
PKG=$(basename $(pwd))

# Counter
C=0
START_TIME=$SECONDS

while true ; do 
        C=$((C+1))
        export GOTRACEBACK=all
        export GOMAXPROCS=$[ 1 + $[ RANDOM % 128 ]]
        ./$PKG.test $@ 2>&1
        ELAPSED_TIME=$(($SECONDS - $START_TIME))
        echo "$C successful runs in $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec"   
done
2 Likes

stress-ng can be used to add stress to a machine. Run it concurrently with one of the scripts above to help reproduce issues since in CI. Install via snap.