Improve latency calculation based on server timings and connect times - #127
Merged
Conversation
carlosefr
requested review from
HenriqueSFernandes,
andre-j3sus and
devandrepascoa
July 21, 2026 19:55
There was a problem hiding this comment.
Review: Improve latency calculation based on server timings and connect times
Summary
This PR improves latency accuracy in the BandwidthEngine by:
- Richer
Server-Timingparsing —cfGetServerTimenow matchescfReqDur/cfRequestDuration(case-insensitive, with variants) and falls back to summingcfSpeed*sub-metrics, replacing the previous single genericdur=match. - TCP RTT fine-tuning — a new
serverTimeDeltais calibrated from fresh TCP connections (HTTP < 3) by comparing the derived server time (ttfb - connectTime) against the server-reported time, blended with an EMA (weight 0.75). This delta is threaded throughMeasurementEngine,ParallelLatency, and persisted across sub-engines so calibration carries forward. - Config/doc cleanups —
estimatedServerTimedefault changed10 → 0;logAimApiUrldefault repointed fromaim.cloudflare.com/__logtospeed.cloudflare.com/__results; matching README/AGENTS.md doc updates. - Idle labeling — idle (non-loaded) latency requests now tagged with
during=idlequery param. - Tests — new unit test covering the three
cfGetServerTimebranches;cfGetServerTimeis now exported.
Overall the approach is reasonable and unit tests pass (101/101). The main issues are the unconditional debug console.log statements, which should not ship in a library, plus a few correctness edge cases worth confirming. Details inline.
|
Review posted successfully to PR #127 with 7 inline comments. Here's a summary of what I reviewed and flagged: What the PR changesImproves latency accuracy in
Also adds a unit test for Issues flagged inline
The review was posted as |
carlosefr
force-pushed
the
server_time_estimates
branch
3 times, most recently
from
July 22, 2026 09:11
5f4bbb2 to
7f71259
Compare
Improve accuracy of latency calculations by making use of additional "thinking time" sent by the server, and by using the observed TCP RTT as fine tuning.
carlosefr
force-pushed
the
server_time_estimates
branch
from
July 22, 2026 09:40
7f71259 to
d19d74e
Compare
andre-j3sus
approved these changes
Jul 22, 2026
devandrepascoa
approved these changes
Jul 22, 2026
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.
Improve accuracy of latency calculations by making use of additional "thinking time" sent by the server, and by using the observed TCP RTT as fine tuning.