Skip to content

Resolve packages in a child process, so the runtime doesn't keep the parsed indexes - #14

Open
sipsma wants to merge 1 commit into
mainfrom
sipsma/alpine-resolve-in-child
Open

sipsma wants to merge 1 commit into
mainfrom
sipsma/alpine-resolve-in-child

Conversation

@sipsma

@sipsma sipsma commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Resolving packages reads the repositories' indexes and builds a resolver, and apko keeps both in process-wide caches it never clears. For Wolfi's two indexes that leaves 150 MB live after a resolve of about a second; for Alpine's, about 40 MB. The module's runtime then waits on the engine for the rest of the call, holding all of it. In a cold run of dagger/dagger's checks, several Wolfi calls wait at once for a minute or more each, at 230 to 375 MB per runtime.

This PR resolves in a short child process instead: the runtime's own binary, started with an argument that an init checks, reads the request on stdin and answers with each package's name, version and URL, which is all the rest of the call uses. What apko parsed goes when the child exits.

  • The request goes in on stdin, not in the arguments, because extra repositories can carry credentials.
  • The child sets up telemetry from the call's environment, as the call itself does. Whether apko's spans reach the trace is not confirmed: a raw OTLP capture showed no apko spans either before or after this change.
  • Errors come back with the messages they had, and the package conflicts note is printed by the call as before.
  • The API is unchanged.

Measured, one call at a time in an engine, peak memory of the module's runtime:

Call Before After
Wolfi, the dagger engine image's packages 204–230 MB 25–27 MB
Wolfi, a Go build image 195–217 MB 17 MB
Alpine about 75 MB 20–23 MB

The child peaks at about the old figure for 1 to 2 s. Wall time is unchanged at 1.3 to 1.9 s per resolve. Package lists, directory and image digests, and errors are identical before and after.

Tests: the new tests serve a signed index over HTTP and check that the child resolves the same packages and fails with the same errors as resolving in the test process, and that the test process keeps none of a 20,000-package index afterwards (15 KiB against 27.8 MiB in-process). This repository has no CI; the module's Go tests were run in Dagger.

Resolving reads the repositories' indexes and builds a resolver, and apko
keeps both in process-wide caches it never clears. For Wolfi's two
indexes that is 150 MB live (218 MB of heap) after a resolve of about a
second; for Alpine's, about 40 MB. The module's runtime then waits on the
engine for the rest of the call, which in a plan of many checks lasts a
minute or more, holding all of it.

Resolve in a child process instead: the runtime's own binary, started
with an argument that an init checks, reads the request on stdin and
answers with each package's name, version and URL, which is all the rest
of the call uses. What apko parsed goes when the child exits. The
request goes in on stdin rather than in the arguments because extra
repositories can carry credentials. The child sets up telemetry from the
same environment as the call, as the call itself does, and errors come
back with the messages they had. The conflicts note is printed by the
call as before.

Container, Directory and Resolve give the same results. The tests run
the child against a signed index served over HTTP and compare it with
resolving in the test process, and check that the test process keeps
none of a 20,000-package index afterwards.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
sipsma added a commit to dagger/wolfi that referenced this pull request Dec 1, 2026
alpine's dependency moves from e746b97 to 923d2f0, the head of
dagger/alpine#14. alpine now resolves packages in a short child process,
so its runtime no longer keeps the parsed Wolfi indexes, about 150 MB
live, for the whole of a call. Between the two commits alpine also
gained Resolve and Directory and moved to go-sdk v1.8.0 and otel-go
v1.47.0. Container, the only function wolfi calls, builds the same
images: for dagger's engine image packages and for go-1.27 with
build-base on amd64, the rootfs digests and environment are identical
before and after.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
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