Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ianblenke/19d5a0dd740bd1e16d1b to your computer and use it in GitHub Desktop.
Save ianblenke/19d5a0dd740bd1e16d1b to your computer and use it in GitHub Desktop.
Tuning EC2 with an ElasticBeanstalk ebextension
packages:
yum:
wget: []
curl: []
commands:
00_remove_99_swap.conf.bak:
command: rm -f /etc/sysctl.d/99_swap.conf.bak
test: test -f /etc/sysctl.d/99_swap.conf.bak
ignoreErrors: true
00_remove_99_filesystem.conf.bak:
command: rm -f /etc/sysctl.d/99_filesystem.conf.bak
test: test -f /etc/sysctl.d/99_filesystem.conf.bak
ignoreErrors: true
00_remove_99_networking.conf.bak:
command: rm -f /etc/sysctl.d/99_networking.conf.bak
test: test -f /etc/sysctl.d/99_networking.conf.bak
ignoreErrors: true
00_remove_00tune_ec2.sh.bak:
command: rm -f /opt/elasticbeanstalk/hooks/appdeploy/pre/00tune_ec2.sh.bak
test: test -f /opt/elasticbeanstalk/hooks/appdeploy/pre/00tune_ec2.sh.bak
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/00tune_ec2.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash -x
echo "Running: $0"
mkdir -p /usr/local/bin
if [ ! -x /usr/local/bin/ec2-metadata ]; then
wget -O /usr/local/bin/ec2-metadata http://s3.amazonaws.com/ec2metadata/ec2-metadata
chmod ugo+rx /usr/local/bin/ec2-metadata
fi
for device in /sys/block/*/queue/rq_affinity ; do echo 2 > $device ; done
for device in /sys/block/*/queue/scheduler ; do echo noop > $device ; done
for device in /sys/block/*/queue/nr_requests ; do echo 256 > $device ; done
for device in /sys/block/*/queue/read_ahead_kb ; do echo 256 > $device ; done
echo tsc > /sys/devices/system/clocksource/clocksource0/current_clocksource
# If TLB exhaustion happens on an older core host (newer CPUs shouldn't have this problem)
#echo never > /sys/kernel/mm/transparent_hugepage/enabled
sysctl -p
"/etc/sysctl.d/99_swap.conf":
mode: "000644"
owner: root
group: root
content: |
vm.swappiness = 0
"/etc/sysctl.d/99_filesystem.conf":
mode: "000644"
owner: root
group: root
content: |
vm.dirty_ratio = 80
vm.dirty_background_ratio = 5
vm.dirty_expire_centisecs = 12000
"/etc/sysctl.d/99_networking.conf":
mode: "000644"
owner: root
group: root
content: |
net.core.somaxconn = 1000
net.core.netdev_max_backlog = 5000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_max_syn_backlog = 8096
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240 65535
net.ipv4.tcp_abort_on_overflow = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment