Can I configure MongoDB to be In-Memory?

谁说胖子不能爱 提交于 2019-12-06 11:34:06
SitnTheShade

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:

cptaffe

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.

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.

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

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

this helps for testing

npm i mongodb-memory-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!