16.03.2017 Views

Learning HTTP/2

akamai-learning-http2-preview-edition

akamai-learning-http2-preview-edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Flow Control<br />

A new feature in h2 is stream flow control. Unlike h1 where the server will send data<br />

just about as fast as the client will consume it, h2 provides the ability for the client to<br />

pace the delivery. (And, as just about everything in h2 is symmetrical, the server can<br />

do the same thing.) Flow control information is indicated in WINDOW_UPDATE<br />

frames. Each frame tells the peer endpoint how many bytes the sender is willing to<br />

receive. As the end point received and consumes sent data it will send out a WIN‐<br />

DOWS_UPDATE frame to indicate its updated ability to consume bytes. (Many an<br />

early implementor spent a good deal of time debugging window updates to answer<br />

the “Why am I not getting data?” question). It is the responsibility of the sender to<br />

honor these limits.<br />

A client may want to use flow control for a variety of reasons. One very practical reason<br />

may be to make certain one stream does not choke out others. Or a client may<br />

have limited bandwidth or memory available and forcing the data to come down in<br />

manageable chunks will lead to efficiency gains. Though flow control cannot be<br />

turned off, setting the maximum value of 2^31-1 effectively disables it, at least for<br />

files under 2 GB in size. Another case to keep in mind is intermediaries. Very often<br />

content is delivered through a proxy or content delivery network which terminated<br />

the <strong>HTTP</strong> connections. Because the different sides of the proxy could have different<br />

throughput capabilities, flow control allows a proxy to keep the two side closely in<br />

sync to minimize the need for overly taxing proxy resournces.<br />

Flow Control Example<br />

At the start of every stream, the window defaults to 65,535 ( 2^16-1 ) bytes. Assume a<br />

client end point A sticks with that default and their peer, B, sends 10,000 bytes. B<br />

keeps track of the window ( now 55,535 bytes ). Now, say A takes its time and consumes<br />

5,000 bytes and sends out a WINDOW_UPDATE frame indicating that its<br />

window is now 60,535 bytes. B gets this and starts to send a large file ( 4 GB ). Each<br />

send can only send up to the window size, 60,535 in this case. If at any point A wants<br />

to adjust how much data it receives it can raise or lower its window at will via WIN‐<br />

DOW_UPDATE frame.<br />

Priority<br />

The last important characteristic of streams is dependencies. Modern browser are<br />

very careful to ask for the most important elements on a web page first. In this way it<br />

improves performance by fetching objects in an optimal order. Once it has the HTML<br />

in hand, the browser generally needs things like cascading style sheets (CSS) and critical<br />

javascript before it can start painting the screen. Without multiplexing it needs to<br />

wait for a response to complete before it can ask for a new object. With h2, the client<br />

34 | Chapter 3: The Protocol

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!