12 Commits

Author SHA1 Message Date
Bright Chen c9778ca1a3 Refactor NULL with nullptr in test (#3464) 2026-08-19 13:26:18 +08:00
stdpain 868f381c52 Reclaim unscheduled timer tasks instead of holding slots until run_time (#3384)
TimerThread only reclaims a Task's pooled slot when the task is popped at
its run_time. A task unscheduled after being pulled into the internal heap
therefore keeps its slot until run_time, and tasks that pile up in the
buckets while the thread sleeps on a far-future deadline are not consumed
(and thus not reclaimed) until that deadline. With large timeouts the live
Task count grows to ~ qps * timeout even though almost all of those tasks
were unscheduled long ago.

Add two independent, bounded reclamation paths:

- Heap sweep: when the internal heap grows past
  brpc_timer_heap_sweep_min_size (default 4096) and has roughly doubled
  since the last sweep, drop unscheduled tasks from it. The trigger is a
  timer-thread-local heuristic, so the unschedule() hot path is unchanged
  (no new shared atomics/contention). Amortized O(1) per task.

- Periodic wakeup: cap the sleep at brpc_timer_max_wakeup_interval_ms
  (default 0 = disabled, legacy behavior) so the thread wakes up to drain
  the buckets and sweep the heap even when every pending task is far in
  the future. An empty heap still sleeps until woken by schedule().

Expose pending_task_count() and allocated_task_count() for observability,
and add unit tests covering both the heap-retention and bucket-accumulation
cases (each verified to fail with the corresponding fix disabled).
2026-07-17 15:49:41 +08:00
Weibing Wang 078051f9bf Update license header to Apache 2019-06-20 14:22:57 +08:00
gejun cde9a4a04a Make some timeout in UT larger 2019-04-18 18:32:19 +08:00
zhujiashun 7c3f109e59 Add LOG_AT macro when linking with glog 2018-03-05 07:34:29 +08:00
gejun 7f9d0e898a loose assertions on running time in test/bthread_timer_thread_unittest.cpp 2017-10-31 18:52:50 +08:00
chenzhangyi01 6fdeeac28e butil/logging could be overwritten by glog
Change-Id: I14cf8724175d1fb5237fe20228f822afdd8521cc
2017-09-12 11:55:30 +08:00
gejun 80f9f2f160 Rename base to butil to avoid potential naming conflicts 2017-09-08 17:17:35 +08:00
gejun 023371e643 Change copyright to Baidu, Inc 2017-09-05 19:44:12 +08:00
gejun 24c64eaa2b Patch svn r35218 2017-09-04 17:12:59 +08:00
gejun d5b908014b Patch svn r35208 2017-09-03 14:37:17 +08:00
gejun 7998155962 first working CI
Change-Id: I68c0cafba040debefd660c5213f21e6fc702a4a6
2017-07-25 23:02:28 +08:00