Skip to content

perf(admin): consider double-checked locking for metrics cache #486

@ehotting

Description

@ehotting

From the code review on #484:

The metrics cache was changed from RwLock to Mutex to fix a TOCTOU race where concurrent Prometheus scrapes could redundantly hit the database. However, this serialises cache-hit reads too — each scrape waits for the previous one to release the lock, even when the cache is fresh.

For a Prometheus endpoint scraped at low frequency (default 15-60s) this is harmless. If scrape intervals are ever tightened, a double-checked pattern (try read first, acquire write only on miss) could recover concurrent reads while keeping single-flight on miss.

Low priority — the current trade-off is reasonable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions