Why the time wait value of redis is so high

142 1

I'm using redis to, using the connect function in code, and the connection is manually closed every request. But the recent iammutex 's a answer remind me about the number of connections in the system, so I see the following when I've a little traffic at night

netstat -na | grep 6379 | grep TIME_WAIT | wc -l
446

There are 446 time wait on the redis port. I don't know whether it's normal. If not, which parameters should be optimized?

4 Answers

58 0
echo 1>/proc/sys/net/ipv4/tcp_tw_reuse

Principle: once the client close of redis is a link, this link will go into the time wait state, and the link of the time wait state is turned off without active. Linux this default appears to be a long, specific value that seems to be a minute. ..
Unfortunately, a tcp link is dead by the source ip and port, the target ip and the port four variables. The four values of the client and server are fixed, so each time a new link is established, the link to the time wait is also notified, and you can't.
So execute the above command so that the link can reuse.

Added:/proc/sys/net/ipv4/tcp_tw_recycle, if set to 1, is a quick recovery of tw, and should be resolved

115 1

Hundreds of hundred shouldn't be high, and the manual close connection is said to send the quit command to redis? If it's, redis will actively disconnect when the quit command is sent, and the disconnected party in tcp doesn't actually maintain time wait. In fact, there isn't a big problem with the, the tw won't take up too much resources.
For too many, @ gaosboy said a bit of reuse, typically set the following tcp parameters to optimize the tcp connection.

vim/etc/sysctl.conf
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
/sbin/sysctl -p//使之生效

But I think the reason of sf is slow, really need to check it out. There's no problem on the network connection. And at the moment, the open page is 2s, and the average is 3s. If optimization is optimized, the speed increases more than ten times.

130 0
...