6

I am interested in using a database that will allow high performance, with an expected requirement of cluster for a massive horizontal scaling.

We are looking into using MongoDB, does anyone know if I can use it InMemory (i.e. in the RAM - for performance reasons)?

Tnx

Joezer
  • 625
  • 1
  • 9
  • 20
  • possible duplicate of [Embedded MongoDB when running integration tests](http://stackoverflow.com/questions/6437226/embedded-mongodb-when-running-integration-tests) – Teoman Soygul Oct 26 '14 at 11:15
  • 1
    @teoman-soygul - not a duplicate. the Q you linked to asks about embedding the DB into an application in a way that it will auto start etc. this Q is talking about embedding it in the RAM instead of file based DB, wanted In-Mem DB performance. – Joezer Oct 26 '14 at 13:40

5 Answers5

8

As of today, latest version of MongoDB, i.e. v3.4 supports in memory engine in their Enterprise software edition. If you seek open source edition, Percona's MongoDB is way to go.

Mongo Enterprise edition : https://docs.mongodb.com/manual/core/inmemory/

Percona's MongoDB offering: https://www.percona.com/software/mongo-database/percona-memory-engine-for-mongodb

Piyush Katariya
  • 655
  • 8
  • 11
7

A performance boost approach you can take is to use a RAM disk

e.g.:

mongod --smallfiles --noprealloc --nojournal --dbpath <ramdisk mounted localtion>

See also:

Community
  • 1
  • 1
  • Tnx, worth a shot, I have thought about it as an option while googling through threads ... – Joezer Oct 29 '14 at 08:52
  • @SitnTheShade: What exactly is the point in adding a RAM disk when you can achieve pretty much the same with MongoDB alone? And on any supported platform pretty much the same way? – Markus W Mahlberg Jan 16 '15 at 10:41
  • 1
    @Markus W Mahlberg - Do you mean the solution you posted below (updaing the syncPeriodSecs to 0)? if so I noticed that in the MongoDB website they specifically state that this parameters should not be touched ("Controls how much time can pass before MongoDB flushes data to the data files via an fsync operation. Do not set this value on production systems. In almost every situation, you should use the default setting."). Do you know differently? –  Jan 18 '15 at 08:14
6

Using a tmpfs

At least on linux, since MongoDB uses memory mapped (mmap) files, you can set up a tmpfs system that resides in memory.

Here's a neat tutorial on setting up a tmpfs for MongoDB.

Memory mapped files

Memory mapped files are explained in more detail on their FAQ. It also says that MongoDB is automatically configured to use all available free memory on a system as its cache (link).

Conclusion

Basically, there is no module for a purely in-memory database, but by using an in-memory fs, one can emulate it.

On a side note, I did find MorboDB, a "In-memory database, mostly-compatible clone of MongoDB". Probably not useful to you, but I thought it interesting.

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
cptaffe
  • 426
  • 3
  • 8
2

Actually, it is quite easy to do so. Simply set syncPeriodSecs to 0 and disable journaling. In order to prevent most files to be created, simply start mongod with

mongod --noprealloc --nojournal 

or the equivalent options configured in mongod.conf.

However, namespace files will be created whatever you do. In case you use a replica set, oplog files will be created, too.

In order to make sure that your mongodb will not eat up all available RAM and inserts don't throw an exception under those circumstances, you might want to have a look at capped collections.

Markus W Mahlberg
  • 19,711
  • 6
  • 65
  • 89
  • 1
    in the MongoDB website they specifically state that this parameters should not be touched. The site states that it "Controls how much time can pass before MongoDB flushes data to the data files via an fsync operation. Do not set this value on production systems. In almost every situation, you should use the default setting" –  Jan 18 '15 at 08:40
  • 2
    @SitnTheShade: I am pretty aware of the docs ;) Those parameters should not be touched for _standard_ use, as fiddling with them may greatly impact performance (because of unnecessary disk IO) and / or data durability. In this case neither disk IO or data durability are of any concern. But in general you are right – fiddling with those values is a Very Bad Idea™ unless you _really_ know what you are doing. – Markus W Mahlberg Feb 03 '15 at 21:13
2

Try https://github.com/nodkz/mongodb-memory-server

this helps for testing

npm i mongodb-memory-server

Manjesh V
  • 1,230
  • 15
  • 22