Skip to content

Instantly share code, notes, and snippets.

@yyuu
Created October 11, 2011 08:33
Show Gist options
  • Save yyuu/1277579 to your computer and use it in GitHub Desktop.
Save yyuu/1277579 to your computer and use it in GitHub Desktop.
aws-rds-benchmark.sh
#!/bin/sh -e
rds_db_instance_identifier() {
echo "$@" | sed -e 's/[^-0-9A-Za-z]/-/g'
}
rds_describe_db_instance() {
if test $# -lt 1; then
return 1
fi
rds-describe-db-instances | awk -v instance_identifier=$1 '
$1=="DBINSTANCE" && $2==instance_identifier {
print($0);
}
'
}
rds_is_available() {
if test $# -lt 1; then
return 1
fi
rds_describe_db_instance $1 | awk '
BEGIN {
available=0;
}
$8 == "available" {
available=1;
}
END {
exit(!available);
}
'
}
rds_db_instance_endpoint() {
if test $# -lt 1; then
return 1
fi
if ! rds_is_available $1; then
echo "rds db instance $1 is not ready." 1>&2
exit 1
fi
rds_describe_db_instance $1 | awk '{ print($9); }'
}
rds_allocated_storage=5
rds_availability_zone=ap-northeast-1b
rds_db_security_groups=default
rds_master_username=root
rds_master_user_password=secret
rds_db_name=test
rds_engine=MySQL
rds_engine_version=5.1.57
mysqlslap_concurrency=25
mysqlslap_queries=100000
mysqlslap_iterations=5
while test $# -gt 0; do
case x$1 in
x-s)
shift; rds_allocated_storage=$1
;;
x-z)
shift; rds_availability_zone=$1
;;
x-a)
shift; rds_db_security_groups=$1
;;
x-u)
shift; rds_master_username=$1
;;
x-p)
shift; rds_master_user_password=$1
;;
x-n)
shift; rds_db_name=$1
;;
x-e)
shift; rds_engine=$1
;;
x-v)
shift; rds_engine_version=$1
;;
x-C)
shift; mysqlslap_concurrency=$1
;;
x-N)
shift; mysqlslap_queries=$1
;;
x-I)
shift; mysqlslap_iterations=$1
;;
*)
break
esac
shift
done
rds_db_instance_types=
while test $# -gt 0; do
case x$1 in
x--)
shift; break
;;
*)
rds_db_instance_types="$rds_db_instance_types $1"
;;
esac
shift
done
rds_db_instance_types=${rds_db_instance_types:-db.m1.small}
rds_db_parameter_group_names=
while test $# -gt 0; do
case x$1 in
x--)
shift; break
;;
*)
rds_db_parameter_group_names="$rds_db_parameter_group_names $1"
;;
esac
shift
done
rds_db_parameter_group_names=${rds_db_parameter_group_names:-default.mysql5.1}
for rds_db_instance_type in $rds_db_instance_types; do
for rds_db_parameter_group_name in $rds_db_parameter_group_names; do
rds_db_instance_identifier=`rds_db_instance_identifier $rds_db_instance_type $rds_db_parameter_group_name`
if ! rds_is_available $rds_db_instance_identifier; then
echo "Creating RDS DB instance: $rds_db_instance_identifier"
rds-create-db-instance \
--allocated-storage $rds_allocated_storage \
--db-instance-class $rds_db_instance_type \
--engine $rds_engine \
--engine-version $rds_engine_version \
--master-user-password $rds_master_user_password \
--master-username $rds_master_username \
--availability-zone $rds_availability_zone \
--db-name $rds_db_name \
--db-parameter-group-name $rds_db_parameter_group_name \
--db-security-groups $rds_db_security_groups \
--db-instance-identifier $rds_db_instance_identifier
fi
while ! rds_is_available $rds_db_instance_identifier; do
echo "RDS DB instance $rds_db_instance_identifier is not ready, waiting..."
sleep 300
done
echo "Benchmarking RDS DB instance: $rds_db_instance_identifier"
rds_db_instance_endpoint=`rds_db_instance_endpoint $rds_db_instance_identifier`
mysqlslap \
--concurrency=$mysqlslap_concurrency \
--auto-generate-sql \
--auto-generate-sql-execute-number=$mysqlslap_queries \
--auto-generate-sql-guid-primary \
--auto-generate-sql-load-type=write \
--create-schema=$rds_db_name \
--engine=InnoDB \
--host=$rds_db_instance_endpoint \
--iteration=$mysqlslap_iterations \
--number-int-cols=3 \
--password=$rds_master_user_password \
--user=$rds_master_username \
| tee $rds_db_instance_identifier.log
echo "Deleting RDS DB intance: $rds_db_instance_identifier"
rds-delete-db-instance $rds_db_instance_identifier --skip-final-snapshot --force
done
done
# vim:set ft=sh :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment