httpcore icon indicating copy to clipboard operation
httpcore copied to clipboard

Connection pool optimization: reduce connection maintenance loops complexity

Open MarkusSintonen opened this issue 8 months ago • 2 comments

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

  • [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [x] I've updated the documentation accordingly.

MarkusSintonen avatar Jun 13 '24 18:06 MarkusSintonen