Skip to content

Instantly share code, notes, and snippets.

@tranvictor
Last active August 29, 2015 14:10
Show Gist options
  • Save tranvictor/51f9c329dd3530f901f5 to your computer and use it in GitHub Desktop.
Save tranvictor/51f9c329dd3530f901f5 to your computer and use it in GitHub Desktop.
Example of tuning kernel variables for production linux server
Add all the following lines to the file: “/etc/sysctl.conf”
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.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
#
# 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). This option is safe to use in production.
#
net.ipv4.tcp_tw_reuse = 1
#
# WARNING:
# ——–
# The option below lets you reduce TIME_WAITs by several orders of magnitude
# but this option is for benchmarks, NOT for production servers (NAT issues)
# So, uncomment the line below if you know what you’re doing.
#
#net.ipv4.tcp_tw_recycle = 1
#
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.ip_forward = 0
net.ipv4.tcp_dsack = 0
net.ipv4.tcp_fack = 0
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_orphan_retries = 0
net.ipv4.tcp_keepalive_time = 120
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl = 10
net.ipv4.tcp_retries2 = 15
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_synack_retries = 5
net.ipv4.tcp_syn_retries = 5
net.ipv4.tcp_moderate_rcvbuf = 1
kernel.sysrq = 0
kernel.shmmax = 67108864
Then add also the 2 following lines to the file: /etc/secutity/limits.conf
* soft nofile 1000000
* hard nofile 1000000
Source: Bryan Veal and Annie Foong (Performance Scalability of a Multi-Core Server, Nov 2007, page 4/10)
************************************************
Ubuntu: error:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/ubuntu/.rvm/rubies/ruby-2.1.3/bin/ruby -r ./siteconf20141216-20731-1ekpo18.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
How to solve: sudo apt-get install libmysqlclient-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment