Positioning and architecture · Engineering
Inside the ~5 MB idle daemon
Where NonoDB’s idle memory goes, why RSS can jump during scans, and why the LMDB map size is not a RAM allocation.
A database that idles at about 5 MB sounds suspicious. Most databases reserve memory for a buffer pool, a JVM heap, or a query cache, and those reservations are usually much larger. NonoDB is different because the daemon does not try to own the data set in its heap. It maps LMDB files and lets the operating system decide which pages are worth keeping.
That design makes the idle number small, and it also makes the number easy to misread.
What “5 MB” measures
The published measurements are process RSS and PSS on a benchmark host:
| State | RSS | PSS |
|---|---|---|
| 1,000 documents, 3 indexes, idle | ~5.1–5.4 MB | ~2.6–3.0 MB |
| 1M documents, 3 indexes, idle after restart | ~5.1 MB | ~2.9 MB |
| 1M documents, after a few reads | ~6.4 MB | ~4.0 MB |
| 1M documents, after a full scan and sort | ~278 MB | ~276 MB |
| 1M documents, peak during parallel index backfill | ~552 MB | — |
| 100k text/fuzzy documents | up to ~788 MB peak | — |
RSS is the resident set size: pages currently mapped into the process. PSS splits shared pages across processes, so it is often lower. Neither number is the Rust heap.
The large numbers are mostly mapped LMDB pages touched by scans. A restart drops RSS back to a few megabytes; the operating system may keep the same pages in page cache and serve them to the next process. That is not a leak, and it is not a promise that the database can run a full scan in 5 MB.
The file is mapped, not loaded
LMDB is a memory-mapped B+ tree. When NonoDB opens a database, it maps the file into the process address space. Reading a document touches the pages that contain the B+ tree path and the value. The operating system brings those pages in on demand and can evict them under memory pressure.
The daemon’s heap holds request buffers, parsed documents, index metadata, and configuration. It does not hold the whole collection. This is why a 1 GB data file can be served by a process with a much smaller RSS. It is also why the first read after a restart is slower: the pages have to come from disk.
map_size is the maximum address space LMDB may use, not an allocation of RAM or disk. The default is 1 GiB. A larger map does not increase RSS by itself; it only raises the ceiling for the file. The operations guide explains how to resize it.
Where memory actually grows
A few operations deliberately use more memory:
- Full scans and sorts parse documents and may hold a bounded top-K result. The more pages touched, the higher RSS climbs.
- Parallel index backfill uses up to 16 worker threads with a bounded queue. Peak memory depends on the queue and document sizes, not collection size, but it is still a real spike.
- Text and fuzzy indexes can use substantially more memory during a large build. The 100k-document benchmark reached roughly 788 MB at peak.
- Aggregation groups are held in memory. A high-cardinality
$groupcan be the largest allocation in the process.
If you run on a 512 MB VM, those are the operations to watch. Use bounded queries, build indexes before the workload arrives, and avoid unbounded aggregation over a large collection.
Why not a JVM or a buffer pool?
A separate cache would duplicate what the OS page cache already does. LMDB’s copy-on-write pages are stable snapshots; the kernel can evict clean pages without asking the database. The daemon does not need to guess a working set, tune a buffer pool, or reserve a JVM heap.
The trade-off is that memory behaviour is less explicit. You cannot set “database memory = 256 MB” and expect every operation to stay under it. You can set map_size, limit aggregation size, and choose queries that do not scan the world. The small deployment profiles exist for constrained hosts, but they change limits rather than hiding the page cache.
The useful mental model
Think of RSS as “pages this process has touched recently”, not “memory this database requires”. The idle daemon is small because it has touched little. A scan is large because it touched a lot. The data itself may still be in page cache after the process exits.
That model is why NonoDB can run next to an application on a cheap VM, and why the same process can spike during an index build. Measure the operation you plan to run, not only the idle state.