I am developing a client which connects to server through TCP. Servers are configured such that if one server is down, connection is set up with another server.
My requirement is that if TCP connection is not established with the 1st server within 2s, client needs to establish connection with the 2nd server.
Below is my observation based on testing- TCP SYN message is sent by client to the 1st server to establish connection. Since 1st server is down, after 1s, TCP SYN retransmission is sent to the 1st server. After 2s(owing to processing and network delays), TCP SYN message is sent to the 2nd server by the client. So its taking 3s (1s + 2s) for the SYN message to be sent to the 2nd server, which is not what I wanted. I want the TCP SYN message to be sent to 2nd server within 2s.
In order to send TCP SYN message to the 2nd server within 2s, I want to avoid TCP SYN retransmission.
I tried setting net.ipv4.tcp_syn_retries=0 in /etc/sysctl.conf. But I get 1 TCP SYN retransmission.
So is there any way to disable TCP SYN retransmission from userspace without changing the kernel source?
My requirement is that if TCP connection is not established with the 1st server within 2s, client needs to establish connection with the 2nd server.
In this case just do a connect with a timeout of 2 seconds at the client and if the connect does not succeed retry with the other server. Once you have closed the socket the kernel will stop trying to connect to the first server. This is much better and more independent from a specific platform than to fiddle with the built in reliability behavior and timing of TCP.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments