Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Performance Tuning your TCP Stack
#!/bin/bash
echo "*****************************************"
echo " Based on information from Google"
echo " http://dev.chromium.org/spdy/spdy-best-practices"
echo "*****************************************"
sudo su
yum –y update
echo "*****************************************"
echo " Changing initcwnd and initrwnd"
echo " Step 1: check route settings."
echo " Make a note of the line starting with 'default'"
echo "*****************************************"
ip route show
read -n1 -r -p "Press any key to continue..." key
echo "*****************************************"
echo " Changing initcwnd and initrwnd"
echo " sudo ip route change [Paste the current settings for default] initcwnd 10 initrwnd 10"
echo " if you do this wrong and blow up your IP stack you will loose remote access!"
echo "*****************************************"
#sudo ip route change default via 10.210.242.1 dev eth0 initcwnd 10 initrwnd 10
echo "*****************************************"
echo " Now change the tcp_slow_start paramenter
echo " Change the 1 to a 0
echo "*****************************************"
sudo sed -e "s/^1$/0/" /proc/sys/net/ipv4/tcp_slow_start_after_idle
=================
http://dev.chromium.org/spdy/spdy-best-practices
Changing initcwnd
Adjusting the value of the initcwnd setting on Linux is simple. Assuming we want to set it to 10:
Step 1: check route settings.
sajal@sajal-desktop:~$ ip route show
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 metric 1
169.254.0.0/16 dev eth0 scope link metric 1000
default via 192.168.1.1 dev eth0 proto static
sajal@sajal-desktop:~$
Make a note of the line starting with default.
Step 2: Change the default settings.
Paste the current settings for default and add initcwnd 10 to it.
sajal@sajal-desktop:~$ sudo ip route change default via 192.168.1.1 dev eth0 proto static initcwnd 10
Step 3: Verify
sajal@sajal-desktop:~$ ip route show
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 metric 1
169.254.0.0/16 dev eth0 scope link metric 1000
default via 192.168.1.1 dev eth0 proto static initcwnd 10
sajal@sajal-desktop:~$
Changing initrwnd
The advertised receive window on Linux is called initrwnd. It can only be adjusted on linux kernel 2.6.33 and newer (H/T: Thomas Habets).
This is relevant for CDN servers because they interact with the origin server and it is relevant to other servers that interact with (3rd party) servers, e.g. most Web 2.0 sites that get/send data via API calls. If the interaction between your server and the other server is faster, then what you are sending to real end users will be faster too!
Step 1: check route settings.
sajal@sajal-desktop:~$ ip route show
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 metric 1
169.254.0.0/16 dev eth0 scope link metric 1000
default via 192.168.1.1 dev eth0 proto static
sajal@sajal-desktop:~$
Make a note of the line starting with default.
Step 2: Change the default settings.
Paste the current settings for default and add initrwnd 10 to it.
sajal@sajal-desktop:~$ sudo ip route change default via 192.168.1.1 dev eth0 proto static initrwnd 10
Step 3: Verify
sajal@sajal-desktop:~$ ip route show
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 metric 1
169.254.0.0/16 dev eth0 scope link metric 1000
default via 192.168.1.1 dev eth0 proto static initrwnd 10
sajal@sajal-desktop:~$
This changes the initcwnd and initrwnd until the next reboot. I don't know of any better way to make it persist. if you know of a way please mention it in the comments.
Change the tcp_slow_start setting:
# sudo nano /proc/sys/net/ipv4/tcp_slow_start*
Change the 1 to a 0

I saw this ip route | while read p; do ip route change $p initcwnd 10 initrwnd 10; done from http://blog.cloudflare.com/optimizing-the-linux-stack-for-mobile-web-per

Might make it scriptable at least.

kxmp commented Feb 19, 2015

How can i keep initcwnd after dhcp renew..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment