Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB - Forcefully keeping index + working set in RAM

Tags:

mongodb

I am currently using MongoDB to store a single collection of data. This data is 50 GB in size and has about 95 GB of indexes. I am running a machine with 256 GB RAM. I basically want to have all the index and working set in the RAM since the machine is exclusively allocated to mongo.

Currently I see that, though mongo is running with the collection size of 50 GB + Index size of 95 GB, total RAM being used in the machine is less than 20 GB.

Is there a way to force mongo to leverage the RAM available so that it can store all its indexes and working set in memory ?

like image 653
Skynet Avatar asked May 03 '13 17:05

Skynet


1 Answers

When your mongod process starts it has none of your data in resident memory. Data is then paged in as it is accessed. Given your collection fits in memory (which is the case here) you can run the touch command on it. On Linux this will call the readahead system call to pull your data and indexes into the filesystem cache, making them available in memory to mongod. On Windows mongod will read the first byte of each page, pulling it in to memory.

If your collection+indexes do not fit into memory, only the tail end of data accessed during the touch will be available.

like image 127
James Wahlin Avatar answered Sep 18 '22 22:09

James Wahlin