Skip to content

Instantly share code, notes, and snippets.

@an2io an2io/testio.yaml

Last active May 26, 2018
Embed
What would you like to do?
Test EBS Volume ext4 and xfs IO performance using dd and monitor performance using iostat
# -----
# Test EBS Volume ext4 and xfs IO performance using dd and monitor performance using iostat
#
# 1) Create InstanceProfile with RoleName
# 2) Create 10GB EBS Volume
# 3) Create EC2 instance with ephemeral storage, attach EBS volume and InstanceProfile
# 4) Create partitions and filesystems.
# 5) Perform tests and generate a report
# 6) Send report to SNS topic
#
# aws cloudformation create-stack --stack-name TestIO --template-body fileb://testio.yaml --capabilities CAPABILITY_IAM
AWSTemplateFormatVersion: "2010-09-09"
Description: >
Test EBS Volume ext4 and xfs IO performance using dd and monitor performance using iostat
Parameters:
RoleName:
Description: EC2 instance role with IAM and SNS permissions
Type: String
Default: CHANGE-ME
AZ:
Description: Availability Zone
Type: AWS::EC2::AvailabilityZone::Name
Default: us-west-2a
Subnet:
Description: SubnetId
Type: AWS::EC2::Subnet::Id
Default: CHANGE-ME
Image:
Description: AMI
Type: AWS::EC2::Image::Id
Default: ami-ad6f1ed5
Keypair:
Description: KeyPair
Type: AWS::EC2::KeyPair::KeyName
Default: CHANGE-ME
MountPoint:
Description: EBS Volume Mount Point
Type: String
Default: /dev/sdf
TestIOUserData:
Type: String
Default: |
#!/bin/bash
yum update -y
yum install -y sysstat tmux xfsprogs fio
# -- Create partitions
parted -s /dev/sdf mklabel msdos
parted -s /dev/sdf mkpart primary 1 4096
parted -s /dev/sdf mkpart primary 4096 8192
sleep 5
# -- Create and mount filesystems
mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/sdf1
mkfs.xfs /dev/sdf2
mkdir -p /mnt/ext4 /mnt/xfs
echo "/dev/sdf1 /mnt/ext4 ext4 defaults 0 0" >> /etc/fstab
echo "/dev/sdf2 /mnt/xfs xfs defaults 0 0" >> /etc/fstab
mount -a
sleep 10
# -- Create report
export REPORT=/tmp/report.txt
echo -e "### REPORT ###\n Instance IP: `curl http://169.254.169.254/latest/meta-data/public-ipv4`" > $REPORT
# -- Test script
cat << EOF > /tmp/runtest.sh
#/bin/bash
REPORT=$REPORT
iostat -dxytm 3 /dev/xvdf > /tmp/\$1-iostat.log &
IOSTATPID=\$!
dd if=/dev/zero of=/mnt/\$1/testfile conv=fsync bs=1M count=512 &> /tmp/\$1-dd.log
sleep 5
kill -19 \$IOSTATPID
# - Generate Report
{
echo -e "\n --- \$1 ---"
grep -m 1 '^Device' /tmp/\$1-iostat.log
grep '^xvd' /tmp/\$1-iostat.log
cat /tmp/\$1-dd.log
echo -e " ---- \n "
} >> \$REPORT
EOF
# -- Run tests
chmod +x /tmp/runtest.sh
/tmp/runtest.sh ext4
/tmp/runtest.sh xfs
# -- Add df and mount data to the report
{
echo -e "--- df ---"
df -h
echo -e "\n--- mount ---"
mount | grep xvdf
} >> $REPORT
# Publish the report
aws sns publish --topic-arn arn:aws:sns:us-west-2:CHANGE-ME:SNSmail --region "us-west-2" --message "`cat $REPORT`"
# Misc
echo -e "export TERM=xterm\n cls\n cat $REPORT" >> /home/ec2-user/.bashrc
Resources:
EBSVolume1:
Type: AWS::EC2::Volume
Properties:
Encrypted: false
VolumeType: gp2
Size: 10
AvailabilityZone: !Ref AZ
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- !Ref RoleName
EC2Instance:
Type: AWS::EC2::Instance
Properties:
KeyName: newkp
IamInstanceProfile: !Ref InstanceProfile
ImageId: !Ref Image # Instance store root
SubnetId: !Ref Subnet
EbsOptimized: false
InstanceType: m3.medium
Volumes:
- VolumeId: !Ref EBSVolume1
Device: !Ref MountPoint
UserData:
Fn::Base64:
!Ref TestIOUserData
DependsOn:
- EBSVolume1
- InstanceProfile
Outputs:
InstanceID:
Description: Server Public IP
Value: !GetAtt [EC2Instance, PublicIp]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.