Skip to content

HTTP/2 refactoring - #612

Merged
lovelydinosaur merged 3 commits into
masterfrom
http2-refactor
Dec 7, 2019
Merged

lovelydinosaur merged 3 commits into
masterfrom
http2-refactor

Conversation

@lovelydinosaur

Copy link
Copy Markdown
Member

This is my first draft onto refactoring the HTTP/2 implementation into something a bit more comprehensible and less brittle.

It's possible that the current implementation might be slow - I think we need to be listening in the background for WindowUpdated events while we're sending the data, rather than sending data until the flow control window hits zero, and then listening for a WindowUpdated event. I've not thought that all through enough.

Probably worth trying it out on a couple of sites to see if I've got that right or not.

It's a really nice, clear, clean-up tho. We actually have a proper isolated HTTP2Stream rather than just mangling all the state on a single class.

@lovelydinosaur lovelydinosaur added the refactor Issues and PRs related to code refactoring label Dec 6, 2019
@lovelydinosaur
lovelydinosaur marked this pull request as ready for review December 6, 2019 16:59
@lovelydinosaur

Copy link
Copy Markdown
Member Author

I've given this a run around and it's looking really good to me so far.

Hanging on www.yahoo.com, which I can't figure out - I don't recall if we'd resolved that fully or not. Haven't tested with 0.8 so see if it's a regression or not.

@pquentin

pquentin commented Dec 6, 2019

Copy link
Copy Markdown
Contributor

Hanging on www.yahoo.com, which I can't figure out - I don't recall if we'd resolved that fully or not. Haven't tested with 0.8 so see if it's a regression or not.

I think you're looking for #236. You memory served you well, it's not a regression as the issue was only partially resolved.

@lovelydinosaur lovelydinosaur changed the title First pass at HTTP/2 refactoring HTTP/2 refactoring Dec 7, 2019
@florimondmanca
florimondmanca self-requested a review December 7, 2019 09:06
@lovelydinosaur

Copy link
Copy Markdown
Member Author

Btw. I'd recommend reviewing by looking at the new implementation itself rather than reviewing the diff.

@lovelydinosaur

Copy link
Copy Markdown
Member Author

Note that this change will also let use drop TimeoutFlags and fork, given that we’ve got a nice simple “send the request, read the response” flow. As it turns out we just don’t need to perform concurrent read/writes. As a result it’ll also give use sync support for HTTP/2.

@florimondmanca florimondmanca added the http/2 Issues and PRs related to HTTP/2 label Dec 7, 2019

@florimondmanca florimondmanca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new implementation is so satisfying to read through. Great job! 👏

Comment thread httpx/dispatch/http2.py
Comment on lines +116 to +124
local_flow = self.state.local_flow_control_window(stream_id)
connection_flow = self.state.max_outbound_frame_size
flow = min(local_flow, connection_flow)
while flow == 0:
await self.receive_events(timeout)
local_flow = self.state.local_flow_control_window(stream_id)
connection_flow = self.state.max_outbound_frame_size
flow = min(local_flow, connection_flow)
return flow

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some duplicated lines here - possible refactor?

        while True:
            local_flow = self.state.local_flow_control_window(stream_id)
            connection_flow = self.state.max_outbound_frame_size
            flow = min(local_flow, connection_flow)
            if flow == 0:
                await self.receive_events(timeout)
                continue
            return flow

I can see that the current implementation really fits the docstring though, so not particularly urging about this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, may well be worthwhile. I’ll get this in as-is for now, and can follow up.

Comment thread httpx/dispatch/http2.py Outdated
@lovelydinosaur
lovelydinosaur merged commit f57bb2f into master Dec 7, 2019
@lovelydinosaur
lovelydinosaur deleted the http2-refactor branch December 7, 2019 14:14
Kludex referenced this pull request in pydantic/httpx2 May 11, 2026
* Enable mypy option `--warn-return-any`

* Remove type ignore comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http/2 Issues and PRs related to HTTP/2 refactor Issues and PRs related to code refactoring

Development

Successfully merging this pull request may close these issues.

3 participants