Skip to content

Cache image IDs to avoid querying Docker for every event - #427

Merged
stepchowfun merged 2 commits into
mainfrom
image-id-cache
Oct 25, 2026
Merged

stepchowfun merged 2 commits into
mainfrom
image-id-cache

Conversation

@stepchowfun

Copy link
Copy Markdown
Owner

Docuum spawned docker image inspect for every container event to resolve the image reference to an ID. Each healthcheck emits several container events (exec_create, exec_start, exec_die), so Docuum's CPU usage scaled with healthcheck activity even when no images were added or removed.

This PR resolves image references for container events through an in-memory cache:

  • Image events (pull, tag, untag, delete, etc.), which can change what a reference points to, bypass the cache and clear it.
  • Entries also expire after five minutes (IMAGE_ID_CACHE_TTL) in case a change goes unreported. The TTL exceeds common healthcheck intervals so that healthchecks actually hit the cache.
  • The cache starts empty on each run, since events may have been missed while Docuum wasn't listening (e.g., after docker system events terminates).

It also bumps the version to 0.27.2.

Testing: in addition to the new unit tests, I ran Docuum (with deletion effectively disabled) against a local Docker daemon with a container that has a 1s healthcheck. 44 of 45 container events were served from the cache, and after retagging the container's image reference to a different image, the tag event cleared the cache and subsequent events resolved to the new image ID.

Status: Ready

Fixes: #426

Each container event (including the several emitted by every healthcheck)
spawned `docker image inspect` to resolve the image reference to an ID,
which made Docuum's CPU usage scale with healthcheck activity even when no
images were added or removed (#426).

Container events now resolve image references through an in-memory cache.
Image events, which can change what a reference points to, bypass and clear
the cache, and entries also expire after five minutes in case a change goes
unreported. The cache starts empty on each run, since events may have been
missed while not listening.
@stepchowfun
stepchowfun merged commit 6375757 into main Oct 25, 2026
6 checks passed
@stepchowfun
stepchowfun deleted the image-id-cache branch October 25, 2026 03:45
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