Wednesday, March 21, 2012

Linux systems network tuning

Before Making any changes , ask yourself why are you making a change and does the system see the same issue.


use : netstat -s to see if netstat has the same story to tell.


Check out the /etc/sysctl.conf  to see what are the parameters set to. And if you modify anything run sysctl -p to commit it. 






TCP BUFFER : 



# increase TCP maximum buffer size
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

# increase Linux autotuning TCP buffer limits
# min, default, and maximum number of bytes to use
net.ipv4.tcp_rmem = 4096 87380 16777216 
net.ipv4.tcp_wmem = 4096 65536 16777216

Adjust it to handle the largest link (16MB above)


ICMP are at times blocked use synack to measure the RTT



timeout_timewait parameter :
Meaning: The time between closing the connection and reusing it. Reopening the connection is less expensive than establishing a new connection.By reducing the value of this entry, TCP/IP can release closed connections faster, providing more resources for new connections. Adjust this parameter if the running application requires rapid release, the creation of new connections, and a low throughput due to many connections sitting in the TIME_WAIT state.


Default is 60 (seconds)

How to change : echo 20 > /proc/sys/net/ipv4/tcp_fin_timeout

OpenFile limit
ulimt -n 8000 <-- recommended value. If too high might even run out of inode. df -i


Connection backlog : when your sever gets too  many connections which leads to connection failures : 



echo 4000 > /proc/sys/net/core/netdev_max_backlog
echo 4000 > /proc/sys/net/core/somaxconn





TCP_KEEPALIVE_INTERVAL  : 

Description : the time between isAlive probes
HOW TO : echo 15 > /proc/sys/net/ipv4/tcp_keepalive_intvl

TCP_KEEPALIVE_PROBES :
Description : Number of probes before timing out.

echo 5  > /proc/sys/net/ipv4/tcp_keepalive_probes