Never Run Your Mongodb as Root User


We have recently had a "to many open files" problem in one of our Mongodb servers. Mongodb kept saying "Out of file descriptors. Waiting one second before trying to accept more connections." and accept no more connections.

The first thing came to our mind was that the reason is too much load, our mongodb servers were no longer enough to carry it. But it was wrong. After first research it became clear that it was because of linux's user limits, so our wrong decision: running mongodb servers with the root user.

In linux systems, every user has some limits which decide how much system resources they are allowed to consume. These limits prevent one devil user to drain all the system and to make other users to starve of resources.

In our linux servers, root user had lower limits than mongodb's suggested limits. Even if the root user had the suggested limits, we could have had the problem any way. Because root user is responsible for other operational works, not only for running mongodb. So, the actual limits of Mongodb were much lower.

Solving this issue was easy, we only had to increase the root's limits. But you cannot know how much of these limits goes to mongodb, because root's responsibilities is very open to be changed.

The best solution is to run Mongodb under a user who has suggested limits, and whose responsibility is only to run Mongodb.

For more information visit the following page: http://docs.mongodb.org/manual/reference/ulimit/

Comments

Popular posts from this blog

Migrating from PHP to Python

Memory organization and cache management

(DRAFT) Scaling a django project using celery and elasticsearch