You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
defaulting CLOSE_CONNECTION=DEFER for rasters leads to large memory consumption with FCGI #7459
i have a 12-process FCGI pool w/ supervisord, servicing loads of WMS requests from large COGs (eg ~150 files, most around 40/70Go, some around 250Go). that's running mapserver 8.6 on debian 13, and is used as a backend for mapproxy which serves requests to end users.
i always had a large memory consumption for the mapserver pools, eg i have a supervisor plugin (superlance/memmon) that kills a worker when it reaches 8Gb, and i have workers getting killed every hour, where i have ~50k hits a day.
so far i attributed this large memory consumption to memleaks down the line in the libraries, but found out that setting PROCESSING "CLOSE_CONNECTION=NORMAL" in each layer config stopped the large memory consumption. Measuring the memory consumption of replaying 5000 requests from a production accesslog on the 12 workers, i noted a 80Gb growth with DEFER, and negligible with NORMAL
so my question is, would it make sense to default CLOSE_CONNECTION to NORMAL for long-running FCGI processes, when using raster data or vector files (i guess the same issue can happen with a bunch of large shps/gpkgs..) ? for postgis layers it makes sense to default to DEFER so that the connections are kept in the pool, but for files... is there a way in the code to know at runtime that we're running as FCGI and not old-school/traditional CGI ?
@landryb - I don't believe there is a way to know if you are running through CGI or FastCGI.
Based on your experience it would make sense to me that the code could be updated to default to DEFER unless explicitly set to CLOSE_CONNECTION ALWAYS for the layer.
I'm not sure of the logic behind setting to DEFER for rasters though.
I'm not sure of the logic behind setting to DEFER for rasters though.
i dunno, from my reading of the code history that seems to be historic. at the time, maybe it made sense if the cost of opening a raster was large, compared to having it already opened. right now, it might only make sense if you have a small amount of small rasters, less so if you have many large ones.
I can confirm the problem with the high RAM usage. I compared my previous data structure to a BIGTIFF variant. The difference in RAM usage between MapServer 8.4 (Debian 13) and the previous MapServer 8.0 (Debian 12) is as follows:
If you have 20,000 TIFF files on disk and create an index using gdaltindex, which is then included in the map file with "TILEINDEX" & TYPE RASTER, MapServer 8.4 uses up to 10 times more RAM. If I calculate a BIGTIFF with an overview from the 20,000 files and specify (PROCESSING "CLOSE_CONNECTION=NORMAL"), then the RAM usage behaves like it did previously with MapServer 8.0.
I'm also concerned that the response times of MapServer 8.4 with HTTP Apache FCGI aren't as good as they were with MapServer 8.0.
Is there anything else to consider when migrating MapServer from Debian 12 to Debian 13? For example, should the raster data be rewritten using the newer GDAL version?
if (close_connection==NULL&&layer->tileindex==NULL)
Does it mean that it does not have an effect in Mapserver 8.4 for some other reason?
@landryb, do you have 150 separate COG layers instead of a tileindex layer? But @geo856 , you do have a tileindex layer but still suffer from high memory usage.
Maybe someone should do a bechmark and test if there is any use case when CLOSE_CONNECTION=DEFER is actually good.
i think CLOSE_CONNECTION=DEFER makes sense for data in actual databases or local small files, less so for huge files..
i do have 150 separate COGs for distinct areas/dates, which were all previously (eg before 2023) separate/distinct tileindex layers in postgis with bazillions of tiles/tiffs/jp2, and the memory consumption when using postgis tileindex was also large but not as large as when using COGs.
I havent seen an actual memory consumption increase between 8.0 (debian 12) & 8.6 (debian 13 with backports)
the benchmarks i did with CLOSE_CONNECTION=normal with my COGs didnt show a response time increase/regression, so i'm probably going to switch all my COGs to it.
When you used the PostGIS tileindex layers, did you ever experiment if CLOSE_CONNECTION= settings on the PostGIS vector layers, which were then used as TILEINDEX source for the raster layers, had any effect on speed or memory consumption?
If you have 20,000 TIFF files on disk and create an index using gdaltindex, which is then included in the map file with "TILEINDEX" & TYPE RASTER, MapServer 8.4 uses up to 10 times more RAM. If I calculate a BIGTIFF with an overview from the 20,000 files and specify (PROCESSING "CLOSE_CONNECTION=NORMAL"), then the RAM usage behaves like it did previously with MapServer 8.0.
I havent seen an actual memory consumption increase between 8.0 (debian 12) & 8.6 (debian 13 with backports)
It feels like some well controlled systematic testing with tileindex would be needed because they are widely used. Unfortunately I do not have proper environment for testing at the moment. @geo856, was your tileindex a shapefile index or a database index?
The life span indicator is controlled by the CLOSE_CONNECTION PROCESSING
the NORMAL option indeed exists but I do not quite understand the difference between NORMAL and ALWAYS. If there is a difference, then perhaps it should be explained in the user documentation as well.
Line 57 in eb2d8af
The life span indicator is controlled by the CLOSE_CONNECTION PROCESSING
the NORMAL option indeed exists but I do not quite understand the difference between NORMAL and ALWAYS. If there is a difference, then perhaps it should be explained in the user documentation as well.
i don't exactly remember right now, but when i looked at the code and the doc i think i concluded that 'anything but DEFER will close it'
Activity
geographika commentedon Mar 21, 2026
@landryb - I don't believe there is a way to know if you are running through CGI or FastCGI.
Based on your experience it would make sense to me that the code could be updated to default to
DEFERunless explicitly set toCLOSE_CONNECTION ALWAYSfor the layer.I'm not sure of the logic behind setting to
DEFERfor rasters though.landryb commentedon Mar 23, 2026
i dunno, from my reading of the code history that seems to be historic. at the time, maybe it made sense if the cost of opening a raster was large, compared to having it already opened. right now, it might only make sense if you have a small amount of small rasters, less so if you have many large ones.
geo856 commentedon Apr 2, 2026
I can confirm the problem with the high RAM usage. I compared my previous data structure to a BIGTIFF variant. The difference in RAM usage between MapServer 8.4 (Debian 13) and the previous MapServer 8.0 (Debian 12) is as follows:
If you have 20,000 TIFF files on disk and create an index using gdaltindex, which is then included in the map file with "TILEINDEX" & TYPE RASTER, MapServer 8.4 uses up to 10 times more RAM. If I calculate a BIGTIFF with an overview from the 20,000 files and specify (PROCESSING "CLOSE_CONNECTION=NORMAL"), then the RAM usage behaves like it did previously with MapServer 8.0.
I'm also concerned that the response times of MapServer 8.4 with HTTP Apache FCGI aren't as good as they were with MapServer 8.0.
Is there anything else to consider when migrating MapServer from Debian 12 to Debian 13? For example, should the raster data be rewritten using the newer GDAL version?
jratike80 commentedon Apr 2, 2026
It seems that "deferred" was not originally planned to be used for tileindex layers
#2815
#3077.
Tileindex exception seems to be there still
MapServer/src/mapraster.c
Line 696 in d0e02b3
Does it mean that it does not have an effect in Mapserver 8.4 for some other reason?
@landryb, do you have 150 separate COG layers instead of a tileindex layer? But @geo856 , you do have a tileindex layer but still suffer from high memory usage.
Maybe someone should do a bechmark and test if there is any use case when CLOSE_CONNECTION=DEFER is actually good.
landryb commentedon Apr 7, 2026
i think
CLOSE_CONNECTION=DEFERmakes sense for data in actual databases or local small files, less so for huge files..i do have 150 separate COGs for distinct areas/dates, which were all previously (eg before 2023) separate/distinct tileindex layers in postgis with bazillions of tiles/tiffs/jp2, and the memory consumption when using postgis tileindex was also large but not as large as when using COGs.
I havent seen an actual memory consumption increase between 8.0 (debian 12) & 8.6 (debian 13 with backports)
the benchmarks i did with
CLOSE_CONNECTION=normalwith my COGs didnt show a response time increase/regression, so i'm probably going to switch all my COGs to it.jratike80 commentedon Apr 7, 2026
When you used the PostGIS tileindex layers, did you ever experiment if
CLOSE_CONNECTION=settings on the PostGIS vector layers, which were then used as TILEINDEX source for the raster layers, had any effect on speed or memory consumption?landryb commentedon Apr 7, 2026
i don't think i've played with disabling connection pooling against databases (they're all backed by pgbouncer anyway, but still..)
jratike80 commentedon Apr 7, 2026
@geo856 wrote
and @landryb wrote
It feels like some well controlled systematic testing with tileindex would be needed because they are widely used. Unfortunately I do not have proper environment for testing at the moment. @geo856, was your tileindex a shapefile index or a database index?
jratike80 commentedon Apr 10, 2026
By the way, the documented options in https://mapserver.org/mapfile/layer.html for CLOSE_CONNECTION are
PROCESSING "CLOSE_CONNECTION=DEFER"
PROCESSING "CLOSE_CONNECTION=ALWAYS"
Why did you use "NORMAL"? Have you been reading https://mapserver.org/input/vector/ogr.html or what?
By looking at the code
MapServer/src/mappool.c
Line 57 in eb2d8af
landryb commentedon Apr 10, 2026
i don't exactly remember right now, but when i looked at the code and the doc i think i concluded that 'anything but DEFER will close it'