dimba
dimba

Reputation: 27571

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?

P.S.

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. 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?

Upvotes: 2

Views: 749

Answers (3)

Karoly Horvath
Karoly Horvath

Reputation: 96258

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.

Something like 10-20 seconds should be fine, but this is depends on how important your task is...

Upvotes: 2

tjg184
tjg184

Reputation: 4676

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.

Upvotes: 1

Peter Alexander
Peter Alexander

Reputation: 54270

That's up to you really, but I imagine something like 10-20 seconds would be a reasonable time out.

Apache's default KeepAliveTimeout is 15 seconds, so that's one standard you could use.

Upvotes: 0

Related Questions