Tuesday, December 14, 2010

Linux TCP/IP Tuning

Now here I will be discussing some techniques to improve the Performance of TCP/IP in Linux.
This is basically quick note to myself.
What happens when the packet is to be transmitted out of NIC?
1) Process writes data to socket file descriptor
2) Kernel encapsulates it into PDU (Protocol Data Unit)
3) PDU's are moved to transmit queue (transmit buffer)
4) Driver copies PDU from head of queue to NIC
5) NIC raises interrupt when the PDU is transmitted

What happens when the packet is received on NIC?
1) NIC receives frame and use DMA(Direct Memory Access) to copy into recieve buffer
2) NIC raises CPU interrupt
3) Kernel handles interrupt and schedules a softirq
4) Softirq is handled to move packets up to the IP layer for routing decision
5) If it's a local delivery, then the packet is decapsulated and placed into Socket's receive buffer.

tc - traffic control command used for modifying kernel parameters related to Network Stack.

For collisions,packets dropped & queues use following commands
tc -s qdisc show dev eth0
tc - traffic control
s - statistics
qdisc - queing discipline

ifconfig eth0 | grep txqueuelen

ip link set eth0 txqueuelen 10001 - to change the queue length of interface

Network parameter paths in Linux (In this case Ubuntu) (can be changed by /etc/sysctl.conf also for persistent configurations)

1)/proc/sys/net/core/rmem_default - default buffer size for receive buffer
2)/proc/sys/net/core/wmem_default - default buffer size or transmit buffer
3)/proc/sys/net/core/rmem_max - maximum recieve buffer used by an application
4)/proc/sys/net/core/wmem_max - maximum send buffer used by an application
5)/proc/sys/net/ipv4/tcp_rmem - TCP reads
6)/proc/sys/net/ipv4/tcp_wmem - TCP writes

Values are in sequence of "Minimum default Maximum".

We can directly see the values of these parameters. Other way is to use the sysctl -a command as follows :
sysctl -a | grep net.core.r
sysctl -a | grep net.core.w
(run sysctl -p to apply the changes in sysctl.conf)

Terminology while doing socket programming:
read = receive
write = transmit

No comments:

Post a Comment