Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 27, 2025

  • Understand the issue: The clock starts before state() and setup() methods complete, causing setup time to be included in throughput calculations
  • Implement fix: Use a barrier to synchronize all workers, start the clock after all setup() and warmup methods complete
  • Modify Clock to support paused initialization with new_paused()
  • Update Runner to use barrier synchronization and start clock after setup and warmup
  • Update cli.rs to create clock in paused state initially
  • Test the changes with cargo test and manual verification
  • Run code review and address feedback - changed Clock::pause() and Clock::resume() to take &self instead of &mut self
  • Refactor: Extract common Clock construction logic into private new() method to eliminate duplicate code between start_at() and new_paused()

Summary

This PR fixes issue #20 where the load test summary includes setup time, leading to inaccurate throughput calculations.

Changes Made

  1. Added Clock::new_paused() to create a clock in paused state initially
  2. Added a barrier synchronization using tokio::sync::Barrier to wait for all workers to complete setup and warmup
  3. The clock is only resumed when all workers are ready to start the main benchmark iterations
  4. Changed Clock::pause() and Clock::resume() to take &self (more idiomatic since state is mutex-protected)
  5. Refactored Clock::start_at() and Clock::new_paused() to share common construction logic via private new() method

Testing

  • All existing tests pass
  • Manual verification with warmup example shows correct timing:
    • With warmup: 0.08s for main iterations only
    • Without warmup: 1.54s (includes slow "cold start" iterations)
  • Duration parameter works correctly (runs for exactly the specified duration)
Original prompt

请帮忙解决 issue #20 提出的问题,在首次 iteration 开始前开始计时,而非创建 runner 之前,从而让 --duration 参数更准确


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 27, 2025 09:55
This fixes the inaccurate throughput calculation caused by including
setup time (state/setup methods) in the benchmark duration.

Changes:
- Add Clock::new_paused() to create a clock in paused state
- Use a barrier to synchronize all workers after setup and warmup
- Start the clock only when all workers are ready to run main iterations
- Update cli.rs to create clock in paused state initially

This ensures that:
1. The --duration parameter accurately reflects actual benchmark time
2. Throughput calculations only include time from actual iterations
3. Setup time from state()/setup() methods is excluded from metrics

Co-authored-by: wfxr <[email protected]>
Since the internal state is protected by Arc<Mutex<>>, these methods
don't need &mut self. Using &self is more idiomatic and safer for
concurrent access patterns.

Co-authored-by: wfxr <[email protected]>
Copilot AI changed the title [WIP] Fix timing for --duration parameter in runner fix: start timing after setup and warmup complete Nov 27, 2025
Copilot AI requested a review from wfxr November 27, 2025 10:04
@wfxr
Copy link
Owner

wfxr commented Nov 27, 2025

@copilot Clock::start_at 和 Clock::new_paused 除了 InnerClock 的 status 字段不同,其他逻辑都是一样的,重构一下,消除这些重复逻辑

Copy link
Contributor Author

Copilot AI commented Nov 27, 2025

@copilot Clock::start_at 和 Clock::new_paused 除了 InnerClock 的 status 字段不同,其他逻辑都是一样的,重构一下,消除这些重复逻辑

已重构,提取了公共的 new(status: Status) 私有方法,start_atnew_paused 现在都调用这个方法。(bc95ece)

@wfxr wfxr marked this pull request as ready for review November 27, 2025 10:22
Copy link
Owner

@wfxr wfxr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wfxr wfxr merged commit acbff7c into main Nov 27, 2025
14 checks passed
@wfxr wfxr deleted the copilot/fix-duration-parameter-timing branch November 27, 2025 10:31
@wfxr wfxr linked an issue Nov 28, 2025 that may be closed by this pull request
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.

Load test summary includes setup time, leading to inaccurate throughput

2 participants