Skip to content

ASA Go: API Locks for stats cache access - #5803

Open
conbrad wants to merge 4 commits into
mainfrom
fix/asa-go-cache-stampede
Open

ASA Go: API Locks for stats cache access#5803
conbrad wants to merge 4 commits into
mainfrom
fix/asa-go-cache-stampede

Conversation

@conbrad

@conbrad conbrad commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Create a lock for each cache key so that only one writer sets the cached result to prevent a thundering heard from all attempting at once.

Updates:

  • Replaced process-only coordination with a Redis distributed lock, ensuring Gunicorn workers and pods don’t simultaneously compute the same cold cache key.
  • Retained a per-process asyncio.Lock to reduce Redis contention and provide fallback when Redis is unavailable.
  • Centralized cache lookup, locking, computation, writing, and release in ASARedisCache.get_or_compute()
  • Ensured Redis locks are explicitly released in finally
  • Reduced the maximum lock wait from 30 to 5 seconds to keep mobile requests responsive (unsure on what this value should be, load tests may help determine)

Test Links:

Landing Page
MoreCast
Percentile Calculator
FireCalc
FireCalc bookmark
Auto Spatial Advisory (ASA)
HFI Calculator
SFMS Insights
Fire Watch
Weather Toolkit

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.80519% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.92%. Comparing base (cadf2bd) to head (1cbdfd7).

Files with missing lines Patch % Lines
.../auto_spatial_advisory/advisory_run_stats/cache.py 90.47% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5803      +/-   ##
==========================================
+ Coverage   68.90%   68.92%   +0.01%     
==========================================
  Files         388      388              
  Lines       21669    21695      +26     
  Branches     2937     2937              
==========================================
+ Hits        14932    14954      +22     
- Misses       5831     5834       +3     
- Partials      906      907       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants