encode / httpcore

A minimal HTTP client. ⚙️
https://www.encode.io/httpcore/
BSD 3-Clause "New" or "Revised" License
465 stars 105 forks source link

Connection pool optimization: reduce connection maintenance loops complexity #929

Open MarkusSintonen opened 4 months ago

MarkusSintonen commented 4 months ago

Summary

This is a small low hanging fruit for optimizing and simplifying the connection maintenance loops in the connection pool. This work is based on suggestion by @T-256 here (thanks!). Previously performance of httpcore degraded as connection count increased in the pool. As the maintenance loops had to do more and more work iterating and reiterating the connections.

This optimization brings the performance of httpcore to same level as urllib3 with sync-usage.

The benchmarks below include the socket polling fix. (The socket polling problem makes request processing latency so highly varying that it overshadows everything.)

Previously with sync (with optimized socket polling): new_expiry_sync

PR with sync: sync_new

As it can be seen the performance gets to exact same level as urllib3. There is almost no overhead from httpcore related request processing anymore.

Checklist

MarkLux commented 2 months ago

wonder if there are any further progress for this PR, our team are waiting for this fix @MarkusSintonen @T-256

MarkusSintonen commented 2 months ago

@MarkLux I don't know where the author has gone :/