garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/optional-layers-on-the-critical-path.md

raw


topic: optional-layers-on-the-critical-path triggers: [OPTIONAL_LAYER_TIMEOUT, BREAKER_COOLDOWN, "http::Breaker", should_fetch, spawn_geometry_task, nav_marks.rs, crossings.rs, api.pdok.nl, "third party", DEFAULT_TIMEOUT] updated: 2026-09-02

An optional layer must cost its own layer, not the map

map_geometry::spawn_geometry_task fetches a cell's tile, then awaits several per-cell datasets, and only then submits the tessellation job. Everything the cell is made of — ground fills, roads, water, bridges, trees, street labels, building footprints — is behind that last await. Two of those datasets are api.pdok.nl's: the navigation marks (systems::nav_marks) and the level crossings (systems::crossings). They are decoration, they are optional, and they are owned by somebody else.

Healthy, they are cheap. A cold start over Groningen makes 18 requests to the marks service (9 cells × 2 collections): 1.70 s in total, median 82 ms, worst 186 ms — about 0.17 s per cell (measured for #267, CARTO_CACHE_DIR pointed at an empty directory). That is not the problem. The problem is the other end: on the inherited DEFAULT_TIMEOUT a service that accepts a connection and then goes quiet costs 20 s per request, the native fetch is a blocking ureq call that holds one of at most eight IoTaskPool threads for all of it, and the surface stream allows eight cells in flight — so a PDOK incident does not read as "no buoys today", it reads as no map.

The rule

A per-cell await that reaches a host we do not own, for data the cell can be drawn without, carries two bounds. Both live in platform::http so a third such layer copies nothing:

The breaker exists because failure is otherwise unremembered: neither layer writes a cache entry on a failed answer (deliberately — a poisoned key is never re-fetched, so half a cell cached under one is worse than a cell asked for again), and map_geometry re-runs the whole task on a re-anchor, a terrain-field revision, a coverage revision or any detail-layer toggle. Without the gate every retear re-pays the full wait for every cell in the ring.

Two constraints on the gate itself, both load-bearing:

The cache is read before the breaker is consulted, and the cell's own gates (coverage, water/rail) before both. A cell already on disk costs the service nothing, so an outage must not blank cells that were complete before it started; a foreign or dry cell must cost neither a request nor a storage lookup.

What this does not fix

Native concurrency. map_geometry awaits the two layers through futures_lite::future::zip, and load_marks_cell does the same with its two collections, but http::fetch is a blocking call with no await point in it on native, so the requests still land in sequence there. The overlap is real only on wasm. Natively what caps a cell's wait is the 3 s bound per request plus the breaker, and the worst case for a first cell during an outage is the three requests end to end. Making it genuine would mean spawning each fetch as its own pool task, which trades a shorter wait for twice the peak thread occupancy in the pool this whole note is about — not obviously the right trade, and not measured.

Directions left open

Neither is foreclosed by the bounds above.