Skip to content

Instantly share code, notes, and snippets.

@beastycoding
Forked from trajakovic/sysctl-conf.sh
Created November 2, 2018 19:42
Show Gist options
  • Save beastycoding/01eca4815b3381dd2f957786e2cbcd87 to your computer and use it in GitHub Desktop.
Save beastycoding/01eca4815b3381dd2f957786e2cbcd87 to your computer and use it in GitHub Desktop.
High performance sysctl.conf
#!/bin/bash
#check if this script is running in su mode
func_check_for_root() {
if [ ! $( id -u ) -eq 0 ]; then
echo "ERROR: $0 Must be run as root, Script terminating" ;exit 7
fi
}
func_check_for_root
#write out this settings to /etc/sysctl.conf
cat >/etc/sysctl.conf <<EOL
# "Performance Scalability of a Multi-Core Web Server", Nov 2007
# Bryan Veal and Annie Foong, Intel Corporation, Page 4/10
fs.file-max = 5000000
net.core.netdev_max_backlog = 400000
net.core.optmem_max = 10000000
net.core.rmem_default = 10000000
net.core.rmem_max = 10000000
net.core.somaxconn = 100000
net.core.wmem_default = 10000000
net.core.wmem_max = 10000000
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_congestion_control = bic
net.ipv4.tcp_ecn = 0
net.ipv4.tcp_max_syn_backlog = 12000
net.ipv4.tcp_max_tw_buckets = 2000000
net.ipv4.tcp_mem = 30000000 30000000 30000000
net.ipv4.tcp_rmem = 30000000 30000000 30000000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_wmem = 30000000 30000000 30000000
net.ipv4.tcp_fin_timeout = 30
# optionally, avoid TIME_WAIT states on localhost no-HTTP Keep-Alive tests:
# "error: connect() failed: Cannot assign requested address (99)"
# On Linux, the 2MSL time is hardcoded to 60 seconds in /include/net/tcp.h:
# #define TCP_TIMEWAIT_LEN (60*HZ)
# The option below is safe to use:
net.ipv4.tcp_tw_reuse = 1
# The option below lets you reduce TIME_WAITs further
# but this option is for benchmarks, NOT for production (NAT issues)
net.ipv4.tcp_tw_recycle = 0
EOL
sysctl -p
cat >>/etc/security/limits.conf <<EOL
* soft nproc 999999
* hard nproc 999999
* soft nofile 999999
* hard nofile 999999
EOL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment