]> git.hungrycats.org Git - bees/commitdiff
bees: consume a token in RateLimiter is_ready log guards
authorZygo Blaxell <bees@furryterror.org>
Thu, 3 Sep 2026 02:22:54 +0000 (22:22 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 5 Sep 2026 04:04:15 +0000 (00:04 -0400)
RateLimiter::is_ready() reports token availability without consuming
anything, so a bare `if (limiter.is_ready()) log` never throttles:
the balance never goes negative and the guard is always true.  The
borrower contention lines and the crawl temp-transid hold report all
used the bare form; a full-corpus run logged 2.87M "memo reacquire
contention" lines through a 10/s limiter that was doing nothing.

Follow is_ready() with borrow() so each emitted line spends a token
and the limiter engages.

Assisted-by: Claude-Code:claude-fable-5
src/bees-borrower.cc
src/bees-roots.cc

index cce3924a4e8e502c02c18b278549e68de12b2c36..027444aed4886869c794f12c8e375bf927564a62 100644 (file)
@@ -90,6 +90,7 @@ Borrower::Borrower(shared_ptr<PlannerState> ps) :
                        BEESCOUNT(borrower_dead_reacquire);
                        static RateLimiter s_reacquire_log_limit(10);
                        if (s_reacquire_log_limit.is_ready()) {
+                               s_reacquire_log_limit.borrow();
                                BEESLOGDEBUG("memo reacquire contention ("
                                        << memo.size() << " locks)");
                        }
@@ -106,6 +107,7 @@ Borrower::Borrower(shared_ptr<PlannerState> ps) :
                                BEESCOUNT(borrower_dead_reacquire);
                                static RateLimiter s_race_log_limit(10);
                                if (s_race_log_limit.is_ready()) {
+                                       s_race_log_limit.borrow();
                                        BEESLOGDEBUG("memo reacquire race ("
                                                << memo.size() << " locks)");
                                }
index 182ab81b1d7ffcdc71c96e1fd72c657771968ff4..1b3cd26f5fdaae3cd930578541033226356ccdb5 100644 (file)
@@ -1944,6 +1944,7 @@ BeesRoots::effective_transid_max()
                        // operators do not need to act on it.
                        static RateLimiter s_hold_report_limit(1.0 / 60);
                        if (s_hold_report_limit.is_ready()) {
+                               s_hold_report_limit.borrow();
                                BEESLOGDEBUG("crawl held below transid "
                                        << temp_floor << " by temp file(s):"
                                        << m_ctx->temp_transid_report());