0

My application is running mongodb 2.4.8 using 2.11.2 version of java driver. It always end up with mongo taking too much cache on my RHEL when there are too many objects in the database. Almost 4GB of my total 8GB is mostly cached. Even if i try to clear the cache forcefully (as admin) using "sync; echo 3 > /proc/sys/vm/drop_caches" it does not clear the cache, but once i stop mongo i can clear the cache using this command. I see nearly 600+ connections to my mongo server using db.serverStatus().connections (I have nearly 6 other app servers writing or reading data from the mongo server).

  1. Is this connection number that is causing the heavy cache?
  2. Even if not, should i be having these many connections to my database?
  3. Currently connectionsPerHost is set as 100 in my code. Is this too high?
  4. Can i keep the connectionsPerHost to 10 and threadsAllowedToBlockForConnectionMultiplier to something like 500? Is this something that is recommended?

Thanks in advance

Akhil Achuthan
  • 141
  • 3
  • 16

1 Answers1

3

600 connections is not unreasonable on a mongod instance. In MongoDB 2.4 the limit is 20K. While there is a cost in memory usage for each connection it should be small. I would suggest the following blog post for more on MongoDB connections: http://blog.mongolab.com/2013/11/deep-dive-into-connection-pooling/

It is important to note that MongoDB will make use of the memory available to it as needed. For the most part this memory will be process resident memory. If you see a large file-system cache for mongod data files it could be that your readahead settings are too high. Readahead is a mechanism where a disk access will pull in additional blocks of sequential data - improving sequential I/O. It is not necessarily beneficial for a process performing random i/o which is generally the case with database systems. To check please run:

  • sudo blockdev --report

A readahead of 32 is recommended as a good starting point for your MongoDB data filesystem. Defaults are often much higher - targeted towards sequential I/O rather than random.

It is important to note that filesystem cache usage - even when high - should not generally be a concern. Linux uses unused memory to populate this cache and should free if needed by active processes.

As for your questions #3 & #4 - I would not tweak the default settings unless needed. Changing will not reduce filesystem cache.

James Wahlin
  • 2,811
  • 21
  • 22