Skip to content

Only persist the state when a last-used timestamp changes meaningfully - #428

Merged
stepchowfun merged 2 commits into
mainfrom
coarse-timestamps
Oct 25, 2026
Merged

stepchowfun merged 2 commits into
mainfrom
coarse-timestamps

Conversation

@stepchowfun

Copy link
Copy Markdown
Owner

Following #427, Docuum still rewrote its state file for every event. Under healthcheck load, that save accounted for about 87% of Docuum's remaining CPU usage.

This PR leaves an image's last-used timestamp alone until it's at least a minute old (LAST_USED_GRANULARITY), and only persists the state when something actually changed. touch_image now returns a Touch (New, Updated, or Unchanged) instead of a boolean: new images still trigger a vacuum, and unchanged ones skip the save. This bounds writes to roughly one per image per minute. Timestamps can be up to a minute stale, which doesn't matter in practice for LRU eviction, and images in use by containers (which is all that healthchecks touch) can't be deleted anyway. A timestamp in the future (e.g., due to the clock moving backward) is always replaced so it can't get stuck.

It also bumps the version to 0.27.3.

Benchmark: 10 containers with a 1s healthcheck (~29 container events/s) and 223 images in the state, measuring Docuum's CPU time (including child processes) over 60 seconds minus startup:

Build Cores Timestamp updates
v0.27.1 0.47 1735
#427 (image ID cache) 0.049 1680
This PR 0.006 1

That's about the same as a build of #427 with the per-event save removed entirely (0.006 cores).

Status: Ready

Fixes: #426

Docuum rewrote its state file for every event, which accounted for most of
its remaining CPU usage under healthcheck load once image IDs were cached
(#426). Last-used timestamps are now left alone until they're at least a
minute old, and the state is only persisted when something changed. This
bounds writes to roughly one per image per minute, at the cost of
timestamps being up to a minute stale, which doesn't matter for LRU
eviction in practice. A timestamp in the future (e.g., due to the clock
moving backward) is always replaced so it can't get stuck.
@stepchowfun
stepchowfun merged commit 8e5bb5f into main Oct 25, 2026
6 checks passed
@stepchowfun
stepchowfun deleted the coarse-timestamps branch October 25, 2026 03:56
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