How to pack many requests in a single TCP packet with HTTP2 and HTTP3? #109703
-
Hello, With HTTP2 and HTTP3, we can fit many HTTP requests into a single TCP packet. How does that work for HttpClient in .NET? Let's suppose a code like this: var reqProfile = httpClient.GetAsync("/user/profile");
var reqPosts = httpClient.GetAsync("/user/posts");
var reqFavourites = httpClient.GetAsync("/user/favourites");
await Task.WhenAll(reqProfile, reqPosts, reqFavourites); Does HttpClient have an internal intelligence that fits all those requests together? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Strictly speaking, you're not guaranteed that those three requests will go to the same physical machine (Even ignoring things like loadbalancing), so the ability to somehow stuff them into the same packet may be non-helpful. And even if you are sending them to the same physical machine, devices along the network route can split them however they want. Is there a particular problem you're trying to solve here, that requires you put things into a single packet? Usually when an application needs to do something like this (eg, multiplayer games) they're manually constructing the packets at quite a low level (and normally using raw UDP/TCP, not HTTP). |
Beta Was this translation helpful? Give feedback.
-
There are no guarantees, but we do try to pack as much data into buffers before flushing it to the network as possible. Currently in the HTTP/2 implementation we have a queue ( |
Beta Was this translation helpful? Give feedback.
There are no guarantees, but we do try to pack as much data into buffers before flushing it to the network as possible.
Currently in the HTTP/2 implementation we have a queue (
Channel
) of frames to write to the connection, and we'll only flush after that channel is empty (or you reach some size limit).If you happen to have multiple requests being sent at exactly the same time and they're in that queue at the same time, it's possible they'll end up being sent together.