Skip to content

fix: use total_rps instead of current_rps in HTML report and navbar stats#3384

Merged
cyberw merged 2 commits intolocustio:masterfrom
juliosuas:fix/html-report-use-total-rps
Apr 1, 2026
Merged

fix: use total_rps instead of current_rps in HTML report and navbar stats#3384
cyberw merged 2 commits intolocustio:masterfrom
juliosuas:fix/html-report-use-total-rps

Conversation

@juliosuas
Copy link
Copy Markdown
Contributor

Summary

Fixes #3355.

The stats API endpoint used current_rps (a ~10-second sliding-window average) to populate total_rps and total_fail_per_sec in the report payload. This made the HTML report inconsistent with the final console summary, which correctly uses total_rps (total requests ÷ elapsed time) since #1152.

Root Cause

# locust/web.py line 486
report["total_rps"] = total_stats["current_rps"]         # ← wrong
report["total_fail_per_sec"] = total_stats["current_fail_per_sec"]  # ← wrong

Fix

report["total_rps"] = total_stats["total_rps"]           # ✓ aggregate rate
report["total_fail_per_sec"] = total_stats["total_fail_per_sec"]    # ✓

Since the HTML report is a post-test artifact representing the entire run, it should always show the aggregate rate — not whatever the last ~10 seconds happened to look like.

The stats endpoint used current_rps (a ~10-second sliding-window average)
for the report's total_rps and total_fail_per_sec fields.  This made the
HTML report inconsistent with the final console summary, which correctly
uses total_rps (total requests / elapsed time) since the fix in locustio#1152.

As the HTML report is a post-test artifact representing the entire run,
it should always show the aggregate rate, not a stale snapshot of
activity during the last few seconds of the test.

Also fix total_fail_per_sec for the same reason.

Fixes locustio#3355
@juliosuas
Copy link
Copy Markdown
Contributor Author

Added some context: I traced this through web.py line 486 where report['total_rps'] = total_stats['current_rps'] was using the sliding-window metric. The fix simply uses total_stats['total_rps'] and total_stats['total_fail_per_sec'] instead — both are already present in the stats dict from to_dict(). The frontend's HtmlReport.tsx already had totalRps in its table structure (line 29), so this was purely a backend data source mismatch. Happy to add a test if that would help.

@cyberw
Copy link
Copy Markdown
Collaborator

cyberw commented Mar 30, 2026

Nice! The fix looks good. No need for the code comments, and would love to see a test case too! Funny how I wasn’t able to reproduce it..

@juliosuas
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, @cyberw! I've pushed two changes:

  1. Removed the inline comments — agree the code is self-explanatory without them
  2. Added a test test_html_report_uses_total_rps_not_current_rps that logs two requests, hits /stats/requests, and asserts the report-level total_rps matches the Aggregated entry's value (total_requests / elapsed_time) rather than the sliding-window metric

The test follows the same pattern as the existing test_stats() so it should fit right in. Let me know if you'd like any adjustments.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@juliosuas juliosuas force-pushed the fix/html-report-use-total-rps branch from 4701459 to 350e011 Compare April 1, 2026 18:41
@cyberw cyberw merged commit 27a2351 into locustio:master Apr 1, 2026
20 checks passed
@cyberw
Copy link
Copy Markdown
Collaborator

cyberw commented Apr 1, 2026

Thanks, great stuff!

@abhi2196
Copy link
Copy Markdown

abhi2196 commented Apr 2, 2026

Thanks @juliosuas for the fix!

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.

HTML report uses current_rps instead of total_rps for req/s column

3 participants