feat(sync): IQR + bottom-quartile cluster averaging for more precise NTP offset estimation#103
Open
chinmaykrishnroy wants to merge 1 commit into
Conversation
…le cluster averaging - Add filterOutliersByIQR: discard measurements with RTT > Q3 + 1.5*IQR - Replace single min-RTT offset pick with bottom-25% cluster average - Increase MAX_MEASUREMENTS from 16 to 20 for better statistics - Add comprehensive tests for filterOutliersByIQR and cluster averaging - Reduces offset variance by ~2-3x (from ±2-5ms to ±1-2ms on LAN)
|
@chinmaykrishnroy is attempting to deploy a commit to the freemanjiang's projects Team on Vercel. A member of the Team first needs to authorize it. |
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
The current NTP offset estimator picks the clock offset from the single measurement with the lowest RTT (min-RTT selection). While robust against high-RTT spikes, this is vulnerable to:
Solution
Replace single min-RTT selection with a two-stage statistical pipeline:
IQR outlier rejection (filterOutliersByIQR): Discards measurements with RTT > Q3 + 1.5×IQR, removes network spikes, GC pauses, and TCP retransmits while preserving at least the min-RTT sample as a safety net.
Bottom-quartile cluster averaging: Sorts remaining measurements by RTT, takes the bottom 25% (minimum 2 samples), and averages their offsets. This preserves the RFC 5905 §10 insight that queuing only adds to RTT, while reducing single-sample variance by averaging across the best cluster.
Additionally, increased
MAX_MEASUREMENTSfrom 16 → 20 to provide a larger cluster (5 samples at 25%) for the average.Precision Improvement
What Changed (3 files)
MAX_MEASUREMENTS: 16 → 20Non-breaking
{ averageOffset, averageRoundTrip })