Skip to content

fix(map): keep the facet indexes within a quarter of maxMemory or --memory-limit - #819

Open
MathiasVDA wants to merge 4 commits into
mainfrom
claude/project-thread-4qfh9q
Open

MathiasVDA wants to merge 4 commits into
mainfrom
claude/project-thread-4qfh9q

Conversation

@MathiasVDA

Copy link
Copy Markdown
Contributor

Requested by Mathias · project thread

What and why

Closes #809
Closes #796

The 1B slowdown between bb4b496 and 648ec84 comes from memory, not from slower queries. The map's facet indexes (added between the two commits) keep every feature's IRI, values and parsed geometry, and neither --memory-limit nor maxMemory bounded them. In the 1B runs, the heap after start was 48.9 GB on 648ec84 against 14.1 GB on bb4b496, with only 6.8 GB of it counted. That left the 66 GB store 11 GB of page cache instead of 41 GB, and the warm-up was still building when the bench stopped waiting at 600 s. Short queries became 2 to 5 times slower.

The fix gives the facet indexes of a dataset a budget: a quarter of its maxMemory or of --memory-limit, whichever is lower.

  • A build (make, update) counts what it holds as it reads: each feature's IRI and values, each geometry and the WKT it keeps. It stops as soon as the build plus the other kept indexes would go past the budget, and logs a line saying so.
  • That collection is then counted and drawn with queries, the same as one the warm-up had no time for. It is remembered per view, so it is not built again or queued for the background until the budget grows.
  • When the budget shrinks below what the indexes hold, they are dropped as under the memory quota: limited views first, then the default view.
  • With neither limit set, nothing changes.
  • Store::memory_limit() exposes the --memory-limit value to the server.

How it was tested

  • New tests/facet_index_budget.rs. Without limits, both indexes are made. With a maxMemory whose quarter fits the stations but not the lines, the lines fail with the message, are not left for the background, mapCaches stays within the quarter, and the facet counts are the same. A larger quota makes the index again. --memory-limit bounds the indexes the same way.
  • Passing: --lib, warm_up, limits, low_zoom, text_tile_memory, tile_cache, feature_list, ogc, plus cargo clippy --all-targets and cargo fmt --check.
  • Local measurement, no paid run. The data is OSM Norway through osm_scale.py --set a, copied 8 times: 11.7M triples, 2.3M features, a 504 MB store. Release builds, 4 vCPU. Query times are the median of 5 warm runs.
bb4b496 648ec84 main d9e6db0 this PR, --memory-limit 2G
peak heap during the warm-up 308 MiB 5,548 MiB 5,545 MiB 1,492 MiB
heap after the warm-up 136 MiB 1,865 MiB 1,903 MiB 361 MiB
warm-up 3.1 s 22.9 s 26.7 s 9.8 s
under a 3 GB cgroup cap runs OOM-killed OOM-killed runs
scale_class_counts 0.77 ms 0.85 ms 0.99 ms
scale_label_lookup 0.47 ms 0.83 ms 0.65 ms
osm_station_admin 48.2 ms 44.6 ms 41.5 ms

With memory to spare, the queries take the same time on every build, which confirms the 1B difference is page-cache pressure. Without a limit this PR behaves as main (peak 5,526 MiB). The build's count is about 70 % of the real heap (land use: 3.66 GB counted against about 5.4 GB peak), because the queries' own working memory is not counted. The docs say so.

The 1B confirmation needs the next scale run, which is a paid run and needs Mathias's OK.

Documentation

  • The user guide (docs/guide/10-maps-and-apis.md) says what the limit does to the layers' indexes
  • docs/server.md (the map's warm-up, --memory-limit, maxMemory) and the CHANGELOG describe it

Generated by Claude Code

…emory-limit (#809, #796)

The map's facet indexes keep each feature's IRI, values and geometry, and
nothing bounded them: at 1B triples with --memory-limit 32G the warm-up's
indexes held about 40 GB of heap, which took the page cache the store's
files need, and short queries became 2 to 5 times slower.

A build now counts what it holds as it reads and stops past a quarter of
the dataset's maxMemory or of --memory-limit (the lower), less what the
other indexes hold. The collection is then counted and drawn with queries,
and not tried again (nor queued for the background) until the budget
grows. Without either limit nothing changes.
@MathiasVDA MathiasVDA self-assigned this Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

The audit job fails on RUSTSEC-2026-0628 (calamine 0.38, a new advisory). This PR does not cause it: the same lock file is on main, and #828 bumps calamine to 0.39. I'll merge main into this branch once #828 lands.


Generated by Claude Code

… them

A tile request starts making the collections again on a thread; when that
finished before the request read them, the planted non-gzip answer kept for
the new data version was served and the test failed with UnexpectedEof.

Part of #809
@MathiasVDA MathiasVDA added the review:approved Reviewer approved label Dec 3, 2026 — with Claude

Copy link
Copy Markdown
Contributor Author

Approved at 12951fa. I merge it when the tests are green.

What I checked beyond the diff: a scratch test with a quota the lines' index just fits in (11 to 20 times the map's caches), three updates and a delete after the warm-up. The index is brought up to date each time and nothing is marked as too large, so the count of update (the index before plus what it reads again) does not push a fitting index out.

Notes, none blocking:

  1. The count is the peak of the build, not what is kept. In the test data the lines' index keeps 0.7 MB and its build counts about 1.8 MB (the WKT is counted twice while it is read). So a quarter of the limit keeps indexes of roughly a tenth of it for collections of long geometries. The docs say what is counted, which is enough for now. On OSM Europe with --memory-limit 32G this means buildings, roads and land use are drawn with queries: the next scale run should report the tile times of those layers next to the short queries.
  2. A collection stays marked as too large until the budget grows or the server restarts, also after a delete that would make it fit.
  3. budget_for takes off what the indexes of limited views hold. With row or graph policies, a build of the full view after an update can then fail and be marked, while the quota drops the limited views first everywhere else. Dropping the limited views' indexes before giving up on a full-view build would keep the order the same.

Points 2 and 3 are worth one follow-up issue.


Generated by Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved Reviewer approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: short queries and osm_station_admin at 1B slower on 648ec84 than on bb4b496 fix(map): count facet index builds against the dataset's maxMemory

1 participant