Repository navigation
Description
Goal
Make the http-core announce benchmark measure one HTTP tracker announce, as its name says, instead of the creation of a future that is never run, and add a guard that fails the test run when a benchmark routine does not execute.
Problem
packages/http-core/benches/http_tracker_core_benchmark.rs defines http_tracker_handle_announce_once/handle_announce_data. Its routine is b.iter(|| sync::return_announce_data_once(100)), where the helper is an async fn that builds the tracker services and awaits handle_announce 100 times.
Calling an async fn only creates a future. Criterion's synchronous b.iter times the closure, receives the future, and drops it without polling it, so the function body never runs. The Tokio runtime the benchmark builds is unused. The reported time, about 85-87 ns, is the cost of creating and dropping a 1160-byte future: it contains no announce and no service setup.
No production behavior is wrong, but the benchmark cannot change with the code it claims to measure, and nothing reports it: Criterion prints a precise result and cargo test --benches prints Success. docs/benchmarking.md lists it under Known Defects. Issue #2458 found and repaired the same defect in the udp-core connect_once benchmark.
Reproduction
Reproduced. A temporary counter, incremented on the first line of the helper's body, read 0 after Criterion ran about 12 million timed iterations:
$ cargo bench -p torrust-tracker-http-core --bench http_tracker_core_benchmark
Benchmarking http_tracker_handle_announce_once/handle_announce_data: Collecting 100 samples in estimated 1.0003 s (12M iterations)
time: [86.776 ns 87.118 ns 87.565 ns]
PROBE: function bodies run = 0, future size = 1160 bytes
The probe diff, the unmodified runs, and the toolchain are in the issue-local manual-verification-evidence.md that accompanies the specification.
Scope
- Restructure the HTTP announce benchmark like the repaired
udp-coreconnect_once: build the services and theAnnounceServiceonce, outside the measured routine, and time one awaitedhandle_announceper iteration withb.to_async(&runtime).iter(...). - Add a regression guard: the benchmark counts the routines it ran and panics after
bench_functionif the count is zero. Criterion runs each benchmark once undercargo test, and both the pre-push hook and CI runcargo test --benches, so a routine that never runs fails those gates. - Add the same guard to the
udp-coreconnect_oncebenchmark. - Update
docs/benchmarking.md: remove the Known Defects entry and describe the guard.
Out of scope: changing the HTTP announce code or its performance, benchmarking other HTTP operations, and an automatic check across all benchmarks.
Acceptance Criteria
cargo bench -p torrust-tracker-http-coretimes one awaited HTTP announce per iteration, and its result is consistent with that work.- The HTTP announce benchmark fails under
cargo test --bencheswhen its routine does not run (red before the fix). - The
udp-coreconnect_oncebenchmark has the same guard. docs/benchmarking.mdno longer lists the benchmark as a known defect and describes the guard.
The full specification, including the bug-fix process, regression-test strategy, plan, and manual verification, will be committed under docs/issues/open/.
Activity
docs(issues): [torrust#2479] add the HTTP announce benchmark bug spec…
docs(issues): [torrust#2479] require test-design and maintainer revie…
docs(pr-reviews): [torrust#2479] record the PR torrust#2480 review audit
Merge #2480: docs(issues): [#2479] add the HTTP announce benchmark bu…
docs(issues): [torrust#2479] record maintainer decisions before imple…
docs(issues): [torrust#2479] record the red run of the announce bench…
fix(http-core): [torrust#2479] make the HTTP announce benchmark measu…
refactor(http-core): [torrust#2479] track benchmark routines with a p…
test(udp-core): [torrust#2479] guard the connect_once benchmark again…
docs(issues): [torrust#2479] record the guard green runs, overhead in…
docs(benchmarking): [torrust#2479] document the routine guard and the…
docs(skills): [torrust#2479] point run-benchmarks at the routine guar…
docs(issues): [torrust#2479] record the like-for-like recheck and the…
docs(issues): [torrust#2479] link PR torrust#2509 and record the pre-…
docs(benchmarking): [torrust#2479] attribute the connect_once layout …
docs(pr-reviews): [torrust#2479] add the PR torrust#2509 review audit
Merge torrust#2509: fix(http-core): [torrust#2479] make the HTTP anno…
chore(issues): archive closed issue torrust#2479 spec to docs/issues/…
chore(issues): archive closed issue torrust#2479 spec to docs/issues/…
Merge #2515: chore(issues): archive closed issue #2479 spec to docs/i…
docs(issues): [torrust#2518] state the departure from the rotating pool
docs(issues): [torrust#2518] add specification for torrust#2518
docs(issues): [torrust#2518] state the departure from the rotating pool
Merge #2519: docs(issues): [#2518] add specification for #2518
Merge #2611: feat(http-core): [#2518] benchmark first HTTP announces …