⚡ Bolt: Optimize circuit breaker fast path to prevent DashMap write lock contention - #80
Conversation
…ock contention Co-authored-by: ovasylenko <3797513+ovasylenko@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
PR #80 predates the edition-2024 if-let-chain style used elsewhere in this file; clippy now flags the nested if as collapsible.
💡 What: Introduced a fast-path read lock using
self.breakers.get(q)at the beginning ofrecord_failurein the circuit breaker registry. If the breaker is already fullyOpen, it returns early instead of acquiring a write lock to increment thefailure_count.🎯 Why: During a failure storm, many in-flight requests may fail sequentially or concurrently. The previous implementation acquired a
get_mut()write lock on theDashMapshard for every failure to increment thefailure_count. However, once a circuit isOpen, thefailure_counthas no behavioral impact on cooldown timers or recovery. Avoiding the write lock entirely removes severe contention on the specificDashMapshard.📊 Impact: Completely eliminates write-lock contention on the hot path for failing services once their circuit is open, dramatically reducing CPU overhead during cascading failures.
🔬 Measurement: Verify via
cargo check,cargo fmt,cargo clippy, andcargo test -p orch8-engine --lib circuit_breaker.PR created automatically by Jules for task 12300898650048027779 started by @ovasylenko