views:

395

answers:

1

I am trying to understand the relation between TCP/IP and HTTP timeout values. Are these two timeout values different or same? Most Web servers allow users to set the HTTP Keep Alive timeout value through some configuration. How is this value used by the Web servers? is this value just set on the underlying TCP/IP socket i.e is the HTTP Keep Alive timeout and TCP/IP Keep Alive Timeout same? or are they treated differently?

My understanding is (maybe incorrect): The Web server uses the default timeout on the underlying TCP socket (i.e. indefinite) regardless of the configured HTTP Keep Alive timeout and creates a Worker thread that counts down the specified HTTP timeout interval. When the Worker thread hits zero, it closes the connection.

EDIT: My question is about the relation or difference between the two timeout durations i.e. what will happen when HTTP keep-alive timeout duration and the timeout on the Socket (SO_TIMEOUT) which the Web server uses is different? should I even worry about these two being same or not?

+2  A: 

They're two separate mechanisms; the name is a coincidence.

HTTP keep-alive (also known as persistent connections) is keeping the TCP socket open so that another request can be made without setting up a new connection.

TCP keep-alive is a periodic check to make sure that the connection is still up and functioning. It's often used to assure that a NAT box (e.g., a DSL router) doesn't "forget" the mapping between an internal and external ip/port.

Mark Nottingham
Hello Mark,Thanks for your answer. I think I didn't phrase the question properly. My question is about the relation or difference between the two timeout durations i.e. what will happen when HTTP keep-alive timeout duration and the timeout on the Socket (SO_TIMEOUT) which the Web server uses is different? should I even worry about these two being same or not?As far as my original question goes, I think your answer is right. Thanks
Suresh Kumar
SO_TIMEOUT (which looks like it's Java-Specific) is a timeout for activity on the socket itself; if there isn't any activity on the socket for that amount of time, the OS will close the socket.So, it's probably best to make sure that it's higher than the timeout on the HTTP keep-alive (since part of using keep-alive is to have idle connections sitting around, waiting for more requests).Cheers,
Mark Nottingham