简体   繁体   English

非阻塞连接超时

[英]Non-blocking connect timeout

I'm perform non blocking connect to server. 我正在执行非阻塞连接到服务器。

What an appropriate timeout value to be used in select to consider the server down/busy? 选择用于考虑服务器停机/忙碌的适当超时值是多少?

PS PS

Connect can fail since server is down or busy. 由于服务器关闭或繁忙,连接可能会失败。

In case server is down I always will always end with select timeout. 如果服务器关闭,我总是会以选择超时结束。

More interesting case is when server is busy. 更有趣的情况是服务器繁忙时。 IMHO 1 sec is enough for TCP handshake. IMHO 1秒足以完成TCP握手。 If it takes too long time to connect to server, than all communication with the server will be delayed. 如果连接服务器花费的时间太长,则与服务器的所有通信都会延迟。 So would it be reasonable decision wait on select max 1 sec? 那么,在选择最多1秒的时间内等待是否是合理的决定?

Packets can be lost in which case the node will resend it after a timeout so do not use a value that's just enough for a handshake. 数据包可能会丢失,在这种情况下,节点将在超时后重新发送它,因此请不要使用刚好足以进行握手的值。 You can play a bit with tcpdump , break the connection (unplug the ethernet cable) and see what's happening. 您可以使用tcpdump播放一些内容,断开连接(拔掉以太网电缆),然后看看发生了什么。

Something like 10-20 seconds should be fine, but this is depends on how important your task is... 大约10到20秒就可以了,但这取决于您的任务有多重要...

The connection to the server should be almost immediately. 与服务器的连接应几乎立即进行。 I think this could be somewhat subjective, but a few seconds should be more than sufficient. 我认为这可能有点主观,但几秒钟就足够了。 For some recent work we used 10 seconds, which has caught all of our cases. 对于最近的一些工作,我们使用了10秒,它捕获了我们所有的案例。

That's up to you really, but I imagine something like 10-20 seconds would be a reasonable time out. 确实由您决定,但是我想大约10到20秒是合理的超时时间。

Apache's default KeepAliveTimeout is 15 seconds , so that's one standard you could use. Apache的默认KeepAliveTimeout为15秒 ,因此这是您可以使用的一种标准。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM