Percona Memory Engine¶
Percona Memory Engine is a special configuration of WiredTiger that does not store user data on disk. Data fully resides in the main memory, making processing much faster and smoother. Keep in mind that you need to have enough memory to hold the data set, and ensure that the server does not shut down.
As of version 3.2, Percona Server for MongoDB runs with WiredTiger by default. You can select a
storage engine using the
--storageEngine command-line option when you start
mongod. Alternatively, you can set the
storage.engine variable in the
configuration file (by default,
Data created by one storage engine is not compatible with other storage engines, because each one has its own data model. When changing the storage engine, you have to do one of the following:
If you simply want to temporarily test Percona Memory Engine, change to a different data directory with the
--dbpathcommand-line option. Make sure that the user running mongod has read and write permissons for the new data directory.
$ service mongod stop $ mongod --storageEngine inMemory --dbpath <newDataDir>
Although Percona Memory Engine stores all data in memory, some diagnostics and statistics are still written to disk. This is controlled using the
If you want to permanently switch to Percona Memory Engine and do not have any valuable data in your database, clean out the default data directory and edit the configuration file:
$ service mongod stop $ rm -rf /var/lib/mongodb/* $ sed -i '/engine: .*inMemory/s/#//g' /etc/mongod.conf $ service mongod start
If there is data that you want to migrate and make compatible with Percona Memory Engine, use the
$ mongodump --out <dumpDir> $ service mongod stop $ rm -rf /var/lib/mongodb/* $ sed -i '/engine: .*inMemory/s/#//g' /etc/mongod.conf $ service mongod start $ mongorestore <dumpDir>
You can configure the Percona Memory Engine using either command-line options or
corresponding parameters in the
/etc/mongod.conf file. The
configuration file is formatted in YAML. For example:
storage: engine: inMemory inMemory: engineConfig: inMemorySizeGB: 140 statisticsLogDelaySecs: 0
Setting parameters in the previous example configuration file is the same as
mongod daemon with the following options:
$ mongod --storageEngine=inMemory \ --inMemorySizeGB=140 \ --inMemoryStatisticsLogDelaySecs=0
The following options are available (with corresponding YAML configuration file parameters):
Default: 50% of total memory minus 1024 MB, but not less than 256 MB
Specifies the maximum memory in gigabytes to use for data.
Specifies the number of seconds between writes to statistics log. If 0 is specified then statistics are not logged.