Skip to content

perf(channels): coalesce concurrent GetChannels/GetEncryptedChannels cache misses #109

Description

@dborup

Upstream source

Evaluate and port the behaviour from Kpa-clawbot/CoreScope#2059: coalesce concurrent cache misses for GetChannels and GetEncryptedChannels so one cold/expired key causes one SQLite query rather than one query per request.

Why this is still relevant here

Current fork master still has no channel-query singleflight. GetChannels uses a 60-second cache, but concurrent callers can all miss before the first result is stored. GetEncryptedChannels follows a separate query path.

This fork has diverged from upstream:

Do not cherry-pick blindly. Preserve those behaviours and adapt request coalescing to the current cache contract.

Acceptance criteria

  • Concurrent misses for the same normalized region execute at most one real GetChannels query.
  • Concurrent misses for the same normalized region execute at most one real GetEncryptedChannels query.
  • Different region keys are never coalesced together and cannot receive each other's result.
  • Errors are shared only within the in-flight call and are not cached as successful data.
  • A second cache check occurs inside the singleflight winner.
  • Existing index-pinning/fallback behaviour from perf(db): pin GetChannels and CountFloodAdvertsForNode to their indexes (issue #100) #107 remains intact.
  • Existing cache-slice protection from fix(server): avoid mutating the cached channels slice on includeEncrypted #98 remains intact.
  • Deterministic tests count actual query executions; timing alone is not sufficient.
  • Run the relevant Go tests with -race and measure cold concurrent behaviour before and after.

No deploy is part of this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions