perf(rfapi): use module-level requests.Session for connection pooling#491
Open
AbdulrahmanXAmer wants to merge 1 commit into
Open
perf(rfapi): use module-level requests.Session for connection pooling#491AbdulrahmanXAmer wants to merge 1 commit into
AbdulrahmanXAmer wants to merge 1 commit into
Conversation
57 bare requests.get/post/put/delete calls each opened a new TCP connection and TLS handshake. A module-level _session reuses connections via keep-alive; urllib3 pools by host so api.roboflow.com and GCS signed-URL calls pool independently. The two functions that accept a caller-provided session (get_version_export, get_search_export) are unchanged. Updated mock targets in tests from requests.get/post to _session.get/post to reflect the new call path.
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.
Problem
rfapi.pymakes 54 barerequests.get/post/put/deletecalls. Each one opens a new TCP connection and TLS handshake — wasted overhead on every API call. Bulk uploads and dataset downloads are hit hardest.Two functions (
get_version_export,get_search_export) already accepted a caller-providedrequests.Session, confirming this pattern was known but never applied globally.Fix
Add a module-level
_session = requests.Session()and route all 54 calls through it.urllib3pools connections by host automatically, soapi.roboflow.comand GCS signed-URL calls pool independently with no configuration needed.The two caller-provided-session functions are unchanged.
Test
Updated
@patchtargets intests/adapters/test_rfapi_model_evals.pyandtests/adapters/test_rfapi_phase2.pyfromrfapi.requests.get/post→rfapi._session.get/post. All 108 rfapi tests pass. Ruff clean.