While working on a Java project that executes multiple sub processes, I found it necessary to increase to the file descriptor limit. By default, processes spawned in Ubuntu had a limit of 1024 open files, but changing that limit via ulimit or by /etc/security/limits.conf had no effect. I discovered that changes in /etc/security/limits.conf (and subsequently /etc/pam.d/common-session ) are only applied to process spawned by a login shell. Programs that launch on startup via “upstart” do not get these limits applied to them. Thankfully, upstart provides the limit stanza that allows you to modify some of these parameters, including the maximum number of open files. To see the limits on process, grab its PID, and cat /proc/<<PID>>/limits
The following is an example of increase the maximum number of open files to 4096 for a given upstart job:
You can checkout the full set of limit options at: http://upstart.ubuntu.com/wiki/Stanzas#limit
Note: Some of these limits (if not all) are transferred to any children that are forked by the parent
Check out upstart at: http://upstart.ubuntu.com/
Thanks for the tip, took me a few hours to realize this fact.
Thank you sir. Very helpful.
[…] http://bryanmarty.com/blog/2012/02/10/setting-nofile-limit-upstart/ […]
which file should i put “limit nofile 4096 4096” into?
only can apply to one service? or globally
Thanks very much for this. I spent several hours trying to figure out why I was hitting these limits even though every last setting had been adjusted to allow for more open FDs (or so I thought).
It seams that using this on my service only raises the hard limit – the soft limit stays at 1024. Any idea why?