Take the 2-minute tour ×

I have a website and application which use a significant number of connections. It normally has about 3,000 connections statically open, and can receive anywhere from 5,000 to 50,000 connection attempts in a few seconds time frame.

I have had the problem of running out of local ports to open new connections due to TIME_WAIT status sockets. Even with tcp_fin_timeout set to a low value (1-5), this seemed to just be causing too much overhead/slowdown, and it would still occasionally be unable to open a new socket.

I've looked at tcp_tw_reuse and tcp_tw_recycle, but I am not sure which of these would be the preferred choice, or if using both of them is an option.

share|improve this question
Did you try socket option SO_REUSEADDR already? –  User1 Jun 21 '11 at 13:47
What's the output of cat /proc/sys/net/ipv4/ip_local_port_range? if not 1024 65535, you may change it with echo 1024 65535 > /proc/sys/net/ipv4/ip_local_port_range –  Pablo Castellazzi Jun 21 '11 at 13:55

1 Answer 1

According to Linux documentation, you should use the TCP_TW_REUSE flag to allow reusing sockets in TIME_WAIT state for new connections.

It seems to be a good option when dealing with a web server that have to handle many short TCP connections left in a TIME_WAIT state.

As described here, The TCP_TW_RECYCLE could cause some problems when using load balancers...

share|improve this answer

Your Answer


