Last active
January 8, 2025 20:37
-
-
Save kigster/3869409f17739461f9d1fb7e0aa5022c to your computer and use it in GitHub Desktop.
AWS Instance Benchmark using sysbench
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
#!/usr/bin/env bash | |
# vim: ft=bash | |
# Uses sysbench on Ubuntu to run CPU, RAM and File IO Tests | |
# Saves the output into "result-for-<instance-type>-<date>-<time>.txt | |
# | |
# You can run this as follows without downloading: | |
# curl -fsSL https://gist.githubusercontent.com/kigster/3869409f17739461f9d1fb7e0aa5022c/raw | bash | |
line() { | |
echo -e "\e[0;33m———————————————————————————————————————————————————————————————————————\e[0m" | |
} | |
print-header() { | |
echo -e "\e[1;35m → $*\e[0m\n" | |
} | |
print-warmup() { | |
echo -e "\e[1;33m ⏳ $*\e[0m\n" | |
} | |
print-test() { | |
echo -e "\e[1;31m 🚀 $*\e[0m\n" | |
} | |
print-msg() { | |
echo -e "\e[1;34m → $*\e[0m" | |
} | |
export instance=$(ec2metadata --instance-type | tr -d '\n') | |
export timestamp=$(date '+%Y-%M-%d.%T.%N') | |
export output="result-for-${instance}-${timestamp}.txt" | |
benchit() { | |
local ram_gb=$(free -g| grep Mem | awk '{print $2}') | |
local cpus=$(cat /proc/cpuinfo | grep "model name" | sed -E 's/^model name\s+: /x /g' | uniq -c | sed -E 's/^ +//g') | |
local test_file_size=1G | |
local test_mem_size=5G | |
local cores=$(nproc) | |
local flags="--verbosity=3 --threads=${cores}" | |
local data_color="\e[1;32m" | |
print-header Instance | |
line | |
print-msg "Hostname ${data_color}$(hostname)" | |
print-msg "AWS Type ${data_color}${instance}" | |
print-msg "With RAM ${data_color}${ram_gb}Gb" | |
print-msg "With CPUs ${data_color}${cpus}" | |
print-msg "With Cores ${data_color}${cores}" | |
echo | |
line | |
print-header "BogoMips & CPU Cache" | |
printf "\e[1;32m" | |
lscpu | grep -i -E '^(bogomips|L[0-9])' --color=never | awk 'BEGIN{FS=": *"}{printf " * %-10.10s: %-20.20s\n", $1, $2}' | |
line | |
command -V sysbench >/dev/null 2>&1 || { | |
print-msg "Please wait while we ensure your sysbench is installed..." | |
bash -c "sudo apt-get update -yqq && sudo apt-get install -yqq sysbench" >/dev/null 2>&1 | |
print-msg "Done." | |
} | |
# then to test CPU speed (warmup) | |
print-warmup "Warming up CPU..." | |
sysbench cpu --cpu-max-prime=10000 ${flags} run >/dev/null 2>&1 | |
print-test "Testing the CPU..." | |
sysbench cpu --cpu-max-prime=10000 ${flags} run | |
print-test "Testing the RAM..." | |
sysbench memory --memory-block-size=1M --memory-total-size=${test_mem_size} ${flags} run | |
print-warmup "Preparing the File IO..." | |
sysbench fileio --file-total-size=${test_file_size} prepare >/dev/null 2>&1 | |
print-test "Testing File IO (async)..." | |
sysbench fileio --file-total-size=${test_file_size} --file-test-mode=rndrw --time=30 --file-io-mode=async ${flags} run | |
print-test "Testing File IO (sync)..." | |
sysbench fileio --file-total-size=${test_file_size} --file-test-mode=rndrw --time=30 --file-io-mode=sync ${flags} run | |
print-warmup "Cleaning after File IO Test..." | |
sysbench fileio --file-total-size=${test_file_size} cleanup >/dev/null 2>&1 | |
print-msg "Test Completed." | |
} | |
rm -f $output && touch $output | |
time benchit 2>&1 | tee -a $output | |
line | tee -a $output | |
print-msg "All test results were saved into file [$output]" | |
line | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment