Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #51 from MrMarkW/gp3
Browse files Browse the repository at this point in the history
feat: Add support for gp3 iops, throughput
  • Loading branch information
wleepang authored Oct 28, 2022
2 parents 4d044c4 + 3d2a656 commit 657d970
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 32 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ aws ec2 run-instances --image-id ami-5253c32d \
--iam-instance-profile Name=MyInstanceProfileWithProperPermissions
```

that installs required packages and runs the initialization script. By default this creates a mount point of `/scratch` on a encrypted 100GB EBS volume. To change the mount point, edit the [cloud-init script](templates/cloud-init-userdata.yaml) file and supply additional options to the install script to suit your specific needs. Install options are shown below.
that installs required packages and runs the initialization script. By default this creates a mount point of `/scratch` on a encrypted 200GB gp3 EBS volume. To change the mount point, edit the [cloud-init script](templates/cloud-init-userdata.yaml) file and supply additional options to the install script to suit your specific needs. Install options are shown below.

```text
Install Amazon EBS Autoscale
Expand Down Expand Up @@ -70,6 +70,27 @@ Options
-t, --volume-type VOLUMETYPE
EBS volume type to use. (Default: gp3)
--volume-iops VOLUMEIOPS
Volume IOPS for gp3, io1, io2 (default: 3000)
--volume-throughput VOLUMETHOUGHPUT
Volume throughput for gp3 (default: 125)
--min-ebs-volume-size SIZE_GB
Mimimum size in GB of new volumes created by the instance.
(Default: 150)
--max-ebs-volume-size SIZE_GB
Maximum size in GB of new volumes created by the instance.
(Default: 1500)
--max-total-created-size SIZE_GB
Maximum total size in GB of all volumes created by the instance.
(Default: 8000)
--max-attached-volumes N
Maximum number of attached volumes. (Default: 16)
```

## A note on the IAM Instance Profile
Expand Down
33 changes: 22 additions & 11 deletions bin/create-ebs-volume
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ Required
Options
-t, --type Type of volume. (Default: gp2)
-t, --type Type of volume. (Default: config.volume.type)
-i, --iops IOPS for volume. Only valid if type=io1. (Default: 3000)
-i, --iops N
IOPS for volume. Only valid if type=io1, io2, gp3. (Default: config.volume.iops)
--throughput N
The throughput for a volume, with a maximum of 1,000 MiB/s. (Default: config.volume.throughput)
--not-encrypted Flag to make the volume un-encyrpted. Default is to create
an encrypted volume
--max-total-created-size SIZE_GB
Maximum total size in GB of all volumes created by the instance.
(Default: config.limits.max_logical_volume_size)
Expand Down Expand Up @@ -78,8 +82,9 @@ function error() {

TYPE=$(get_config_value .volume.type)
IOPS=$(get_config_value .volume.iops)
THROUGHPUT=$(get_config_value .volume.throughput)
ENCRYPTED=$(get_config_value .volume.encrypted)
MAX_TOTAL_EBS_SIZE=$(get_config_value .limits.max_logical_volume_size)
MAX_LOGICAL_VOLUME_SIZE=$(get_config_value .limits.max_logical_volume_size)
MAX_ATTACHED_VOLUMES=$(get_config_value .limits.max_ebs_volume_count)
MAX_CREATED_VOLUMES=$MAX_ATTACHED_VOLUMES

Expand All @@ -99,10 +104,18 @@ while (( "$#" )); do
IOPS=$2
shift 2
;;
--throughput)
THROUGHPUT=$2
shift 2
;;
--not-encrypted)
unset ENCRYPTED
shift
;;
--max-total-created-size)
MAX_LOGICAL_VOLUME_SIZE=$2
shift 2
;;
--max-attached-volumes)
MAX_ATTACHED_VOLUMES=$2
shift 2
Expand All @@ -111,10 +124,6 @@ while (( "$#" )); do
MAX_CREATED_VOLUMES=$2
shift 2
;;
--max-total-created-size)
MAX_TOTAL_EBS_SIZE=$2
shift 2
;;
-v|--verbose)
VERBOSE=1
shift
Expand Down Expand Up @@ -227,8 +236,8 @@ function create_and_attach_volume() {
done

# check how much EBS storage this instance has created
if [ "$total_created_size" -ge "$MAX_TOTAL_EBS_SIZE" ]; then
error "maximum total ebs volume size reached ($MAX_TOTAL_EBS_SIZE)"
if [ "$total_created_size" -ge "$MAX_LOGICAL_VOLUME_SIZE" ]; then
error "maximum total ebs volume size reached ($MAX_LOGICAL_VOLUME_SIZE)"
fi

# check how many volumes this instance has created
Expand All @@ -251,7 +260,9 @@ function create_and_attach_volume() {
# create the volume
local tmpfile=$(mktemp /tmp/ebs-autoscale.create-volume.XXXXXXXXXX)
local volume_opts="--size $SIZE --volume-type $TYPE"
if [ "$TYPE" == "io1" ]; then volume_opts="$volume_opts --iops $IOPS"; fi
local IOPS_TYPES=( io1 io2 gp3 )
if [[ " ${IOPS_TYPES[*]} " =~ " ${TYPE} " ]]; then volume_opts="$volume_opts --iops $IOPS"; fi
if [ "$TYPE" == "gp3" ]; then volume_opts="$volume_opts --throughput $THROUGHPUT"; fi
if [ "$ENCRYPTED" == "1" ]; then volume_opts="$volume_opts --encrypted"; fi
local timestamp=$(date "+%F %T UTC%z") # YYYY-mm-dd HH:MM:SS UTC+0000

Expand Down
24 changes: 13 additions & 11 deletions bin/ebs-autoscale
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@

initialize

MIN_EBS_VOLUME_SIZE=$(get_config_value .limits.min_ebs_volume_size)
MAX_EBS_VOLUME_SIZE=$(get_config_value .limits.max_ebs_volume_size)
MAX_LOGICAL_VOLUME_SIZE=$(get_config_value .limits.max_logical_volume_size)
MAX_EBS_VOLUME_COUNT=$(get_config_value .limits.max_ebs_volume_count)
INITIAL_UTILIZATION_THRESHOLD=$(get_config_value .limits.initial_utilization_threshold)

FILE_SYSTEM=$(get_config_value .filesystem)

Expand Down Expand Up @@ -98,7 +100,7 @@ calc_threshold() {
# as more ebs volumes are added, the threshold level increases

local num_devices=$1
local threshold=50
local threshold=${INITIAL_UTILIZATION_THRESHOLD}

if [ "$num_devices" -ge "4" ] && [ "$num_devices" -le "6" ]; then
threshold=80
Expand All @@ -107,7 +109,7 @@ calc_threshold() {
elif [ "$num_devices" -gt "10" ]; then
threshold=90
else
threshold=50
threshold=${INITIAL_UTILIZATION_THRESHOLD}
fi

echo ${threshold}
Expand All @@ -118,29 +120,29 @@ calc_new_size() {
# new volume sizes increase as the number of attached volumes increase
local num_devices=$1
#local num_devices=$(get_num_devices)
local new_size=150
local new_size=$MIN_EBS_VOLUME_SIZE

if [ "$num_devices" -ge "4" ] && [ "$num_devices" -le "6" ]; then
if [ "$MAX_EBS_VOLUME_SIZE" -ge "299" ]; then
if [ "$MAX_EBS_VOLUME_SIZE" -ge "299" ] && [ "$MIN_EBS_VOLUME_SIZE" -le "299" ]; then
new_size=300
elif [ "$MIN_EBS_VOLUME_SIZE" -ge "299" ]; then
new_size=$MIN_EBS_VOLUME_SIZE
else
new_size=$MAX_EBS_VOLUME_SIZE
fi
elif [ "$num_devices" -gt "6" ] && [ "$num_devices" -le "10" ]; then
if [ "$MAX_EBS_VOLUME_SIZE" -ge "999" ]; then
if [ "$MAX_EBS_VOLUME_SIZE" -ge "999" ] && [ "$MIN_EBS_VOLUME_SIZE" -le "999" ]; then
new_size=1000
elif [ "$MIN_EBS_VOLUME_SIZE" -ge "999" ]; then
new_size=$MIN_EBS_VOLUME_SIZE
else
new_size=$MAX_EBS_VOLUME_SIZE
fi
elif [ "$num_devices" -gt "10" ]; then
if [ "$MAX_EBS_VOLUME_SIZE" -ge "1499" ]; then
new_size=1500
else
new_size=$MAX_EBS_VOLUME_SIZE
fi
new_size=$MAX_EBS_VOLUME_SIZE
else
if [ "$MAX_EBS_VOLUME_SIZE" -ge "149" ]; then
new_size=150
new_size=$MIN_EBS_VOLUME_SIZE
else
new_size=$MAX_EBS_VOLUME_SIZE
fi
Expand Down
17 changes: 10 additions & 7 deletions config/ebs-autoscale.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
"mountpoint": "%%MOUNTPOINT%%",
"filesystem": "%%FILESYSTEM%%",
"lvm": {
"volume_group": "autoscale_vg",
"logical_volume": "autoscale_lv"
"volume_group": "autoscale_vg",
"logical_volume": "autoscale_lv"
},
"volume": {
"type": "%%VOLUMETYPE%%",
"iops": 3000,
"iops": "%%VOLUMEIOPS%%",
"throughput": "%%VOLUMETHOUGHPUT%%",
"encrypted": 1
},
"detection_interval": 2,
"limits": {
"max_ebs_volume_size": 1500,
"max_logical_volume_size": 8000,
"max_ebs_volume_count": 16
"min_ebs_volume_size": "%%MINEBSVOLUMESIZE%%",
"max_ebs_volume_size": "%%MAXEBSVOLUMESIZE%%",
"max_logical_volume_size": "%%MAXLOGICALVOLUMESIZE%%",
"max_ebs_volume_count": "%%MAXATTACHEDVOLUMES%%",
"initial_utilization_threshold": "%%INITIALUTILIZATIONTHRESHOLD%%"
},
"logging": {
"log_file": "/var/log/ebs-autoscale.log",
"log_interval": 300
}
}
}
72 changes: 70 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,49 @@ Options
-t, --volume-type VOLUMETYPE
Volume type (default: gp3)
-s, --initial-size SIZE
--volume-iops VOLUMEIOPS
Volume IOPS for gp3, io1, io2 (default: 3000)
--volume-throughput VOLUMETHOUGHPUT
Volume throughput for gp3 (default: 125)
--min-ebs-volume-size SIZE_GB
Mimimum size in GB of new volumes created by the instance.
(Default: 150)
--max-ebs-volume-size SIZE_GB
Maximum size in GB of new volumes created by the instance.
(Default: 1500)
--max-total-created-size SIZE_GB
Maximum total size in GB of all volumes created by the instance.
(Default: 8000)
--max-attached-volumes N
Maximum number of attached volumes. (Default: 16)
--initial-utilization-threshold N
Initial disk utilization treshold for scale-up. (Default: 50)
-s, --initial-size SIZE_GB
Initial size of the volume in GB. (Default: 200)
Only used if --initial-device is NOT specified.
EOF
)

MOUNTPOINT=/scratch
# defaults to set into ebs-autoscale.json
SIZE=200
VOLUMETYPE=gp3
VOLUMEIOPS=3000
VOLUMETHOUGHPUT=125
MIN_EBS_VOLUME_SIZE=150
MAX_EBS_VOLUME_SIZE=1500
MAX_LOGICAL_VOLUME_SIZE=8000
MAX_ATTACHED_VOLUMES=16
INITIAL_UTILIZATION_THRESHOLD=50

DEVICE=""
FILE_SYSTEM=btrfs
BASEDIR=$(dirname $0)
Expand All @@ -87,6 +120,34 @@ while (( "$#" )); do
VOLUMETYPE=$2
shift 2
;;
--volume-iops)
VOLUMEIOPS=$2
shift 2
;;
--volume-throughput)
VOLUMETHOUGHPUT=$2
shift 2
;;
--min-ebs-volume-size)
MIN_EBS_VOLUME_SIZE=$2
shift 2
;;
--max-ebs-volume-size)
MAX_EBS_VOLUME_SIZE=$2
shift 2
;;
--max-total-created-size)
MAX_LOGICAL_VOLUME_SIZE=$2
shift 2
;;
--max-attached-volumes)
MAX_ATTACHED_VOLUMES=$2
shift 2
;;
--initial-utilization-threshold)
INITIAL_UTILIZATION_THRESHOLD=$2
shift 2
;;
-d|--initial-device)
DEVICE=$2
shift 2
Expand Down Expand Up @@ -150,7 +211,14 @@ cp ${BASEDIR}/config/ebs-autoscale.logrotate /etc/logrotate.d/ebs-autoscale
cat ${BASEDIR}/config/ebs-autoscale.json | \
sed -e "s#%%MOUNTPOINT%%#${MOUNTPOINT}#" | \
sed -e "s#%%VOLUMETYPE%%#${VOLUMETYPE}#" | \
sed -e "s#%%FILESYSTEM%%#${FILE_SYSTEM}#" \
sed -e "s#%%VOLUMEIOPS%%#${VOLUMEIOPS}#" | \
sed -e "s#%%VOLUMETHOUGHPUT%%#${VOLUMETHOUGHPUT}#" | \
sed -e "s#%%FILESYSTEM%%#${FILE_SYSTEM}#" | \
sed -e "s#%%MINEBSVOLUMESIZE%%#${MIN_EBS_VOLUME_SIZE}#" | \
sed -e "s#%%MAXEBSVOLUMESIZE%%#${MAX_EBS_VOLUME_SIZE}#" | \
sed -e "s#%%MAXLOGICALVOLUMESIZE%%#${MAX_LOGICAL_VOLUME_SIZE}#" | \
sed -e "s#%%MAXATTACHEDVOLUMES%%#${MAX_ATTACHED_VOLUMES}#" | \
sed -e "s#%%INITIALUTILIZATIONTHRESHOLD%%#${INITIAL_UTILIZATION_THRESHOLD}#" \
> /etc/ebs-autoscale.json

## Create filesystem
Expand Down

0 comments on commit 657d970

Please sign in to comment.