mongodb 실행시 아래와 같은 경고가 발생했다. 

 CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 31394 processes, 1024000 files. Number of processes should be at least 512000 : 0.5 times number of files.




이 문제를 확인하려면, 소스를 확인한다.


https://github.com/mongodb/mongo/blob/c0db389c3f72280d9c82202e9ee6fc70e7a17027/src/mongo/db/startup_warnings_mongod.cpp


#if defined(RLIMIT_NPROC) && defined(RLIMIT_NOFILE) // Check that # of files rlmit > 1000 , and # of processes > # of files/2
const unsigned int minNumFiles = 1000;
const double filesToProcsRatio = 2.0;
struct rlimit rlnproc;
struct rlimit rlnofile;
if (!getrlimit(RLIMIT_NPROC, &rlnproc) && !getrlimit(RLIMIT_NOFILE, &rlnofile)) {
if (rlnofile.rlim_cur < minNumFiles) {
log() << startupWarningsLog;
log() << "** WARNING: soft rlimits too low. Number of files is " << rlnofile.rlim_cur
<< ", should be at least " << minNumFiles << startupWarningsLog;
}
if (false) {
// juse to make things cleaner
}
#ifdef __APPLE__
else if (rlnproc.rlim_cur >= 709) {
// os x doesn't make it easy to go higher
// ERH thinks its ok not to add the warning in this case 7/3/2012
}
#endif
else if (rlnproc.rlim_cur < rlnofile.rlim_cur / filesToProcsRatio) {
log() << startupWarningsLog;
log() << "** WARNING: soft rlimits too low. rlimits set to " << rlnproc.rlim_cur
<< " processes, " << rlnofile.rlim_cur
<< " files. Number of processes should be at least "
<< rlnofile.rlim_cur / filesToProcsRatio << " : " << 1 / filesToProcsRatio
<< " times number of files." << startupWarningsLog;
}
} else {
log() << startupWarningsLog;
log() << "** WARNING: getrlimit failed. " << errnoWithDescription() << startupWarningsLog;
}
#endif





위의 코드를 살펴보면, 아래 코드에서 걸렸다.

else if (rlnproc.rlim_cur < rlnofile.rlim_cur / filesToProcsRatio) {



ulimit -a로 실행해서 나오는 max user processes (rlnproc.rlim_cur)개수가 open files 수 / 2.0 보다 작다면 경고 메시지가 출력된다. 따라서 이 문제를 해결하려면 /etc/security/limits.conf 에 다음 내용을 추가한다.


*       soft    nproc   1024000

*       hard    nproc   1024000



mongodb를 종료하고, logout하고 login 한 후 mongod를 실행하면 다시는 warning로그는 발생하지 않는다.






참고로 아래 에러 로그가 발생하면 file number 개수 크기를 수정한다. (ulimit -n x)


WARNING: soft rlimits too low. Number of files is ...




또한, mongodb에서는 ulimit 설정을 다음과 같이 추천한다. 



http://docs.mongodb.org/manual/reference/ulimit/


Recommended ulimit Settings

Every deployment may have unique requirements and settings; however, the following thresholds and settings are particularly important for mongod and mongos deployments:

  • -f (file size): unlimited
  • -t (cpu time): unlimited
  • -v (virtual memory): unlimited [1]
  • -n (open files): 64000
  • -m (memory size): unlimited [1] [2]
  • -u (processes/threads): 64000



Posted by '김용환'
,