Worker Pool 防止饿死#51
Conversation
owent
left a comment
There was a problem hiding this comment.
AICR problem for src/atframe/modules/worker_pool_module.cpp:282
AI Code Review
AI Code Review SummaryWorker 睡眠时间统计问题Target: Worker Pool 防止饿死 审查范围审查 发现问题1.
|
| # | Severity | Category | Location | Message |
|---|---|---|---|---|
| 0 | MEDIUM | correctness | src/atframe/modules/worker_pool_module.cpp:500 |
cpu_time_sleep_us_ 会重复计算睡眠时间。当常规睡眠(line 467)和保护性睡眠(line 493)在同一迭代中执行时,busy_end_time 始终是第一次工作结束的时间点。Line 474 已将第一次睡眠时长加到 cpu_time_sleep_us_,而 line 500 计算的 sleep_rep = sleep_end_time - busy_end_time 包含了第一次睡眠时长和保护性睡眠时长,导致第一次睡眠被重复计算。 |
触发场景:Worker 在一次迭代中,tick 工作时间短于 tick_interval(触发常规睡眠),且累计的 busy+waited 时间达到 1 秒(触发保护性睡眠)。
建议修复:在保护性睡眠前捕获当前时间(如 preserve_sleep_start = std::chrono::system_clock::now()),在 line 500 使用 sleep_end_time - preserve_sleep_start 计算实际保护性睡眠时长。
|
| 1 | LOW | correctness | src/atframe/modules/worker_pool_module.cpp:501 | 保护性睡眠的时间未记录到 current_tick_second_waited_us_。Lines 482-483 将每秒计数器重置为 0 后,保护性睡眠的时长只被添加到 cpu_time_sleep_us_(line 500),但 current_tick_second_waited_us_ 未被更新,导致新的一秒内的等待统计缺失这段睡眠时间。 |
- Powered by AICodeReviewer*
Open Issues (2)
- [MEDIUM] correctness —
src/atframe/modules/worker_pool_module.cpp:500(new in7423828) - [LOW] correctness —
src/atframe/modules/worker_pool_module.cpp:501(new in7423828)
Resolved (1)
The following previously reported issues are no longer present:
✅ Resolved415dc25b23d3b529
There was a problem hiding this comment.
Pull request overview
This PR adds worker-pool throttling intended to prevent starvation by tracking per-worker busy/wait time and inserting a preserved sleep window once accumulated tick time reaches one second.
Changes:
- Adds per-worker counters for current-second busy and waited microseconds.
- Adds a worker-set preserve interval defaulting to 8000µs.
- Inserts an extra condition-variable wait after each accumulated second of worker activity.
Comments suppressed due to low confidence (1)
src/atframe/modules/worker_pool_module.cpp:481
- This added line exceeds the repository's
.clang-formatColumnLimit: 120; please wrap it or run clang-format to keep formatting consistent.
auto wait_preserve_us = self->get_owner().configure_tick_preserve_microseconds_in_second.load(std::memory_order_acquire);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| auto wait_preserve_us = self->get_owner().configure_tick_preserve_microseconds_in_second.load(std::memory_order_acquire); | ||
| if (wait_preserve_us <= 0) { | ||
| wait_preserve_us = 8000; | ||
| } | ||
|
|
||
| std::unique_lock<std::mutex> lk_cv(self->waker_lock_); | ||
| self->status_.store(static_cast<uint8_t>(worker_status::kSleeping), std::memory_order_release); | ||
| self->waker_cv_.wait_for(lk_cv, std::chrono::microseconds(wait_preserve_us)); | ||
| self->status_.store(static_cast<uint8_t>(worker_status::kRunning), std::memory_order_release); | ||
|
|
||
| self->cpu_time_sleep_us_.fetch_add(wait_preserve_us, std::memory_order_release); |
owent
left a comment
There was a problem hiding this comment.
AICR problem for src/atframe/modules/worker_pool_module.cpp:491
owent
left a comment
There was a problem hiding this comment.
AICR problem for src/atframe/modules/worker_pool_module.cpp:463
owent
left a comment
There was a problem hiding this comment.
MEDIUM
·
correctness
cpu_time_sleep_us_ 会重复计算睡眠时间。当常规睡眠(line 467)和保护性睡眠(line 493)在同一迭代中执行时,busy_end_time 始终是第一次工作结束的时间点。Line 474 已将第一次睡眠时长加到 cpu_time_sleep_us_,而 line 500 计算的 sleep_rep = sleep_end_time - busy_end_time 包含了第一次睡眠时长和保护性睡眠时长,导致第一次睡眠被重复计算。
触发场景:Worker 在一次迭代中,tick 工作时间短于 tick_interval(触发常规睡眠),且累计的 busy+waited 时间达到 1 秒(触发保护性睡眠)。
建议修复:在保护性睡眠前捕获当前时间(如 preserve_sleep_start = std::chrono::system_clock::now()),在 line 500 使用 sleep_end_time - preserve_sleep_start 计算实际保护性睡眠时长。
Location: src/atframe/modules/worker_pool_module.cpp:500
owent
left a comment
There was a problem hiding this comment.
LOW
·
correctness
保护性睡眠的时间未记录到 current_tick_second_waited_us_。Lines 482-483 将每秒计数器重置为 0 后,保护性睡眠的时长只被添加到 cpu_time_sleep_us_(line 500),但 current_tick_second_waited_us_ 未被更新,导致新的一秒内的等待统计缺失这段睡眠时间。
Location: src/atframe/modules/worker_pool_module.cpp:501
No description provided.