perf: replace blocking urllib webhook with async httpx + connection pooling (issue #193)#197
Merged
Merged
Conversation
…ooling (issue #193) - Add httpx>=0.28.0 to dependencies with mypy override - Replace urllib + run_in_executor with httpx.AsyncClient using connection pooling (20 max connections, 10 keepalive, 30s keepalive expiry) - Add AlertManager.close() to clean up the httpx client; call from RealtimeListener.stop() - Move hmac import to module level (was inside _send_webhook) - Add _HTTPX_AVAILABLE graceful fallback when httpx is not installed - Update webhook tests to mock httpx.AsyncClient instead of urllib Closes #193
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #193. Replaces blocking
urllib+run_in_executorwebhook calls withhttpx.AsyncClientfor non-blocking async HTTP with connection pooling.Changes
httpx>=0.28.0to dependencies with mypy overrideAlertManager.__init__: added_httpx_clientfieldAlertManager._get_client(): lazily creates a sharedhttpx.AsyncClientwith connection pooling (20 max connections, 10 keepalive, 30s keepalive expiry)AlertManager.close(): new method to properly close the httpx clientAlertManager._send_webhook(): replacedurllib.request.urlopen+loop.run_in_executor(None, ...)withawait client.post(...)— fully non-blocking, no thread pool usage, connection reuse via keep-aliveRealtimeListener.stop(): now callsawait self._alert_manager.close()to clean up the http clienthttpxis not installed, logs an error and returns immediatelyhmacmoved to module level import (was inside_send_webhook)httpx.AsyncClientinstead ofurllib.request.urlopen; addedtest_send_webhook_skipped_when_httpx_unavailableTest Results