Skip to content

perf: cache moq-api namespace lookups for a few seconds - #206

Open
thexeos wants to merge 1 commit into
cloudflare:draft-ietf-moq-transport-14from
thexeos:perf/coordinator-lookup-cache-draft-14
Open

perf: cache moq-api namespace lookups for a few seconds#206
thexeos wants to merge 1 commit into
cloudflare:draft-ietf-moq-transport-14from
thexeos:perf/coordinator-lookup-cache-draft-14

Conversation

@thexeos

@thexeos thexeos commented Aug 13, 2026

Copy link
Copy Markdown

Backport of #201 to draft-14

ApiCoordinator::lookup() issued a fresh HTTP request to moq-api on every call, and the relay looks a namespace up once per track it cannot serve locally — so a subscriber asking for several tracks of one namespace produced that many identical requests, each on the critical path of a cold subscribe. This adds a small TTL cache in front of the lookup, defaulting to 2s and configurable via ApiCoordinatorConfig::with_lookup_cache_ttl() / --api-lookup-cache-ttl (0 disables it); the TTL sits far below the registration TTL so a cached origin cannot outlive the registration it came from. Misses are cached for a tenth of that, long enough to collapse a burst but short enough that a namespace registered moments ago is not hidden, and failed requests are not cached at all. The cache uses only the standard library plus existing dependencies, and is covered by unit tests for hits, expiry, the shorter negative TTL, the disable switch, bounded growth, and concurrent use.

`ApiCoordinator::lookup()` issued a fresh HTTP request to moq-api on every
call. The relay looks a namespace up once per track it cannot serve locally,
so a subscriber asking for several tracks of the same namespace produced that
many identical requests, each one on the critical path of a cold subscribe.

Put a small TTL cache in front of the lookup. It defaults to 2s and is
configurable through `ApiCoordinatorConfig::with_lookup_cache_ttl()` and
`--api-lookup-cache-ttl`, where 0 disables it. The TTL is deliberately far
below the registration TTL, so a cached origin cannot outlive the registration
it came from; it is also the only invalidation, since a stale origin is
discovered by connecting, which the coordinator does not observe. Misses are
cached for a tenth of that, long enough to collapse a burst but short enough
that a namespace registered moments ago is not hidden. Failed requests are not
cached, so a transient API error is retried by the next subscriber.
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