Last active
August 7, 2024 10:43
-
-
Save huevos-y-bacon/4f13efe0837e39b491ab6f8880077459 to your computer and use it in GitHub Desktop.
AWS EC2 - Storage Tests
This file contains 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 | |
# shellcheck disable=all | |
### Mount the instance store volume to the instance | |
# see: | |
# https://stackoverflow.com/questions/45167717/mounting-a-nvme-disk-on-aws-ec2 | |
# https://gist.github.com/ktheory/3c3616fca42a3716346b | |
# install hdparm and htop | |
sudo yum -y install hdparm htop | |
# Mount points | |
IS=/is_test_data | |
EBS=/var/ebs_test_data | |
# Device names | |
IS_DEV=/dev/nvme1n1 | |
EBS_DEV=/dev/nvme0n1p1 | |
# Get script name without extension | |
SCRIPT_NAME=$(basename "$0" .sh) | |
stdout_log="/tmp/${SCRIPT_NAME}.log" | |
stderr_log="/tmp/${SCRIPT_NAME}_err.log" | |
rm -f ${stdout_log} ${stderr_log} | |
LINE="\n########################################################################\n" | |
echo -e "${LINE}" | |
### Format and mount the disk | |
format_mount(){ | |
echo "Formatting and mounting the intance store disk..." | |
echo | |
file -s ${IS_DEV} | |
if [[ $? -eq 0 ]]; then | |
# Check if disk is mounted | |
if mount | grep ${IS_DEV}; then | |
echo "${IS_DEV} is already mounted" | |
else | |
mkfs -t xfs ${IS_DEV} # format the disk | |
mkdir ${IS} # create a directory to mount the disk | |
mount ${IS_DEV} ${IS} # mount the disk | |
echo "${IS_DEV} ${IS} xfs defaults 0 0" >> /etc/fstab # add the disk to /etc/fstab | |
df -h # check the disk is mounted | |
fi | |
else | |
echo "nvme1n1 does not exist" | |
exit 1 | |
fi | |
mkdir -p ${EBS} | |
echo -e "${LINE}" | |
} > >(tee -a ${stdout_log}) 2> >(tee -a ${stdout_log_err} >&2) | |
### DD TEST - WRITE | |
write_test(){ | |
echo "Performing write tests using dd command (2GB)..." | |
echo | |
# 2GB using 4K block size | |
BLOCK_SIZE=4K # | |
COUNT=512K | |
echo "===============================" | |
echo "Instance Store Write Test (dd):" | |
echo " BLOCK_SIZE = ${BLOCK_SIZE}" | |
echo " COUNT = ${COUNT}" | |
echo "===============================" | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=${IS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=${IS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=${IS}/test | |
echo | |
echo "=========================" | |
echo "EBS Write Test (dd):" | |
echo " BLOCK_SIZE = ${BLOCK_SIZE}" | |
echo " COUNT = ${COUNT}" | |
echo "=========================" | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=/${EBS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=/${EBS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=/${EBS}/test | |
echo -e "${LINE}" | |
} > >(tee -a ${stdout_log}) 2> >(tee -a ${stdout_log_err} >&2) | |
write_test_small(){ | |
echo "Performing write tests using dd command (0.25GB)..." | |
echo | |
# 268MB using 1M block size | |
BLOCK_SIZE=1M | |
COUNT=256 | |
echo "===============================" | |
echo "Instance Store Write Test (dd):" | |
echo " BLOCK_SIZE = ${BLOCK_SIZE}" | |
echo " COUNT = ${COUNT}" | |
echo "===============================" | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=${IS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=${IS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=${IS}/test | |
echo | |
echo "=========================" | |
echo "EBS Write Test (dd):" | |
echo " BLOCK_SIZE = ${BLOCK_SIZE}" | |
echo " COUNT = ${COUNT}" | |
echo "=========================" | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=/${EBS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=/${EBS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=/${EBS}/test | |
echo -e "${LINE}" | |
} > >(tee -a ${stdout_log}) 2> >(tee -a ${stdout_log_err} >&2) | |
write_test_large(){ | |
echo "Performing write tests using dd command (20GB)..." | |
echo | |
# 20GB using 4K block size | |
BLOCK_SIZE=4K # | |
COUNT=5120K | |
echo "===============================" | |
echo "Instance Store Write Test (dd):" | |
echo " BLOCK_SIZE = ${BLOCK_SIZE}" | |
echo " COUNT = ${COUNT}" | |
echo "===============================" | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=${IS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=${IS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=${IS}/test | |
echo | |
echo "=========================" | |
echo "EBS Write Test (dd):" | |
echo " BLOCK_SIZE = ${BLOCK_SIZE}" | |
echo " COUNT = ${COUNT}" | |
echo "=========================" | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=/${EBS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=/${EBS}/test | |
dd bs=${BLOCK_SIZE} count=${COUNT} if=/dev/zero of=/${EBS}/test | |
echo -e "${LINE}" | |
} > >(tee -a ${stdout_log}) 2> >(tee -a ${stdout_log_err} >&2) | |
### HDPARM TEST -t = disk read test, -T = cache read test | |
read_tests_disk(){ | |
echo "Performing disk read tests using hdparm command..." | |
echo | |
# Disk read test - Instance Store | |
echo "==================================" | |
echo "Instance Store Read Test (disk):" | |
echo " hdparm -t ${IS_DEV}" | |
echo "==================================" | |
hdparm -t ${IS_DEV} | |
hdparm -t ${IS_DEV} | |
hdparm -t ${IS_DEV} | |
echo | |
# Disk read test - EBS | |
echo "======================" | |
echo "EBS Read Test (disk):" | |
echo " hdparm -t ${EBS_DEV}" | |
echo "======================" | |
hdparm -t ${EBS_DEV} | |
hdparm -t ${EBS_DEV} | |
hdparm -t ${EBS_DEV} | |
echo | |
echo -e "${LINE}" | |
} > >(tee -a ${stdout_log}) 2> >(tee -a ${stdout_log_err} >&2) | |
read_tests_cache(){ | |
echo "Performing cache read tests using hdparm command..." | |
echo | |
# Cache read test - Instance Store | |
echo "==================================" | |
echo "Instance Store Read Test (cache):" | |
echo " hdparm -T ${IS_DEV}" | |
echo "==================================" | |
hdparm -T ${IS_DEV} | |
hdparm -T ${IS_DEV} | |
hdparm -T ${IS_DEV} | |
echo | |
# Cache read test - EBS | |
echo "======================" | |
echo "EBS Read Test (cache):" | |
echo " hdparm -T ${EBS_DEV}" | |
echo "======================" | |
hdparm -T ${EBS_DEV} | |
hdparm -T ${EBS_DEV} | |
hdparm -T ${EBS_DEV} | |
echo -e "${LINE}" | |
} > >(tee -a ${stdout_log}) 2> >(tee -a ${stdout_log_err} >&2) | |
format_mount && \ | |
write_test_small && \ | |
write_test && \ | |
write_test_large && \ | |
read_tests_disk && \ | |
read_tests_cache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment