<div dir="ltr"><div>We did some investigation in this regard and the following 2 changes could solve this specific problem on Windows and <a href="http://ASP.NET">ASP.NET</a>.</div><div><br></div><div>1. Adding the ability to use a single cache instead of a per-thread cache. </div><div><br></div><div>2. Increase the number of open stdio file handle limit for Windows. Default is 512 the upper limit is 2048 accoding to this documentation: <a href="https://msdn.microsoft.com/en-us/library/6e3b887c.aspx">https://msdn.microsoft.com/en-us/library/6e3b887c.aspx</a>  </div><div><br></div><div><br></div><div>These settings should probably be controlled with compile options or environment variables.</div><div><br></div><div>Any objections to apply such changes?</div><div><br></div><div>Best regards,</div><div><br></div><div>Tamas</div><div><br></div><div><br></div><div><br></div><div><br></div><br><div class="gmail_extra"><br><div class="gmail_quote">2017-11-27 16:42 GMT+01:00 Lime, Steve D (MNIT) <span dir="ltr"><<a href="mailto:steve.lime@state.mn.us" target="_blank">steve.lime@state.mn.us</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_-1732092239187213257WordSection1">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">The former is certainly simpler. How expensive is setting up and clearing out the cache? Probably should look at Thomas’ RFC on the topic.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"> mapserver-dev [mailto:<a href="mailto:mapserver-dev-bounces@lists.osgeo.org" target="_blank">mapserver-dev-bounces@<wbr>lists.osgeo.org</a>]
<b>On Behalf Of </b>Tamas Szekeres<br>
<b>Sent:</b> Sunday, November 26, 2017 2:01 PM<br>
<b>To:</b> <a href="mailto:mapserver-dev@lists.osgeo.org" target="_blank">mapserver-dev@lists.osgeo.org</a><br>
<b>Subject:</b> [mapserver-dev] Mapserver causes too many open files error<u></u><u></u></span></p><div><div class="gmail-h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Hi Devs,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">We experienced an issue with mapserver 7.x (comparing to 6.x) that it causes too many open file handles in a multi-threaded environment. Actually the process is using the
<a href="http://ASP.NET" target="_blank">ASP.NET</a> backend where the web requests are served through the
<a href="http://ASP.NET" target="_blank">ASP.NET</a> worker process by using a thread pool, and the process should be considered as a long running process, where msCleanup is not being called regularly.<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">By looking into the code the issue should probably be dedicated to the global font cache approach implemented in mapserver 7. Since freetype keeps the font files open, we get the number of fonts used in the mapfile multiplied with the thread
 pool size which may exceed the number of stdio open file handle limit as per <a href="https://msdn.microsoft.com/en-us/library/kdfaxaay(v=vs.140).aspx" target="_blank">https://msdn.microsoft.<wbr>com/en-us/library/kdfaxaay(v=<wbr>vs.140).aspx</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">With the former approach (ie. 6.x) the font cache was implemented in the renderers and the cache cleanup was happening on the renderer cleanup in msFreeOutputFormat/<wbr>msFreeMap.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Do you have any suggestions about a proper workaround to this?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I might think that we should either bind the font cache to each map objects (like earlier) or use a single common font cache for the entire process. I would probably prefer the first one as soon as we want to clean up every resources what
 a rendering session allocates.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Tamas<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div></div></div>
</div>

</blockquote></div><br></div></div>