Skip to content

Sample the engine's memory where the engine is - #120

Merged
tamnd merged 1 commit into
mainfrom
mem-sample
Aug 24, 2026
Merged

Sample the engine's memory where the engine is#120
tamnd merged 1 commit into
mainfrom
mem-sample

Conversation

@tamnd

@tamnd tamnd commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Part of #56, the memory half of the resource measurement section.

A served engine reported its driver's memory and called that the engine. getrusage has no field for a server this process never forked, so the memory rows of the resource table described the Bolt driver for neo4j and memgraph, which is the one part of that run nobody wants sized. That is what the issue means by RUSAGE_SELF reading about zero for bolt engines.

Memory is now read once a second where the engine actually is:

  • a served engine: the container's own cgroup, memory.current with the v1 file as fallback. It includes the page cache the container caused, which is the fair comparison against an embedded engine, since a resident set counts the file pages that engine mapped the same way.
  • an embedded or subprocess engine: the resident set of this process and every descendant alive at the moment of the reading, out of /proc. Descendants count because on a subprocess plane the engine is one.

The sampler keeps the largest reading and the last one. An engine that reaches a gigabyte to answer one query and an engine that holds a gigabyte all day are a different problem with the same peak, and a table that carries only one of the two numbers cannot tell them apart. Two rows are added, memory peak (sampled) and memory steady (sampled), and a row that is unknown everywhere is dropped as before.

Sampling starts before the engine is up, so the peak covers the load as well as the measured run. The load is often where an engine reaches highest.

Off Linux the local probe answers -1 rather than forking ps once a second. Every fork lands in RUSAGE_CHILDREN, which is the accounting a subprocess engine's own cost is read out of, so a sampler built that way would pay for itself out of the figures it sits beside. There is a clean reading on darwin through proc_pidinfo, but only by linking libproc through cgo, and the default build here is cgo-free. The peak rss rows still answer there, from getrusage; what is missing off Linux is the steady state, which no rusage field holds.

A document written before this carries no sampled fields, and a missing number decodes as zero, which in this table would read as an engine that used no memory. Read normalizes those to unknown, told apart by the sample count.

Verified: the sampler and the /proc probe pass in a Linux container (the measure tests cross compiled and run under alpine), and cgroup memory.current answers through docker exec on this box. go test ./... green on darwin, GOOS=linux go build green.

A served engine reported its driver's memory and called that the engine.
getrusage has no field for a server this process never forked, so the
resource table's memory rows described the Bolt driver for neo4j and
memgraph, which is the one part of that run nobody wants sized.

Memory is now read once a second where the engine actually is: out of the
container's own cgroup for a served engine, off the process tree for an
embedded or subprocess one. The sampler keeps the largest reading and the
last, because an engine that reaches a gigabyte to answer one query and an
engine that holds a gigabyte all day are a different problem with the same
peak.

Off Linux the local probe answers -1 rather than forking ps once a second:
every fork lands in RUSAGE_CHILDREN, which is where a subprocess engine's
own cost is read from, so a sampler built that way would pay for itself out
of the figures it sits beside. The peak rss rows still answer there.
@tamnd
tamnd merged commit a5a47ca into main Aug 24, 2026
2 checks passed
@tamnd
tamnd deleted the mem-sample branch August 24, 2026 11:48
@tamnd tamnd mentioned this pull request Aug 24, 2026
12 tasks
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