Fix sender busy-wait between reply arrival and next probe - #19
Open
phr0stb1t3 wants to merge 1 commit into
Open
Conversation
The session sender loop only blocked in the select immediately after sending a probe. When the reflected reply arrived, that select returned after one RTT, the reply was drained at the top of the loop, and the loop then spun on the zero-timeout select until the next 1-second deadline: a pure busy-wait costing (interval - RTT) of one core per interval, i.e. roughly one full core per sender session at the default probe rate. Move the wait out of the send branch: after draining replies and the endtime check, block on select until the next probe deadline, or until endtime once all probes have been sent. A reply still wakes the select early and is drained normally, so timing, sequencing, statistics and log output are unchanged. Loopback validation (10 probes, -i 1000, local responder): original: wall 9.07s, CPU 9.06s (100% of a core) patched: wall 9.09s, CPU 0.07s (~1%) 0.0% loss, probes exactly 1s apart, reply log lines unchanged. Full test suite: 12 passed.
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.
Closes #18.
The bug
TwampySessionSender.run()only ever blocks in theselectimmediately after sending a probe. When the reflected reply arrives, that select returns after one RTT, the reply is drained at the top of the loop, and the loop then spins on the zero-timeoutselectuntil the next 1-second deadline — a pure busy-wait forinterval - RTTout of every interval, i.e. roughly one full core per sender session at the default probe rate. See #18 for details.The fix
Move the wait out of the send branch: after draining replies and the endtime check, block on
selectuntil the next probe deadline, or untilendtimeonce all probes have been sent and only stragglers remain. A reply arriving still wakes the select early and is drained normally, so timing, sequencing, statistics, and log output are unchanged.Validation
Loopback, 10 probes at
-i 1000against a local responder:0.0% packet loss, probes exactly 1s apart,
-vreply log lines identical in format to the original. Full test suite: 12 passed.