tags:

views:

214

answers:

5

Being curious, I wonder why HTTP, by design, can only handle one pending request per socket.

I understand that this limitation is because there is no 'Id' to associate a request to its response, so the only way to match a response with its request is to send the response on the same socket that sent the request. There would be no way to match a response to its request if there was more than one pending request on the socket because we may not receive the responses in the same order requests were sent.

If the protocol had been designed to have a matching 'Id' for requests and responses, there could be multiple pending requests on only one socket. This could greatly reduce the number of socket used by internet browsers and applications using web services.

Was HTTP designed like this for simplicity even if it's less efficient or am I missing something and this is the best approach?

Thanks.

+5  A: 

Not true. Read about HTTP1.1 pipelining. Apache implements it and Firefox implements it. Although Firefox disables it by default.

To turn it on in Firefox use about:config and write 'pipelining' in the filter.

see: http://www.mozilla.org/projects/netlib/http/pipelining-faq.html

slebetman
Thanks I'll read about that.
SelflessCoder
From what I just read, POST requests can't be pipelined. Most web services requests are POST. Wouldn't a matching ID for request and response allow better pipelining?
SelflessCoder
link: http://en.wikipedia.org/wiki/HTTP_pipelining
David
@Jeff, you are right for SOAP. but RESFful web services use other requests, including heavy use of GET requests for reading data.
tster
+1  A: 

One problem with sending multiple requests on a single socket is that it would cause inefficient queuing.

For instance, lets say you are in a store and there are 2 cashiers, and 10 people waiting to be checked out. The ideal way to make the line is to have a single queue of 10 people and the next person in line goes to a cashier when they become available. However, if you sent all the requests at once you would probably send 5 people to cashier A and 5 to cashier B. However, what if you sent the 5 people with the largest shopping carts to the same cashier? That's bad queuing and what could happen if you queued a bunch of requests on a single socket.

NOTE: I'm not saying that you couldn't use queuing well, but it keeps it simple to do it right if there is no queuing on a single socket.

tster
I agree that it's more complex to handle the requests queuing in the socket pool efficiently. But don't you think it worth the complexity as it could have drastic impact on scalability?
SelflessCoder
Yes. (more characters)
tster
+1  A: 

It's basically for simplicity; various proposals have been made over the years that multiplex on the same connection (e.g. SPDY) but none have taken off yet.

EricLaw -MSFT-
+1 for SPeeDY, this link (http://dev.chromium.org/spdy/spdy-whitepaper) nicely answer my question, thanks.
SelflessCoder
A: 

Also realize that HTTP doesn't necessarily mandate a Content-Length header to serve data. Even if each HTTP response was ID'd, how would you manage streaming binary content with no content length (HTTP/1.0 style)? or if the client sent the Connection: close header to have the client close due to non-known lengths?

To manage this you would have to HTTP chunk (already present) in multiplex (I don't think anyone implements this) and add some non-trivial work to many programs.

Xepoch
+1  A: 

There are a few concidertaions I would review.

The first is related to the nature of TCP itself. TCP suffers from 'head-of-line' blocking issue where there can only be a single outstanding (unacknowledged) request (connection/TCP level) in flight. Given traditional latencies this can be a problem from a load time user experience perspective compared to results of parallel connection scheme browsers employ today. The higher the latency of the link the larger the impact of this fundemental limitation.

There is also a concurrency issue in that sometimes you really want to load multiple resources incrementally / in parallel. Back in the day one of the greatest features mozilla had over mosaic was that it would load images and objects incrementally so you could begin to see what was going on and use a resource without having to wait for it to load. With fewer connections there is a risk in that for example loading a large image on page before a style sheet can be catastrophic from an experience point of view. Expecting some kind of mitigating intelligence or explicit configuration to optimally order requests may not be a realistic or ideal solution.

There are proposals such as HTTP over SCTP that will more or less totally correct the issue you raise at the transport level.

Einstein