Preface
In the project, I wrote a MQTT client applet to test the upper limit of the number of connections of MQTTServer. After running for a period of time, an error was reported: Cannot assign requested address
I checked "Cannot assign requested address" on the Internet, which means that the Linux system cannot continue to assign ports to the client (exhausted), so the supervisor socket connection cannot be performed.
Positioning problem
1. View the available ports of the current Linux system
cat /proc/sys/net/ipv4/ip_local_port_range
The number of ports in the current system ranges from 20000 to 65534, so the number of ports that can be allocated is 25535. If my number of connections reaches 25535, the above error will be reported.
So how to adjust this port range?
Solution
1. Modify the port range
Execute: vim /etc/sysctl.conf , add the following content
#1000 to 65534 can be used by user programs, below 1000 are reserved ports for the system net.ipv4.ip_local_port_range = 1000 65534
Execute: sysctl -p
Check the port range again: cat /proc/sys/net/ipv4/ip_local_port_range
2. Configure the reuse configuration of tcp ports to improve port recycling efficiency
Execute: vim /etc/sysctl.conf and add the following content:
#TCP connection recovery
net.ipv4.tcp_max_tw_buckets = 6000000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 10
net.ipv4.route.max_size = 5242880
net.ipv4.ip_forward = 1
net.ipv4.tcp_timestamps = 1
Blogger: Test to make money
Motto: Focus on testing and automation, and strive to improve R&D efficiency; through testing and diligence to complete the original accumulation, through reading and financial management to financial freedom.
csdn:https://blog.csdn.net/ccgshigao
Blog Park: https://www.cnblogs.com/qa-freeroad/