-
-
Notifications
You must be signed in to change notification settings - Fork 856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP/3 support. #275
Comments
I'm not too sure how to move this forward. Ideally I'd like to have a WIP pull request which we can rebase / amend until we're happy with the result. However I haven't really got a feel for how the code should integrate with httpx's connection management. Any hints on how to approach this problem? |
We'll need to add UDP support to our backend interface, that's definitely step 1. After that we need to see how we want to implement client storage so we can remember things like Alt-Svc headers between requests. Next would be landing an Anything I'm missing @encode/httpx-maintainers? |
I don't know enough about HTTP/3 to tell (for example, I'm not sure what the differences between QUIC and HTTP/3 and the associated aioquic APIs are?), but the approach highlighted by @sethmlarson sounds sensible to me. One thing I'm sure of is that we'll need to chunk this into multiple PRs, otherwise we risk ending up with a 1000 LOC+ PR that's a pain for everyone to look at. That way we can more easily track progress too.
Yup, and UDP support is definitely going to be a big chunk. HTTPX is currently very much coupled to TCP. In particular, right now a given
I think this should be an improvement over a basic design, right? (Under the hypothesis that remembering Alt-Svc headers will only allow us to skip the protocol switching phase of establishing an HTTP/3 connection.) So, in terms of planning, I tried to think about the various steps in a bit more detail. I could see something like:
Some resources I've come across:
|
Lots of great info @florimondmanca!! 🎉 I'm going to chime in here again at the idea of using AnyIO and adding our stream interface to that? |
As in, using AnyIO (see #296) to provide an Edit: also, since AnyIO mandates the same "strict context management everywhere" approach than Trio, it's highly probable we'd need to refactor some internals to comply with that requirement. One item in particular is the |
I don't see why the different connections should have any kind of coupling. The most straightforward approach is going to be opening a distinct UDP socket for every QUIC/HTTP3 connection so there will be a one-to-one mapping between socket and QUIC/HTTP3 connection. At a high level, an HTTP3 connection is going to be very similar to an HTTP2 connection: you can run any number of requests on top of your connection.
HTTP3 support has landed in cURL and more recently in Chrome/canary so I'd suggest looking into how they handle Alt-Svc.
You might want to add aioquic's demo HTTP client: https://github.com/aiortc/aioquic/blob/master/examples/http3_client.py |
I tried to follow the guide written by @tomchristie above. The first step was
It has been implemented in #339 @florimondmanca , @tomchristie Update |
@cdeler Well, it's about as complex as you could get for a contribution, but if you're up for it then I can certainly put in the guidance for a sensible way to approach it. The keyword here, as with anything like this, will be incremental. 😀
At that point we've got a stub behaviour for detecting HTTP/3 support, which we can start to iterate on. |
it's smart behaviour to make incremental changes, I'm happy to try doing that |
Slight update - let's scratch the second part of that, actually I think we'll want to use the We'll use that because we don't want to wait for response headers before we decide on if we should upgrade. The |
It's looking to me like
So I think the best we'll be able to do is storing |
Have you seen this example in the aioquic repo? |
@cdeler — Sure, it was posted by Jeremy (OP) in the issue description. :-) Obviously looks outdated by now since some bits of HTTPX API have changed, but I'm sure it's been discussed earlier in this thread? |
Any way to make this work again? Currently getting NotImplementedError |
I've submitted aiortc/aioquic#203 to update the httpx demo for recent httpcore versions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump still important. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump, still relevant. |
Any updates? |
bump |
|
So, I'm absolutely in favour of someday having support for HTTP/3, yup. But also... "Any updates?", "bump", "+" aren't valuable in any way. More interesting would be illustrations of genuine motivations for wanting HTTP/3 support. What context are you using it in & why do you want a client that supports it? I'm interested in cases that go beyond "I want it because it exists". |
Well at SearXNG we would want it in order to decrease the loading time when fetching some data from a website that support HTTP3. This would make the experience much snappier for the users of SearXNG. |
I am a solana dev. they just announced that they are using quic as an option. I am a contributor to the solana python library. I also build stuff on top that. I tried using aioquic. it works, but the latency is worse than using a regular http/1.1 using httpx. ~1.4s on aioquic, and ~0.7s on httpx. (for two concurrent request from initial request time, until closing the connection.) I don't know if the reason is because aioquic has to bind to the raw ip socket first. |
This doesn't surprise me. My expectation is that in Python, using HTTP/3 will generally be slower, because of the increased complexity. I can get that it might be useful for us to include for general debugging/tooling purposes, tho. |
once a connection has been established though, it works amazingly. bulk requests is excellent using quic. |
This does surprise me, measurements I made show good connection setup time and throughput against most servers. |
were your servers local or on the cloud handling hundreds, possibly thousands of requests per second sir? the post requests made is to a solana rpc. perhaps I am doing something wrong. |
The servers were distant, the results I mention are runs of aioquic's interop suite against a variety of servers, and the acceptance criterion is that the time to download 5MB and 10MB files over HTTP/3 must no more than 10% over HTTP/1.1 or HTTP/2 (using httpx). I'm not sure the server's load is relevant here as we are talking about client performance. I don't think you're doing anything wrong, there are definitely some reports of initial connection time outliers using aioquic, which can kill the measured performance. I haven't managed to debug these cases yet but I do believe they are fixable. |
That's a positive snippet of info. I should be more precise in what I mean to say here. I wouldn't assume that HTTP/3 for |
thanks team for your efforts. may I ask if we should expect something? or shall I continue with aioquic? |
You'll see updates here if/when someone starts working on integrating HTTP/3 support into I expect it'll happen sometime. I'm up for supervising a pull request to get the support in, if someone wants to take it on. |
I'm interested in trying at moving this forward, but I'm still a beginner in these code bases. The summary at #275 (comment) seems the most thorough. Am I correct in understanding that the next step is to detect
It seems like you had been originally thinking that there should be support for a |
Nope. We'd have an However, I'd probably suggest starting this off from a different direction... Start by testing out @jlaine's |
It was not working, but it is now in aiortc/aioquic#333 or aiortc/aioquic#314 — whether it's truly all good will take a more thorough suite of tests. |
aiortc/aioquic#314 is approved and merged, so we have a working example to work from if you want to continue to provide guidance. |
I have opened a pull request that adds HTTP3 support. |
All our ingest endpoints support HTTP/2 and some even HTTP/3 which are significantly more efficient compared to HTTP/1.1 with multiplexing and, header compression, connection reuse and 0-RTT TLS. This patch adds an experimental HTTP2Transport with the help of httpcore library. It makes minimal changes to the original HTTPTransport that said with httpcore we should be able to implement asyncio support easily and remove the worker logic (see #2824). This should also open the door for future HTTP/3 support (see encode/httpx#275). --------- Co-authored-by: Ivana Kellyer <[email protected]>
It would be nice to start planning support for HTTP/3. aioquic provides a sans-I/O API for HTTP/3 similar to h2 which would make such an integration possible.
The main hurdle is that the connection model is very different to HTTP/1.1 and HTTP/2 : we cannot simply establish a (reader, writer) pair over a TCP connection and pass this to the protocol layer. Between the HTTP/3 layer and the UDP transport, we have a QUIC layer which returns (datagram, addr) tuples indicating where datagrams need to be sent:
https://aioquic.readthedocs.io/en/latest/quic.html#aioquic.quic.connection.QuicConnection.datagrams_to_send
Note that the destination address may change during the connection's lifetime, for example in response to receiving a PreferredAddress from the server during the TLS handshake.
In order to provide a first demonstration, @tomchristie suggested I write a dispatcher which makes use of aioquic's HTTP/3 support. The code is still a bit rough, but it works:
https://github.com/aiortc/aioquic/blob/master/examples/httpx_client.py
This can be run as:
python examples/httpx_client.py https://cloudflare-quic.com/
See also encode/httpcore#173
The text was updated successfully, but these errors were encountered: