views:

142

answers:

3

I am currently doing some network programming and had a couple questions concerning timeouts.

Is there a recommended timeout in doing a ping?

Also, is there a recommended timeout in doing a URL connection?

Edit: In my case, with the ping, I am just trying to see if a device is connected to the network. With the URL connection, I am trying to open a URL and get the text from it.

Thanks

A: 

In general I set a timeout of 60 seconds for a request (This varies if you are streaming many MB of files via a request).

There are two types of pings. Active pings where you actually ping a pingable component when requested and Passive pings where you ping a component in the background and just return a cached status when requested. In my application I still set these timeouts at 60s but if you think you want fail-fast feel free to set a smaller number.

Calm Storm
A: 

How do you expect your network to behave ? That will dictate how you regard the connections to behave and when you'd expect a timeout.

e.g. how many network jumps will your ping perform over ? How loaded are those devices in a normal scenario ?

Brian Agnew
I apologize for the lack of knowledge. What do you mean by network jumps and device load?
stjowa
+1  A: 

This depends on the where you're going to connect to.

To give an example: if you connect to another box in the same data center or even same rack, there are only few jumps (routers, switches, firewalls, ...) and connections should usually be established under a second - hence no need for a 30 second timeout (I'd set it to 5 seconds).

If you connect to a box on another continent, that's a totally different story. Packet loss, crowded routes and connections may slow down the connection. A timeout of 30s or 60s sounds fair.

Additionally, you should consider if you're client really wants to wait for 60 seconds. To give another example, if you connect to a web service in order to serve an HTTP request from a user. Waiting 60 seconds won't make much sense as the user will cancel/leave the request anyway. Furthermore, such blocking service calls might lead to a lot of waiting threads filling up the thread pool of your server - not a good thing. In this case, I'd set the timeout to 10 seconds and rather risk some "service not available" or similar page being thrown at the user as soon as the web service becomes slow.

sfussenegger