Non-serial pipelined HTTP possible?

2019-05-26 07:34发布

RFC 2616 section 8.1.2.2 states:

A client that supports persistent connections MAY "pipeline" its requests (i.e., send multiple requests without waiting for each response). A server MUST send its responses to those requests in the same order that the requests were received.

Serial responses are often more harm than good, since serial responses actually require the server to do more processing and negates the performance benefits gained by pipelining.

For example, if a HTTP client requests for files 1.jpg, 2.jpg, 3.jpg, 4.jpg, and 5.jpg, it doesn't matter if 3.jpg is returned before 1.jpg, or if 4.jpg is returned before 3.jpg. The client simply want the responses as soon as they are available, in any order.

How can a HTTP client gain the benefits of pipelining, and at the same time not pay for the disadvantages of response queueing?

标签: http
3条回答
Anthone
2楼-- · 2019-05-26 07:48

There is no default mechanism in the HTTP headers to identify which response would match which request. A response is known to be that to a specific request because of the order in which it's received. If you requested 1.jpg, 2.jpg, 3.jpg, 4.jpg, and 5.jpg and sent the responses in any order, you wouldn't know which one is which.

(You could implement your own markers in client and server headers, but you'd certainly not be compliant with the protocol and most implementations would not know how to deal with that. You would have to do some processing to map, which may negate the anticipated benefits of this parallel implementation too.)

The main benefits you get from the existing HTTP pipeline mechanism are:

  • Possible reduced communication latency. This may matter depending on your connection.
  • For request that require some longer server-side computation, the server could start this computation in the background, upon reception of the request, while it's sending a previous response, so as to be able to start sending the second result earlier. (This is also a form a latency, but in terms of response preparation.)

Some of these benefits can also be gained by more modern web-browser techniques, where multiple requests can be sent separately and parts of the page may be updated progressively (via AJAX).

查看更多
唯我独甜
3楼-- · 2019-05-26 07:50

It can't (in HTTP/1.1). It might be in a future version of HTTP.

查看更多
够拽才男人
4楼-- · 2019-05-26 08:08

A client can't circumvent HOL-queueing as it's part of RFC 2616. The only benefit of pipelining (in my opinion) is in extremely specific and narrow cases. Consider:

R1cost = Request A processing cost.
R2cost = Request B processing cost.
TCPcost = Cost of negotiating new TCP connection.

Using pipelining would, therefore, be viable in specific cases where:

R1costR2costTCPcost

How often is a request more expensive than a previous request and less expensive than negotiating a new TCP connection? Not often. I would add that Websockets are (by far) a more interesting and appropriate solution (as far as parallel back-end processing is concerned).

查看更多
登录 后发表回答