MongoDB Connections – Troubleshooting High Connection Count

linuxmongodbmongodb-3.0

I currently have my MongoDB running in Production Environment. It has 1 Primary, 1 secondary and an Arbiter. Configuration of the ubuntu machines are pretty decent, it's got 56GB of RAM and about 100GB of HardDisk space. It's been around a week's time since MongoDb has been running continuously. I did some reading about the uLimit and it is set as

httpd soft nofile 10240
httpd hard nofile 10240
* soft nofile 65000
* hard nofile 65000

Our server-side is Java and we have implemented connection pooling. Today when I did a db.serverStatus(), under connections I got the following

"connections" : {
            "current" : 19314,
            "available" : 32686,
            "totalCreated" : NumberLong(53770)
    },

Is this something which I should be concerned with, because I could not find any limit or number which tells me I've reached a danger limit before mongoDB crashes. Can anyone let me know if there is anything I should be doing?

Best Answer

RAM, mainly. Every connection gets a stack allocated, at the size of 1MB. The more connections you have, the more RAM is needed for them and the less RAM is available for keeping indices or the working set of data in RAM.

So with your 19314 connections, roughly 19GB of RAM is used for connections. That's roughly a third of your available RAM – which is too much, from my point of view. What is acceptable has very much to do with your use cases, performance needs and whatnot. Finding out an acceptable RAM utilization is out of scope of an answer and can take many hours of analysis and optimization.