(reproduced) Redis: solution of Cannot assign requested address

I wanted to try redis today, and I wrote a program to access redis for 100,000 consecutive times, but the problem of Cannot assignrequestedaddress appeared. I thought it was a problem of redis at first (it may not be able to withstand so many visits), but redis was blown away by everyone. So NB, there won't be such a SB problem, so I googled it and found that it turned out to be:

The client frequently connects to the server. Because each connection ends in a very short time, resulting in a lot of TIME_WAIT, so that the available port number is used up, so the new connection cannot bind the port, that is, "Cannot assign requested address" ". It's a client-side problem, not a server-side problem. Through netstat, I do see a lot of connections in the TIME_WAIT state.
I found a solution from the Internet:
execute the command to modify the following 2 kernel parameters  

sysctl -w net.ipv4.tcp_timestamps=1 Enable support for TCP timestamps. If this item is set to 0, the following settings will not work

sysctl -w net.ipv4.tcp_tw_recycle=1 means to enable fast recycling of TIME-WAIT sockets in TCP connections

However, it seems that only the root user can have the authority to modify these two parameters. I happen to have the root authority of the machine. After modifying it, I found that it is really possible.

But if there is no root privilege how to solve it, I don't know if it can be obtained by modifying the program. Hope someone can give some pointers after seeing it!

 

 

 

Redis error: Cannot assign request

When the performance of Redis is tested on CentOS, it will report as soon as the number increases:

Could not connect to Redis at 127.0.0.1:6379: connect: Cannot assign request

After checking the official Wiki, the system network configuration problem has been solved:

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326970991&siteId=291194637