Skip to content

fix(http-core): make the HTTP announce benchmark measure the announce #2479

Closed

Description

@josecelano

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-core connect_once: build the services and the AnnounceService once, outside the measured routine, and time one awaited handle_announce per iteration with b.to_async(&runtime).iter(...).
  • Add a regression guard: the benchmark counts the routines it ran and panics after bench_function if the count is zero. Criterion runs each benchmark once under cargo test, and both the pre-push hook and CI run cargo test --benches, so a routine that never runs fails those gates.
  • Add the same guard to the udp-core connect_once benchmark.
  • 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-core times one awaited HTTP announce per iteration, and its result is consistent with that work.
  • The HTTP announce benchmark fails under cargo test --benches when its routine does not run (red before the fix).
  • The udp-core connect_once benchmark has the same guard.
  • docs/benchmarking.md no 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

  1. added
    Bug
    on Oct 8, 2026
  2. added 4 commits that reference this issue on Oct 8, 2026
  3. added theissue type on Oct 13, 2026
  4. self-assigned this
    on Oct 13, 2026
  5. added 12 commits that reference this issue on Oct 13, 2026
  6. added 8 commits that reference this issue on Oct 14, 2026
  7. added a commit that references this issue on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions