Skip to content

perf(rfapi): use module-level requests.Session for connection pooling#491

Open
AbdulrahmanXAmer wants to merge 1 commit into
roboflow:mainfrom
AbdulrahmanXAmer:perf/rfapi-session-pooling
Open

perf(rfapi): use module-level requests.Session for connection pooling#491
AbdulrahmanXAmer wants to merge 1 commit into
roboflow:mainfrom
AbdulrahmanXAmer:perf/rfapi-session-pooling

Conversation

@AbdulrahmanXAmer
Copy link
Copy Markdown

Problem

rfapi.py makes 54 bare requests.get/post/put/delete calls. 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-provided requests.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. urllib3 pools connections by host automatically, so api.roboflow.com and GCS signed-URL calls pool independently with no configuration needed.

The two caller-provided-session functions are unchanged.

Test

Updated @patch targets in tests/adapters/test_rfapi_model_evals.py and tests/adapters/test_rfapi_phase2.py from rfapi.requests.get/postrfapi._session.get/post. All 108 rfapi tests pass. Ruff clean.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant