Commit 7d379dc
Cache parameterized Mapnik maps per render thread to fix PostGIS memory leak
When parameterize_style is configured, render() previously created a full
copy of the Mapnik Map object and called set_datasource() on each affected
layer for every single tile render. Each set_datasource() call creates a new
PostGIS datasource, which registers a new connection pool entry in Mapnik's
global ConnectionManager singleton. These pools were never released, causing
renderd to exhaust memory rapidly under load. SQLite-backed styles were
unaffected because the SQLite datasource has no global connection pool.
Fix: add a std::map<string, mapnik::Map> parameterized_map_cache to
xmlmapconfig. On the first render for a given options string the parameterized
Map is built as before and then moved into the cache. Subsequent renders with
the same options reuse the cached Map directly, calling set_datasource() only
once per (thread, style, options) combination.
Document the remaining render_thread startup allocation leaks in CLAUDE.md.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent f3e3ed6 commit 7d379dc
2 files changed
Lines changed: 40 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
137 | 142 | | |
138 | 143 | | |
139 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
92 | 97 | | |
93 | 98 | | |
94 | 99 | | |
| |||
247 | 252 | | |
248 | 253 | | |
249 | 254 | | |
250 | | - | |
251 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
252 | 274 | | |
253 | | - | |
254 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
255 | 278 | | |
256 | 279 | | |
257 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
258 | 286 | | |
259 | 287 | | |
260 | 288 | | |
261 | 289 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
| 290 | + | |
| 291 | + | |
275 | 292 | | |
276 | 293 | | |
277 | 294 | | |
| |||
0 commit comments