commit 976bd555b2700f61efd83e802c936145aec1a3e6
parent 9ea84758b3cfc19a46c78e52641492b26fd052a4
Author: Alex Balgavy <alexander.balgavy@spaceapplications.com>
Date: Sat, 14 Dec 2024 15:45:54 +0100
dd-test: script for testing disk write speed
Diffstat:
A | scripts/dd-test | | | 72 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 72 insertions(+), 0 deletions(-)
diff --git a/scripts/dd-test b/scripts/dd-test
@@ -0,0 +1,72 @@
+#!/bin/sh
+# IBS
+TEST_FILE=${1:-dd_ibs_testfile}
+[ -e "$TEST_FILE" ]; TEST_FILE_EXISTS=$?
+TEST_FILE_SIZE=134217728
+
+# Exit if file exists
+if [ -e "$TEST_FILE" ]; then
+ echo "Test file $TEST_FILE exists, aborting."
+ exit 1
+fi
+
+# Create test file
+echo 'Generating test file...'
+BLOCK_SIZE=65536
+COUNT=$((TEST_FILE_SIZE / BLOCK_SIZE))
+dd if=/dev/urandom of="$TEST_FILE" bs=$BLOCK_SIZE count=$COUNT > /dev/null 2>&1
+
+stats=""
+
+# Block sizes of 512b 1K 2K 4K 8K 16K 32K 64K 128K 256K 512K 1M 2M 4M 8M 16M 32M 64M
+for BLOCK_SIZE in 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864
+do
+ # Read test file out to /dev/null with specified block size
+ DD_RESULT=$(dd if="$TEST_FILE" of=/dev/null bs=$BLOCK_SIZE 2>&1 1>/dev/null)
+
+ # Extract transfer rate
+ TRANSFER_RATE=$(echo "$DD_RESULT" | \grep --only-matching -E '[0-9.]+ ([MGk]?B|bytes)/s(ec)?')
+ stats="$stats
+$BLOCK_SIZE:$TRANSFER_RATE"
+done
+
+# Clean up the test file if we created one
+[ $TEST_FILE_EXISTS -ne 0 ] && rm "$TEST_FILE"
+
+printf "Optimal ibs: "
+printf "%s" "$stats" | awk -F ':' 'NF > 1 { sub("B/s", "", $2); gsub(" ", "", $2); gsub(" ", "", $1); print $1 ":" $2 }' | numfmt -d ':' --field 2 --from auto | sort -t ':' -k 2rn | head -n 1 | numfmt -d ':' --field 2 --to iec
+
+# OBS
+TEST_FILE=${1:-dd_obs_testfile}
+[ -e "$TEST_FILE" ]; TEST_FILE_EXISTS=$?
+TEST_FILE_SIZE=134217728
+
+stats=""
+
+# Block sizes of 512b 1K 2K 4K 8K 16K 32K 64K 128K 256K 512K 1M 2M 4M 8M 16M 32M 64M
+for BLOCK_SIZE in 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864
+do
+ # Calculate number of segments required to copy
+ COUNT=$((TEST_FILE_SIZE / BLOCK_SIZE))
+
+ if [ $COUNT -le 0 ]; then
+ echo "Block size of $BLOCK_SIZE estimated to require $COUNT blocks, aborting further tests."
+ break
+ fi
+
+ # Create a test file with the specified block size
+ DD_RESULT=$(dd if=/dev/zero of="$TEST_FILE" bs=$BLOCK_SIZE count=$COUNT 2>&1 1>/dev/null)
+
+ # Extract the transfer rate from dd's STDERR output
+ TRANSFER_RATE=$(echo "$DD_RESULT" | \grep --only-matching -E '[0-9.]+ ([MGk]?B|bytes)/s(ec)?')
+
+ # Clean up the test file if we created one
+ [ $TEST_FILE_EXISTS -ne 0 ] && rm "$TEST_FILE"
+
+ # Output the result
+ stats="$stats
+$BLOCK_SIZE:$TRANSFER_RATE"
+done
+
+printf "Optimal obs: "
+printf "%s" "$stats" | awk -F ':' 'NF > 1 { sub("B/s", "", $2); gsub(" ", "", $2); gsub(" ", "", $1); print $1 ":" $2 }' | numfmt -d ':' --field 2 --from auto | sort -t ':' -k 2rn | head -n 1 | numfmt -d ':' --field 2 --to iec