Disk_Benchmark_No_Dependency/disk_benchmark.sh
2025-04-16 18:08:49 +02:00

98 lines
No EOL
3.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
# Valeurs par défaut
FILESIZE="1G"
FILECOUNT=1000
FILEMODE="fixed"
LINES=1
function show_help {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options disponibles :"
echo " --size=SIZE Taille du fichier dd (ex: 1G, 500M). Défaut: 1G"
echo " --count=N Nombre de petits fichiers. Défaut: 1000"
echo " --mode=MODE Mode de génération : fixed ou random. Défaut: fixed"
echo " --lines=N Nombre de lignes pour les fichiers en mode fixed. Défaut: 1"
echo " --help Affiche ce message daide"
exit 0
}
# Parsing des arguments
for arg in "$@"; do
case $arg in
--size=*)
FILESIZE="${arg#*=}"
;;
--count=*)
FILECOUNT="${arg#*=}"
;;
--mode=*)
FILEMODE="${arg#*=}"
;;
--lines=*)
LINES="${arg#*=}"
;;
--help)
show_help
;;
*)
echo "Argument inconnu : $arg"
show_help
;;
esac
done
# Répertoires
BENCHDIR="./testbench"
TESTFILE="$BENCHDIR/dd_testfile"
SMALLDIR="$BENCHDIR/smallfiles"
mkdir -p "$SMALLDIR"
echo "=== Test d'écriture séquentielle avec dd ($FILESIZE, sync forcée) ==="
WRITE_TIME_SEC=$( (time dd if=/dev/zero of="$TESTFILE" bs="$FILESIZE" count=1 conv=fdatasync status=none) 2>&1 | grep real | awk '{print $2}' | sed 's/m/:/;s/s//')
WRITE_SEC=$(echo "$WRITE_TIME_SEC" | awk -F: '{ print ($1 * 60) + $2 }')
echo "Durée : $WRITE_TIME_SEC (~$(awk -v size="$FILESIZE" -v sec="$WRITE_SEC" 'BEGIN {
gsub(/[A-Za-z]/, "", size)
if (index(tolower(ARGV[1]), "g")) mult=1024; else mult=1;
printf "%.2f", (size * mult) / sec
}') MB/s)"
echo -e "\\n=== Test de lecture séquentielle ==="
READ_TIME_SEC=$( (time dd if="$TESTFILE" of=/dev/null bs="$FILESIZE" status=none) 2>&1 | grep real | awk '{print $2}' | sed 's/m/:/;s/s//')
READ_SEC=$(echo "$READ_TIME_SEC" | awk -F: '{ print ($1 * 60) + $2 }')
echo "Durée : $READ_TIME_SEC (~$(awk -v size="$FILESIZE" -v sec="$READ_SEC" 'BEGIN {
gsub(/[A-Za-z]/, "", size)
if (index(tolower(ARGV[1]), "g")) mult=1024; else mult=1;
printf "%.2f", (size * mult) / sec
}') MB/s)"
echo -e "\\n=== Test IOPS sur $FILECOUNT fichiers ($FILEMODE) ==="
echo -n "Création : "
CREATE_TIME_SEC=$( (time for i in $(seq 1 "$FILECOUNT"); do
if [[ "$FILEMODE" == "random" ]]; then
head -c $((RANDOM % 4096 + 128)) /dev/urandom > "$SMALLDIR/file_$i"
else
yes "Ligne test $i" | head -n "$LINES" > "$SMALLDIR/file_$i"
fi
done) 2>&1 | grep real | awk '{print $2}' | sed 's/m/:/;s/s//')
CREATE_SEC=$(echo "$CREATE_TIME_SEC" | awk -F: '{ print ($1 * 60) + $2 }')
CREATE_IOPS=$(awk -v total="$FILECOUNT" -v sec="$CREATE_SEC" 'BEGIN { printf "%.1f", total / sec }')
echo "$CREATE_TIME_SEC (~$CREATE_IOPS IOPS)"
echo -n "Lecture : "
READ_SMALL_SEC=$( (time for i in $(seq 1 "$FILECOUNT"); do
cat "$SMALLDIR/file_$i" > /dev/null
done) 2>&1 | grep real | awk '{print $2}' | sed 's/m/:/;s/s//')
READ_SMALL_IOPS=$(awk -v total="$FILECOUNT" -v sec="$(echo $READ_SMALL_SEC | awk -F: '{ print ($1 * 60) + $2 }')" 'BEGIN { printf "%.1f", total / sec }')
echo "$READ_SMALL_SEC (~$READ_SMALL_IOPS IOPS)"
echo -e "\\nNettoyage..."
rm -rf "$BENCHDIR"
echo -e "\\nBenchmark terminé."