Buy Percona ServicesBuy Now!

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.

The Percona Memory Engine is available in Percona Server for MongoDB along with the standard MongoDB engines (the original MMAPv1 and the default WiredTiger), as well as MongoRocks.

Using Percona Memory Engine

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, /etc/mongod.conf):

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 --dbpath command-line option:

    $ service mongod stop
    $ mongod --storageEngine inMemory --dbpath <newDataDir>
    

    Note

    Make sure that the user running mongod has read and write permissons for the new data directory.

    Note

    Although Percona Memory Engine stores all data in memory, some diagnostics and statistics are still written to disk. This is controlled using the --inMemoryStatisticsLogDelaySecs option.

  • 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 and mongorestore utilities:

    $ 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>
    

Configuring Percona Memory Engine

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 starting the mongod daemon with the following options:

mongod --storageEngine=inMemory \
  --inMemorySizeGB=140 \
  --inMemoryStatisticsLogDelaySecs=0

The following options are available (with corresponding YAML configuration file parameters):

option --inMemorySizeGB
Config:storage.inMemory.engineConfig.inMemorySizeGB
Default:50% of total memory minus 1024 MB, but not less than 256 MB

Specifies the maximum memory in gigabytes to use for data.

option --inMemoryStatisticsLogDelaySecs
Config:storage.inMemory.engineConfig.statisticsLogDelaySecs
Default:0

Specifies the number of seconds between writes to statistics log. If 0 is specified then statistics are not logged.

Visit Percona Store


General Inquiries

For general inquiries, please send us your question and someone will contact you.