After years of Plone/Zope running on a 10.5 web server, this last weekend I started seeing the zope logs filling with errors saying “ Too many open files”. One, I hadn’t seen this before, and two, I couldn’t figure out why it was happening after years of solid use.
So, looking around online, it appeared that 10.5 just set the max files open per user to an awfully small limit (especially in the server version)… 256 files per user! Since I use a zeo/client setup, and use FileSystemStorage for storing files outside the zodb, I easily had this many files open. Again, why is this just happening after years?
I found a fair amount of info online about this issue. ulimit seemed to be the way to fix this on many *nix’s, but since 10.5 replaced much of this functionality with launchd, so it didn’t seem to actually do much.
First, from the command line, run “launchctl limit”. This will show you 3 columns. The first is the type, then the limit per user, then the limit for the whole system. So, at least in 10.5, you’ll see the maxfiles is 256 per user. To fix this, you have to create a file /etc/launchd.conf. In that, you just want to put “limit maxfiles 2048 unlimited” or something like that. That will raise the limit per user to 2048 (8x the previous limit).
The key, after this, is to reboot. Launchd sets all these limits on boot, and changing them once you’re up and going doesn’t seem to accomplish much (I’m guessing if you closed down everything running as a specific user, then restarted those processes, the new limits would take affect, but it’s just easier to reboot). Once you reboot, you can run “launchctl limit” again and see that the limits are raised.
Me, I set the per user limit to 8192 (32x the original limit), just because I know zope is going to open a lot of files, and this web server doesn’t do anything else.
That’s basically it. If you get errors about too many open files, up the limit, and reboot. Really pretty annoying this limit is so low on a server OS. And looking at my other systems, it’s still 256 per user in 10.6.4. This should be something Apple smartly configures based on usage… the 256 limit seems like something for a multi-user system where people are SSH’ing in and running tasks. Not for something like a web server. =/