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
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:
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
来源:https://stackoverflow.com/questions/26572248/can-i-configure-mongodb-to-be-in-memory