The following changes will make sure Linux will clear unused connections faster:
Important: This solution requires adjusting Linux kernel parameters. You should make a note of the original values so you can reset them if necessary.
- To reduce the timeout wait time for closed sockets, change the value of the kernel parameter from its default of 60 to a smaller number, for example, 30.
sysctl -w net.ipv4.tcp_fin_timeout=30
- To increase the maximum number of ports available to applications. Change the value of the kernel parameter from its default of 28232 to a higher wider range, for example, 1024 to 65535.
sysctl -w net.ipv4.ip_local_port_range=1024 65500
The values specified here are just examples, you may have to try different values based on your systems load.