Added persistent HTTP session support with connection pooling and improved retry handling#6
Open
Argu333 wants to merge 1 commit into
Open
Added persistent HTTP session support with connection pooling and improved retry handling#6Argu333 wants to merge 1 commit into
Argu333 wants to merge 1 commit into
Conversation
…roved retry handling.
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.
Added persistent HTTP session support with connection pooling and improved retry handling
Description
First-time contributor here, so please let me know if there are any changes needed to better align with project standards or contribution guidelines.
This PR optimizes the existing session management implementation by introducing persistent HTTP sessions with connection pooling and improving retry/backoff behavior.
Changes include:
requests.Session()instance to reuse connections across API calls.HTTPAdapterwith connection pooling (pool_connections=200,pool_maxsize=200).While this is marked as a new feature, the intent is primarily to optimize the existing implementation rather than introduce new functionality or alter the public API.
Motivation and Context
The existing implementation established a new HTTP connection for every API request. While functional, this became a significant bottleneck when executing large numbers of API calls, especially when using parallel processing.
By introducing persistent sessions and connection pooling:
Additionally, the existing retry logic maintained a global exponential backoff timer that did not reset after a retried request eventually succeeded. In long-running jobs, this would cause future transient failures to immediately inherit the maximum backoff delay, even after the system had recovered and requests were succeeding normally.
This change resets the backoff timer when a retried request succeeds, allowing future retries to start from the initial delay while still preserving exponential backoff protection during periods of sustained rate limiting or service instability.
How Has This Been Tested?
Test Environment
Functional Testing
I tested both:
ThreadPoolExecutorThe most significant improvements were observed during parallel execution, though sequential execution also showed noticeable performance gains.
Test Scenario 1
Workload:
Results before changes:
Results after changes:
I did not re-test the sequential version of this workload after implementing the changes.
Test Scenario 2
Workload:
Results before changes:
Results after changes:
Additional Notes
I also tested large threaded workloads using
ThreadPoolExecutorby submitting approximately:For all three test sizes, the overhead of creating and submitting futures to the executor remained relatively consistent at approximately 10-30 seconds. Once the API calls began executing, the impact of connection reuse and pooling became apparent.
Observed end-to-end runtimes were approximately:
These results were achieved using approximately 150 worker threads. The relatively small increase in runtime despite substantial increases in API volume highlights the scalability improvements gained from persistent sessions and connection pooling.
I verified:
Types of changes
Checklist
I have updated the documentation accordingly.
I have read the CONTRIBUTING document.
I have added tests to cover my changes if appropriate.
All new and existing tests passed.