How to optimize TCP/IP performance and network performance of Linux systems

WBOY
Release: 2023-11-07 11:15:24
Original
968 people have browsed it

How to optimize TCP/IP performance and network performance of Linux systems

In the field of modern computers, the TCP/IP protocol is the basis for network communication. As an open source operating system, Linux has become the preferred operating system used by many businesses and organizations. However, as network applications and services become more and more critical components of business, administrators often need to optimize network performance to ensure fast and reliable data transfer.

This article will introduce how to improve the network transmission speed of Linux systems by optimizing TCP/IP performance and network performance of Linux systems. This article will explore some necessary TCP parameters and how to change them to optimize network performance. This article will also introduce how to use some common CLI and kernel tools to check network performance in the system, and provide readers with some code examples.

1. Understand tcp tw_reuse

TCP connection is a connection-oriented transmission protocol, so the IP address and port combination must be different to create a new connection. After the client and server have been closed, but Linux is still waiting for a period of time when the connection may have been recently created, an attempt is made to establish a tcp connection. This period of time is called the "TIME_WAIT" state, and connections in this state cannot be reused. This behavior can slow down the server's TCP/IP performance.

To avoid this situation, we can use the tw_reuse parameter. Enabling tw_reuse allows exited connections to be reused without waiting for a certain period of time. This parameter can be enabled through the following command:

echo 1 >/proc/sys/net/ipv4/tcp_tw_reuse
Copy after login

2. Adjust the TCP keepalive parameters appropriately

TCP keepalive is a mechanism that can detect whether the connection is still active and prevent problems due to network congestion. Causes connection loss. TCP keepalive periodically checks the connection status to determine whether the connection is still active and closes the connection if not.

Adjusting TCP keepalive parameters can improve transmission performance. The following are three important TCP parameters:

1.tcp_keepalive_time

The tcp_keepalive_time parameter defines the time interval between sending keep-alive messages. If a node in the network becomes unresponsive, the keepalive mechanism attempts to reestablish the connection.

The default value is 7200 seconds (i.e. 2 hours)

2.tcp_keepalive_intvl

The tcp_keepalive_intvl parameter defines the retry interval after sending a keep-alive message.

The default value is 75 seconds

3.tcp_keepalive_probes

tcp_keepalive_probes defines how many TCP probes are performed before sending a keepalive message.

The default value is 9 times

These parameters can be changed to improve TCP performance. The following is the command to change the above three parameters:

echo 600 >/proc/sys/net/ipv4/tcp_keepalive_time
echo 30 >/proc/sys/net/ipv4/tcp_keepalive_intvl
echo 5 >/proc/sys/net/ipv4/tcp_keepalive_probes
Copy after login

3. Enable TCP window scaling option

TCP Window Scaling (TCP Window Scaling) is an option to extend the TCP header to support High speed internet. By default, the Linux kernel automatically enables the TCP window extension option, but if you are using an older version of the kernel, you may need to enable this option.

The following is the command to enable the TCP window extension option:

echo 1 >/proc/sys/net/ipv4/tcp_window_scaling
Copy after login

4. Use ifconfig to adjust the MTU and MRU values ​​

MTU (Maximum Transmission Unit) is the data packet that can be transmitted Maximum size, while MRU (Maximum Receive Unit) is the maximum packet size that the receiving end can receive.

Changing the MTU and MRU values ​​can improve the network performance of the system. We can use the ifconfig command to change these values. The following are the commands to change MTU and MRU:

ifconfig eth0 mtu 9000
ifconfig eth0 mru 9000
Copy after login

5. Use iperf3 to test network performance

iperf3 is a traffic detection and network service quality testing tool. It helps administrators measure the system's network performance and check network congestion. Use iperf3 to quickly discover network bottlenecks for tuning.

First, start iperf3 on the server side. The following command can start a TCP server listening on the default port:

iperf3 -s
Copy after login

Then, run iperf3 on the client to test the broadcast speed of network information. For TCP testing, you can run the following command:

iperf3 -c <server-ip>
Copy after login

6. Use the netstat command to monitor network performance

The netstat command is a commonly used command line tool that can be used to check network connections in Linux systems and transmission performance.

You can use the following command to check the number and status of TCP connections in a Linux system:

netstat -nat | grep -i "tcp.*established"
Copy after login

This command will return the number of TCP connections currently established. The higher the number of connections established, the lower the TCP/IP performance of the system will be.

7. Use sysctl to view TCP/IP parameters

sysctl is a CLI utility that manages kernel parameters. You can use it to view and change TCP/IP parameters.

The following is the command to view the TCP/IP parameters:

sysctl -a | grep tcp
Copy after login

We can change these parameters as needed by using the following command:

sysctl -w <parameter=value>
Copy after login

For example, the following command will change The maximum memory compression size of the TCP stack:

sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'
Copy after login

8. Use tcpdump to monitor network traffic

tcpdump is a command line utility tool for capturing network data packets. You can use it to monitor network traffic to find network faults or bottlenecks.

The following is the command to capture inbound and outbound TCP traffic using the tcpdump command:

tcpdump -i eth0 -vv tcp
Copy after login

Its output can be redirected to a file and then viewed using wireshark:

tcpdump -i eth0 -vv tcp -w <filename>
wireshark <filename>
Copy after login

in conclusion

The network performance of Linux systems can be improved by appropriately configuring TCP/IP and network parameters. Through the CLI and kernel tools provided in this article, administrators can better understand the network performance of the system and optimize it. This article provides code examples to help administrators better understand how to optimize TCP/IP performance and network performance.

The above is the detailed content of How to optimize TCP/IP performance and network performance of Linux systems. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!