Skip to content

Stop refetching Go, RPM and PyPI metadata that can't change - #598

Merged
andrew merged 2 commits into
git-pkgs:mainfrom
simonchrz:perf/immutable-metadata
Oct 25, 2026
Merged

andrew merged 2 commits into
git-pkgs:mainfrom
simonchrz:perf/immutable-metadata

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

Some upstream requests the proxy makes are for data that never changes once published.

Go .mod and .info. For a canonical version they are fixed by the module proxy protocol and the checksum database, but they went through metadata_ttl. go mod download for a mid-sized service asks for 200-400 .mod files (every module version in the graph, including pruned ones) plus their .info. With cache_metadata off that was 200-400 full GETs to proxy.golang.org on every build; with it on, the same number of conditional requests whenever a build ran more than 5 minutes after the last.

They are now kept in the metadata cache with or without cache_metadata, as .zip files are kept in the artifact cache, and served whatever their age. That covers releases, pre-releases, pseudo-versions and +incompatible versions (module.CanonicalVersion(v) == v). Pseudo-versions are included: they name a commit by its hash, and the checksum database pins their content like any other version. A query (@v/main.info, @v/v1.2.info), @v/list and @latest stay on the TTL. The cooldown path reads .info through the same cache, so a version's time still comes from the versions row first and its .info second; nothing about which versions are withheld changes.

RPM repodata. createrepo names primary, filelists, other, comps, updateinfo and so on after their own checksum (repodata/<sha256>-primary.xml.zst), so a name always has the same content. A fresh CI container running dnf against Fedora fetches 5-10 of these per repository, tens of MB, and each did so from upstream with cache_metadata off. They now get the same treatment as Go's files. repomd.xml and repositories built with --simple-md-filenames stay on the TTL. A file over metadata_max_size is streamed from upstream uncached instead of failing with 502.

A stored immutable document is never revalidated, so it is checked against the digest recorded for it, as streamed cache hits already are, and fetched again if it doesn't match.

PyPI download cooldown. Every download with cooldown on read the JSON API before looking at the cache, cached files included. Installing 150 cached wheels with cache_metadata off made 150 requests for /pypi/<name>/json, which is several MB for packages like boto3. The download path now stores the release's upload time on its versions row, as npm, Go, Maven and Composer do, and checks a cached file against it without asking upstream. The same 150 cached wheels now cost no upstream request.

A PyPI release's time is its newest file's upload time, and a file can be added to an old release later. So the stored time only answers for files that are already cached. A file that isn't cached is still looked up, which stores the newer time; from then on the whole release is withheld until it leaves cooldown, as before. A stored time inside the window withholds the release without a lookup. The one difference from before: a file cached before a new file was added to its release keeps being served, since it is the same bytes that already passed. The simple-page filtering is unchanged.

Tested with counting httptest upstreams, each test failing without the change:

  • TestGoVersionFilesAreNotRevalidated: .mod/.info for a release and a pseudo-version fetched once over three rounds, with and without cache_metadata and cooldown and with an expired TTL; @v/main.info, @v/list and @latest fetched each time.
  • TestRPMContentAddressedRepodataIsNotRevalidated: a checksum-named file fetched once, repomd.xml and primary.xml.gz each time.
  • TestPyPICachedDownloadUsesStoredUploadTime: three downloads of a cached file, one JSON API request.
  • TestPyPIFileAddedToReleaseIsChecked: a wheel added to an old release is looked up and withheld, and the cached sdist of that release is withheld after it without another lookup.

Also TestImmutableMetadataRefetchedWhenCorrupt, TestImmutableMetadataOverSizeLimitIsStreamed, and table tests for which Go versions and repodata names count as immutable. docs/configuration.md describes both changes.

A Go module's .mod and .info for a canonical version, and RPM repodata
files named after their checksum, never change once published. They
went through the metadata TTL, so each cost a revalidation every TTL with
cache_metadata on and a full fetch on every request with it off.

They are now kept in the metadata cache with or without cache_metadata
and served whatever their age. A stored copy is checked against its
digest and fetched again if it doesn't match. Go queries, @v/list,
@latest and repomd.xml stay on the TTL.
Every PyPI download with cooldown on read the JSON API first, cached
files included. Without cache_metadata that was a full /pypi/<name>/json
per file.

A download that looks up the JSON API now stores the release's newest
upload time on its versions row. A cached file is then checked against
the stored time without asking upstream. A file that isn't cached is
still looked up, since files can be added to a release later, and the
stored time is refreshed. A stored time inside the window withholds the
release without a lookup.
@andrew
andrew merged commit c5b8088 into git-pkgs:main Oct 25, 2026
7 checks 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.

2 participants