Added ability to set open file descriptor limit at run-time #89
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instead of running
ulimit -n
from init script, we could utilize the POSIXsetrlimit(2)
system function and set the open file limit dynamically at run-time.To do this, I added an optional config file variable called
nofile
. Ifnofile
exists in the config file and it's value is greater than 0, then we will try to setRLIMIT_NOFILE
when server starts.Please note that on Linux, only privileged user could raise the hard limit, that's why we need to call
setrlimit(2)
before callingrun_as
. Upon failure to setRLIMIT_NOFILE
, we simply output some helpful error message and keeps going.Tested and confirmed to work on Linux 3.15.4 and Mac OS X 10.9.4.
Support of
setrlimit(2)
was added since Linux 2.6.36 and 4.2BSD.