views:

32

answers:

1

I have written a program that communicates with many servers at once using the asyncore module. For the most part I am just responding to data received from the servers, but occasionally I need to send some data "out-of-sync". With the default timeout of 30 seconds there is an obvious delay before the packet gets sent, so I have lowered the timeout to 0.1 for more responsiveness.

My question is: is it a good idea performance-wise to use a timeout with such a low value, and if not, is there another more performant way of accomplishing the same thing? What's the best practice for doing this?

+1  A: 

To answer my own question:

For this type of polling application it is necessary to have a small timeout value. The timeout specifies how long the internal select function blocks waiting for a socket to become active. If you are sending data frequently you need to set the timeout to a small value, so that select polls your socket for writable data at an acceptable interval. Otherwise select will block for too long before checking and can cause these kinds of delays.

In the end I used a timeout of 0.05 seconds.

Fara