Performance Optimizations for Near-Zero Check-In Latency#389
Open
VedanthR5 wants to merge 1 commit intojdholtz:developfrom
Open
Performance Optimizations for Near-Zero Check-In Latency#389VedanthR5 wants to merge 1 commit intojdholtz:developfrom
VedanthR5 wants to merge 1 commit intojdholtz:developfrom
Conversation
Owner
|
Thanks for the PR! A quick scan over it, and this looks very good. I've wanted to try session pooling for a while. Do you have the logs for a check-in that succeeded with these changes? I unfortunately won't have another check-in before Southwest removes the check-in policy. |
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.
Performance Optimizations for Near-Zero Check-In Latency
Title
perf: Add HTTP session pooling, connection pre-warming, and optimized retry delays for faster check-ins
Description
This PR implements several performance optimizations to minimize latency during the critical check-in window. Since Southwest check-in opens exactly 24 hours before departure, every millisecond counts.
Summary of Changes
lib/utils.pylib/checkin_handler.py,lib/checkin_scheduler.pylib/utils.pylib/utils.pyDetailed Changes
1. HTTP Session Pooling (
lib/utils.py)Problem: Each
requests.post()/requests.get()call created a new TCP connection, requiring a full TCP handshake + TLS negotiation (~100-300ms overhead).Solution: Added
create_session()function that returns a configuredrequests.Sessionwith connection pooling viaHTTPAdapter:Updated
make_request()and_do_request()to accept an optionalsessionparameter for connection reuse.2. Session Management (
lib/checkin_scheduler.py)Added session lifecycle management to
CheckInScheduler:sessionproperty - Lazy initialization of sessionclose_session()- Clean up session resourcesrefresh_session()- Close old session and create new one (useful before check-in)pre_warm_connection()- Makes a lightweight HEAD request to establish the connection pool3. Connection Pre-Warming (
lib/checkin_handler.py)In
_wait_for_check_in(), added pre-warming right before the check-in attempt:Updated
_check_in_to_flight()to pass the session to both POST requests.4. Exponential Backoff for Check-In Retries (
lib/utils.py)Before: Fixed 500ms delay between retries
After: Exponential backoff starting at 50ms, doubling each attempt (capped at 500ms)
This allows faster recovery on transient failures while preventing server overload.
5. Improved NTP Timing (
lib/utils.py)pool.ntp.orgTesting
All 329 unit tests pass with these changes.
New tests added:
test_create_session_returns_configured_sessiontest_do_request_uses_session_when_providedtest_do_request_uses_session_for_get_when_providedtest_make_request_uses_session_when_providedtest_session_property_creates_session_lazilytest_close_session_closes_and_clears_sessiontest_refresh_session_closes_old_and_creates_newtest_pre_warm_connection_makes_requesttest_pre_warm_connection_handles_errors_gracefullytest_get_current_time_returns_a_datetime_from_tertiary_ntp_serverUpdated tests:
refresh_sessionandpre_warm_connectionmethodspytest tests/unit -q # 329 passed in 1.86sPerformance Impact
Estimated total latency reduction: 200-500ms for the check-in request sequence, which can be the difference between boarding positions A1 and B30.
Breaking Changes
None. All changes are backward compatible:
make_request()session parameter is optional (defaults toNone)Checklist
pytest tests/unit)developbranch