3

Why does mongodb logs show too many opened connections? It's showing me more than the maximum connection limit and number of current operations in db.

Also my primary refused to create more connections after reaching 819 limit. That time, the number of current operations in db were less than 819. Raising ulimit has solved my problem temporarily, but why were idle connections not utilized to serve the requests?

4444
  • 3,541
  • 10
  • 32
  • 43
user2638955
  • 91
  • 1
  • 4
  • What mongodb library are you using? It sounds like a failure to properly pool connections on its part. –  Jul 31 '13 at 17:36
  • Can you describe your MongoDB setup (# replicas, sharded?) as well as the # of clients you are running? Also, what is the connection pool size set on your clients? This will all factor in. In regards to ulimits, I would suggest reading through the MongoDB Production notes page to help in setting up your environment properly (see http://docs.mongodb.org/manual/administration/production-notes/) – James Wahlin Jul 31 '13 at 21:00
  • I am using 1 primary and one replica secondary setup. Four web applications are accessing the primary using java driver 2.11.2. Each web app has connectionsPerHost=100 and threadsAllowedToBlockForConnectionMultiplier=20 – user2638955 Aug 05 '13 at 06:23

3 Answers3

2

I was having this exact same problem. My connection number just kept growing and growing until it hit 819 and then no more connections were allowed.

I'm using mongo-java-driver version 2.11.3. What has seemed to fix the problem is explicitly setting the connectionsPerHost and threadsAllowedToBlockForConnectionMultiplier properties of the MongoClient. Before I was not setting these values myself and accepting the defaults.

MongoClientOptions mco = new MongoClientOptions.Builder()
    .connectionsPerHost(100)
    .threadsAllowedToBlockForConnectionMultiplier(10)
    .build();
MongoClient client = new MongoClient(addresses, mco); //addresses is a pre-populated List of ServerAddress objects

In my application the MongoClient is defined as a static singleton.

I was watching the mongodb logs, and once the application hit 100 open connections I didn't see any more connections established from the client application. I am running a replica set, so you still see the internal connections being made which properly close.

eMike Wallace
  • 151
  • 2
  • 3
  • This helped me. Evidently, this specifies the maximum number of connections to pool if you're using (what I understand to be the generally advised) static singleton pattern for sharing one Mongo Client for one's application. – bleeckerj Dec 07 '13 at 08:46
0

From the MongoDB documentation:

"If you see a very large number connection and re-connection messages in your MongoDB log,then clients are frequently connecting and disconnecting to the MongoDB server. This is normal behavior for applications that do not use request pooling, such as CGI. Consider using FastCGI, an Apache Module, or some other kind of persistent application server to decrease the connection overhead.

If these connections do not impact your performance you can use the run-time quiet option or the command-line option --quiet to suppress these messages from the log."

http://docs.mongodb.org/manual/faq/developers/#why-does-mongodb-log-so-many-connection-accepted-events

soulkphp
  • 3,753
  • 2
  • 17
  • 14
  • 1
    Why my primary is refusing connection after 819 opened connection eventhough no of current operation are less than 819? Why it is not using connections in pool? – user2638955 Aug 03 '13 at 04:59
0

Make sure you are using latest driver of mongodb.

vivex
  • 2,496
  • 1
  • 25
  • 30