Skip to content

Make queue claimer cap configurable#214

Merged
hardbyte merged 1 commit into
mainfrom
brian/dispatcher-claimer-cap-env
May 3, 2026
Merged

Make queue claimer cap configurable#214
hardbyte merged 1 commit into
mainfrom
brian/dispatcher-claimer-cap-env

Conversation

@hardbyte
Copy link
Copy Markdown
Owner

@hardbyte hardbyte commented May 3, 2026

Summary

  • add AWA_MAX_CLAIMERS_PER_QUEUE to override the queue-storage dispatcher claimer cap
  • preserve the existing default of 4 claimers per queue
  • keep the tuning knob runtime-only so benchmark sweeps do not need source edits

Validation

  • cargo check -p awa-worker

Summary by CodeRabbit

  • New Features
    • Added support for configuring the maximum number of claimers per queue via the AWA_MAX_CLAIMERS_PER_QUEUE environment variable. The value must be a positive integer; if unset or invalid, the system falls back to the built-in default. The setting is validated and cached for consistent runtime behavior.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 3, 2026

Warning

Rate limit exceeded

@hardbyte has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 56 minutes and 52 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2516b0f0-89c7-401f-bc62-3a2fb2ee3b5a

📥 Commits

Reviewing files that changed from the base of the PR and between 442bc60 and 91b144b.

📒 Files selected for processing (1)
  • awa-worker/src/dispatcher.rs
📝 Walkthrough

Walkthrough

Added a cached max_claimers_per_queue() helper that reads AWA_MAX_CLAIMERS_PER_QUEUE (parsed as i16, must be > 0) with fallback to MAX_CLAIMERS_PER_QUEUE. Updated the runtime storage job claiming call to use this helper instead of the constant.

Changes

Configurable Max Claimers Per Queue

Layer / File(s) Summary
Data Shape / Cache
awa-worker/src/dispatcher.rs
Added max_claimers_per_queue() which lazily caches an env var AWA_MAX_CLAIMERS_PER_QUEUE, parses to i16, validates > 0, falls back to MAX_CLAIMERS_PER_QUEUE.
Core Integration
awa-worker/src/dispatcher.rs
Replaced use of MAX_CLAIMERS_PER_QUEUE with max_claimers_per_queue() when calling claim_runtime_batch_with_aging_for_instance in the RuntimeStorage::QueueStorage claim path.
Imports
awa-worker/src/dispatcher.rs
Added OnceLock to std::sync imports to support cached value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 I peeked at the code with whiskers bright,
A cached env tweak to make claimers light,
From constant to flex, the dispatcher hops,
Quick change, gentle thump—no more hard stops! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Make queue claimer cap configurable' directly and accurately summarizes the main change: introducing configurability for the queue claimer limit via environment variable.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch brian/dispatcher-claimer-cap-env

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get your free trial and get 200 agent minutes per Slack user (a $50 value).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 56 minutes and 52 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
awa-worker/src/dispatcher.rs (1)

588-588: ⚡ Quick win

Cache the result of max_claimers_per_queue() — avoid a global env-lock on every poll.

max_claimers_per_queue() calls std::env::var, which acquires the process-wide environment mutex on every invocation. Under load, drain_ready loops calling poll_once continuously (once per claimed batch), so this mutex acquisition + string parse fires on every DB round-trip. The value is logically static for the process lifetime; there is no benefit to re-reading it each time.

The cleanest fix is a std::sync::OnceLock:

♻️ Proposed refactor using `OnceLock`
+use std::sync::OnceLock;
+
+static MAX_CLAIMERS: OnceLock<i16> = OnceLock::new();
+
 fn max_claimers_per_queue() -> i16 {
-    std::env::var("AWA_MAX_CLAIMERS_PER_QUEUE")
-        .ok()
-        .and_then(|value| value.parse::<i16>().ok())
-        .filter(|value| *value > 0)
-        .unwrap_or(MAX_CLAIMERS_PER_QUEUE)
+    *MAX_CLAIMERS.get_or_init(|| {
+        // ... same parsing + warn! logic as above ...
+        std::env::var("AWA_MAX_CLAIMERS_PER_QUEUE")
+            .ok()
+            .and_then(|v| v.parse::<i16>().ok())
+            .filter(|&v| v > 0)
+            .unwrap_or(MAX_CLAIMERS_PER_QUEUE)
+    })
 }

Alternatively, read and store the value in Dispatcher::new / Dispatcher::with_concurrency and add it as a field — which also makes it straightforward to test with different values.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@awa-worker/src/dispatcher.rs` at line 588, The call to
max_claimers_per_queue() is performed inside the hot loop (e.g., drain_ready ->
poll_once) and repeatedly invokes std::env::var, causing a global env mutex
contention; cache this value instead by initializing it once and reusing it:
either add a field to Dispatcher (set in Dispatcher::new or
Dispatcher::with_concurrency) to store the parsed max_claimers_per_queue value,
or use a process-wide std::sync::OnceLock to compute and store the value on
first access, then replace direct calls to max_claimers_per_queue() in the
polling path with the cached value; ensure the cached type matches the current
return type and adjust tests to set the value via the chosen initialization path
if needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@awa-worker/src/dispatcher.rs`:
- Around line 21-27: The function max_claimers_per_queue currently silently
falls back to MAX_CLAIMERS_PER_QUEUE on parse errors or non-positive values;
update it to detect when AWA_MAX_CLAIMERS_PER_QUEUE is set but invalid or <= 0
and emit a warning (e.g., using log::warn!) that includes the raw env value and
parse error or the fact it was non-positive, then return the existing fallback;
modify the code in max_claimers_per_queue to inspect
std::env::var("AWA_MAX_CLAIMERS_PER_QUEUE") result, attempt parse with map_err
to capture parse errors, log appropriately when Err or when parsed_value <= 0,
and only use unwrap_or(MAX_CLAIMERS_PER_QUEUE) after logging.

---

Nitpick comments:
In `@awa-worker/src/dispatcher.rs`:
- Line 588: The call to max_claimers_per_queue() is performed inside the hot
loop (e.g., drain_ready -> poll_once) and repeatedly invokes std::env::var,
causing a global env mutex contention; cache this value instead by initializing
it once and reusing it: either add a field to Dispatcher (set in Dispatcher::new
or Dispatcher::with_concurrency) to store the parsed max_claimers_per_queue
value, or use a process-wide std::sync::OnceLock to compute and store the value
on first access, then replace direct calls to max_claimers_per_queue() in the
polling path with the cached value; ensure the cached type matches the current
return type and adjust tests to set the value via the chosen initialization path
if needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3f38fd39-a4f3-46d6-bf7d-82c6ffc9c24b

📥 Commits

Reviewing files that changed from the base of the PR and between 7eb4cd8 and 312d217.

📒 Files selected for processing (1)
  • awa-worker/src/dispatcher.rs

Comment thread awa-worker/src/dispatcher.rs
@hardbyte hardbyte force-pushed the brian/dispatcher-claimer-cap-env branch from 312d217 to 442bc60 Compare May 3, 2026 01:53
@hardbyte hardbyte force-pushed the brian/dispatcher-claimer-cap-env branch from 442bc60 to 91b144b Compare May 3, 2026 01:56
@hardbyte hardbyte merged commit 8ebcbc5 into main May 3, 2026
13 checks passed
@hardbyte hardbyte deleted the brian/dispatcher-claimer-cap-env branch May 3, 2026 02:04
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.

1 participant