Open Bug 1986567 Opened 1 month ago

[wpt-sync] Sync PR 54653 - [wptserve] Move the H2 server to an event loop

Categories

(Testing :: web-platform-tests, task, P4)

task

Tracking

(Not tracked)

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Sync web-platform-tests PR 54653 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/54653
Details from upstream follow.

Sam Sneddon <gsnedders@apple.com> wrote:

[wptserve] Move the H2 server to an event loop

Previously, we were seeing acquiring the H2ConnectionGuard lock being very expensive on Python 3.13 and later, as in Python 3.13 Lock.acquire began to release the GIL, and with the large numbers of threads we create for our H2 server we saw performance grind to a stand still. I believe this was the underlying cause of #51981.

Using asyncio, and using worker threads (via a worker pool) only for calling the handler code, we see this bottleneck go away.

Notably:

H2ResponseWriter now has to deal with a StreamWriter owned by another thread (this is unavoidable as we need to use a StreamWriter to handle async access to SSL sockets); this does introduce IPC here, but as far as I can tell this is still a net win even on older Python versions.

We no longer wrap the socket into an SSLSocket in WebTestServer for the http2 case, and we now store the context we create. We use this context only after the accept() call, which should provide no functional difference.

Otherwise: this is mostly a fairly simple replacement of threads with tasks.

You need to log in before you can comment on or make changes to this bug.