Created
November 19, 2025 06:36
-
-
Save dogterbox/21761fe16a386da407070cccf1ef32bd to your computer and use it in GitHub Desktop.
Testing File IO Performance
This file contains hidden or 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 | |
| DIR="/mnt/s3fs/testfile" | |
| FILESIZE="100M" | |
| BS_SEQ="1M" | |
| BS_RAND="1M" | |
| IODEPTH=16 | |
| JOBS_PAR=4 | |
| RESULTS=() | |
| mkdir -p $DIR | |
| run_fio() { | |
| NAME="$1" | |
| RW="$2" | |
| BS="$3" | |
| JOBS="$4" | |
| echo "Running $NAME ..." | |
| OUTPUT=$(fio --name="$NAME" --directory="$DIR" \ | |
| --size="$FILESIZE" \ | |
| --bs="$BS" --rw="$RW" \ | |
| --numjobs="$JOBS" --direct=1 \ | |
| --iodepth="$IODEPTH" --group_reporting 2>&1) | |
| FIO_STATUS=$? | |
| if [[ $FIO_STATUS -ne 0 ]]; then | |
| ERROR_LINE=$(printf '%s\n' "$OUTPUT" | grep -m1 -i "error=") | |
| ERROR_REASON=${ERROR_LINE#*error=} | |
| ERROR_REASON=${ERROR_REASON%%$'\n'*} | |
| ERROR_REASON=${ERROR_REASON:-"exit $FIO_STATUS"} | |
| echo "fio $NAME failed (exit $FIO_STATUS): $ERROR_REASON" >&2 | |
| RESULTS+=("$NAME|$RW|$BS|$JOBS|N/A|error: $ERROR_REASON") | |
| return | |
| fi | |
| BW=$(echo "$OUTPUT" \ | |
| | grep -Eo "[Bb][Ww]=[0-9\.]+[KMG]i?B/s" \ | |
| | head -n1 \ | |
| | cut -d= -f2) | |
| BW=${BW:-"N/A"} | |
| LAT_LINE=$(echo "$OUTPUT" | grep -m1 "clat (") | |
| LAT_VALUE="" | |
| LAT_UNIT="" | |
| if [[ -n "$LAT_LINE" ]]; then | |
| LAT_VALUE=$(echo "$LAT_LINE" \ | |
| | grep -Eo "avg=[0-9\.]+" \ | |
| | head -n1 \ | |
| | cut -d= -f2) | |
| LAT_UNIT=$(echo "$LAT_LINE" \ | |
| | sed -n 's/.*clat (\([^)]*\)).*/\1/p') | |
| fi | |
| LAT_VALUE=${LAT_VALUE:-"N/A"} | |
| LAT_UNIT=${LAT_UNIT:-""} | |
| LAT_DISPLAY="$LAT_VALUE${LAT_UNIT:+ $LAT_UNIT}" | |
| RESULTS+=("$NAME|$RW|$BS|$JOBS|$BW|$LAT_DISPLAY") | |
| } | |
| ##### RUN TESTS ##### | |
| run_fio "seq-write-1job" "write" "$BS_SEQ" 1 | |
| run_fio "seq-write-4job" "write" "$BS_SEQ" $JOBS_PAR | |
| run_fio "rand-write-4job" "randwrite" "$BS_RAND" $JOBS_PAR | |
| run_fio "seq-read-1job" "read" "$BS_SEQ" 1 | |
| run_fio "seq-read-4job" "read" "$BS_SEQ" $JOBS_PAR | |
| run_fio "rand-read-4job" "randread" "$BS_RAND" $JOBS_PAR | |
| ##### PRINT TABLE ##### | |
| echo "" | |
| echo "================ S3FS FIO Benchmark Summary ================" | |
| printf "%-20s %-12s %-10s %-8s %-15s %-10s\n" \ | |
| "Test Name" "RW" "BlockSize" "Jobs" "Bandwidth" "Latency" | |
| echo "--------------------------------------------------------------------------" | |
| for row in "${RESULTS[@]}"; do | |
| IFS="|" read -r NAME RW BS JOBS BW LAT <<< "$row" | |
| printf "%-20s %-12s %-10s %-8s %-15s %-10s\n" \ | |
| "$NAME" "$RW" "$BS" "$JOBS" "$BW" "$LAT" | |
| done | |
| echo "==========================================================================" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sudo apt update
sudo apt install fio -y