Skip to content

reads: cut statements on narinfo and nar requests - #39

Merged
Uzaaft merged 4 commits into
masterfrom
perf/reads
Nov 18, 2026
Merged

Uzaaft merged 4 commits into
masterfrom
perf/reads

Conversation

@Uzaaft

@Uzaaft Uzaaft commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

No description provided.

A scoped read now admits the cache and reads the requested publication
in a single statement, joining published_paths and blob_objects onto
the cache row by the narinfo hash. A public narinfo hit or miss costs
one database round trip.

Previously every scoped read first looked up the cache, and a narinfo
request then ran a second statement for the publication. Each was its
own pool checkout and round trip, and narinfo requests, most of them
misses, are the hottest route the service has.

The cache row still decides the response on its own. An unknown cache
or one without the Nix protocol is a plain miss, a private cache
authorizes the caller before anything read about the path is used, and
a former organization slug authenticates and then exposes nothing. The
publication columns are optional on the row, so nix-cache-info and
invalid hashes pass no hash and match no path.
The narinfo statement now also reports whether the publication's access
stamp is missing or older than five minutes, and a hit spawns the stamp
update only when it is.

Previously every successful narinfo read spawned the update. Its
predicate skipped the write for a fresh stamp, but the task still took
a pool connection and a database round trip per hit to learn that.

The update keeps its own guard, so readers that race on a due stamp
still write it once, and the bounded semaphore is unchanged. Reads keep
reordering LRU eviction at the same five-minute granularity.
A scoped NAR request now admits the cache and resolves the object key
in one statement, the proxied body is read in 256 KiB frames, and the
bandwidth upsert for a private download runs as tracked background
work instead of ahead of the response headers.

Previously a scoped NAR read looked up the cache and then the key in
two round trips, a private download awaited the bandwidth write before
sending headers, and the body was framed at the 4 KiB reader default,
which costs a wakeup and a frame for every few kilobytes of a large
NAR. The Bazel read path already uses 256 KiB frames.

A private cache still authorizes the caller before the key is used, so
a rejected read answers the same for stored and absent NARs. Metering
keeps its meaning: an admitted GET counts for the full object size at
its start, HEAD does not count, and graceful shutdown drains the task.
The uploads test that reads the meter right after a download now waits
for the row, since the write no longer precedes the response.
The statement that admits a scoped cache and resolves a NAR's key was
the one read-path query still bound at runtime and decoded into a
positional tuple. It now uses the query macro like the narinfo lookup
beside it, so the build verifies it against the schema.
@Uzaaft
Uzaaft merged commit f654ab3 into master Nov 18, 2026
1 check passed
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