Skip to content

Fix sender busy-wait between reply arrival and next probe - #19

Open
phr0stb1t3 wants to merge 1 commit into
nokia:masterfrom
phr0stb1t3:fix/sender-busy-loop
Open

Fix sender busy-wait between reply arrival and next probe#19
phr0stb1t3 wants to merge 1 commit into
nokia:masterfrom
phr0stb1t3:fix/sender-busy-loop

Conversation

@phr0stb1t3

Copy link
Copy Markdown

Closes #18.

The bug

TwampySessionSender.run() only ever blocks in the select immediately 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-timeout select until the next 1-second deadline — a pure busy-wait for interval - RTT out 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 select until the next probe deadline, or until endtime once 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 1000 against a local responder:

build wall CPU time CPU
original 9.07s 9.06s 100%
patched 9.09s 0.07s ~1%

0.0% packet loss, probes exactly 1s apart, -v reply log lines identical in format to the original. Full test suite: 12 passed.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session sender busy-waits between reply arrival and the next probe (one full core per session)

1 participant