Historical Reference — Superseded by Upstream Merge
The Phase 1-3 keepalive improvements proposed in this document were superseded by the upstream merge from
irlserver/main(completed at commitaa66a88). ACK throttling was removed and quality evaluation was enhanced upstream. This document is retained as a historical record of the design exploration. For the current model, seeEXTENDED_KEEPALIVE_FIX.mdanddocs/HOW_IT_WORKS.md.
This document tracks the implementation of improvements to SRTLA's load balancing and quality evaluation algorithms by leveraging connection information from extended keepalive packets.
The codebase already supports extended keepalive packets that include rich connection telemetry from the sender:
typedef struct __attribute__((__packed__)) {
uint32_t conn_id;
int32_t window; // SRT window size
int32_t in_flight; // Packets currently in flight
uint32_t rtt_ms; // Round-trip time in milliseconds
uint32_t nak_count; // NAK (retransmission) count
uint32_t bitrate_bytes_per_sec; // Client-side bitrate measurement
} connection_info_t;Packet Length: 38 bytes (extended keepalive)
Previous Status: This data was only parsed and logged, not used for decision-making.
Current Status: FULLY IMPLEMENTED - All telemetry data is now stored and used for quality assessment.
Location: src/protocol/srtla_handler.cpp (handler), src/quality/quality_evaluator.cpp (evaluation)
Rationale: Latency is often a better early indicator of connection problems than bandwidth. High or increasing RTT signals congestion, routing issues, or link instability.
Implementation:
- Store RTT values in
ConnectionStats - Track RTT history for trend analysis
- Add error points based on RTT thresholds
- Monitor RTT variance (jitter)
Error Point Thresholds:
- RTT > 500ms: +20 error points
- RTT > 200ms: +10 error points
- RTT > 100ms: +5 error points
- High RTT variance: +10 error points
Status: NOT STARTED
Rationale: The sender's NAK count provides ground truth about packet loss and retransmissions, which is more accurate than receiver-side estimation.
Implementation:
- Store sender NAK count in
ConnectionStats - Compare with receiver-side packet loss tracking
- Use NAK rate (NAKs per packet) for quality scoring
- Replace or supplement current loss detection
Error Point Thresholds:
- NAK rate > 20%: +40 error points
- NAK rate > 10%: +20 error points
- NAK rate > 5%: +10 error points
- NAK rate > 1%: +5 error points
Status: NOT STARTED
Rationale: The ratio of in_flight/window reveals how aggressively the sender is using each connection and can indicate congestion or throttling.
Implementation:
- Calculate window utilization ratio
- Detect persistently full windows (congestion)
- Detect low utilization (client-side issues)
- Use for advanced load balancing decisions
Analysis:
- Utilization > 95%: Possible congestion, reduce priority
- Utilization < 30%: Client throttling, investigate
- Optimal range: 60-80% utilization
Status: NOT STARTED
Rationale: Comparing sender and receiver bitrate measurements can detect path issues and validate metrics.
Implementation:
- Store sender bitrate in
ConnectionStats - Compare sender vs receiver measurements
- Alert on significant discrepancies (>20% difference)
- Use for debugging and diagnostics
Status: ✅ COMPLETED (2025-12-04)
- Add keepalive metrics fields to
ConnectionStats(receiver_config.h)uint32_t rtt_msuint32_t rtt_history[RTT_HISTORY_SIZE]uint8_t rtt_history_idxtime_t last_keepaliveint32_t windowint32_t in_flightuint32_t sender_nak_countuint32_t last_sender_nak_countuint32_t sender_bitrate_bps
- Modify
SRTLAHandler::handle_keepalive()to store metrics - Update connection stats with keepalive data
- Track timestamp of last keepalive received
- Add helper functions for RTT history and variance
- Add RTT-based error point calculation
- Add NAK rate error point calculation
- Add window utilization analysis
- Add bitrate comparison logic
- Test with simulated high-latency connections
- Test with varying packet loss scenarios
- Validate error point calculations
- Monitor impact on load balancing behavior
- Update keepalive-improvements.md with implementation details
- Document keepalive metrics in technical docs
- Add configuration parameters
- Update README.md with new quality metrics
- Earlier Problem Detection: RTT increases often precede bandwidth degradation
- More Accurate Loss Tracking: Sender NAK count is ground truth
- Better Load Distribution: Window utilization reveals true connection capacity
- Improved Debugging: Bitrate comparison helps diagnose path issues
- Reduced Latency: Penalizing high-RTT connections improves stream responsiveness
New parameters to add:
// RTT thresholds (milliseconds), graduated so worse RTT reaches worse tiers
inline constexpr uint32_t RTT_THRESHOLD_MODERATE = 100; // 100ms -> +5
inline constexpr uint32_t RTT_THRESHOLD_HIGH = 200; // 200ms -> +10
inline constexpr uint32_t RTT_THRESHOLD_CRITICAL = 500; // 500ms -> +20
inline constexpr uint32_t RTT_THRESHOLD_SEVERE = 1000; // 1000ms -> +30
inline constexpr uint32_t RTT_THRESHOLD_EXTREME = 2000; // 2000ms -> +40
// Window utilization thresholds
inline constexpr double WINDOW_UTILIZATION_CONGESTED = 0.95;
inline constexpr double WINDOW_UTILIZATION_LOW = 0.30;
// Bitrate comparison tolerance
inline constexpr double BITRATE_DISCREPANCY_THRESHOLD = 0.20; // 20%
// Jitter detection — stddev scored relative to mean RTT (coefficient of
// variation), not an absolute stddev, so normal cellular jitter on a healthy
// link is not penalized. Replaces the retired absolute RTT_VARIANCE_THRESHOLD.
inline constexpr double RTT_JITTER_RATIO_HIGH = 1.0; // stddev > 1.0*mean -> +5
inline constexpr double RTT_JITTER_RATIO_SEVERE = 1.5; // stddev > 1.5*mean -> +10- Mitigation: Only apply RTT-based penalties if keepalive received within last 2 seconds
- Mitigation: Fall back to receiver-side metrics if keepalives stale
- Mitigation: Use as supplementary data, not sole decision factor
- Mitigation: Validate against receiver measurements
- Mitigation: Use gradual error point increases, not binary decisions
- Mitigation: Maintain grace period for new connections
- Phase 1 (RTT): ✅ 100% complete
- Phase 2 (NAK): ✅ 100% complete
- Phase 3 (Window): ✅ 100% complete
- Phase 4 (Bitrate): ✅ 100% complete
Overall Progress: ✅ 100% (Implementation Complete)
Implementation Date: 2025-12-04 Build Status: ✅ Successful Next Steps: Testing and validation