Skip to content

This documentation is for the end of life version of Percona Server for MongoDB and is no longer supported. You may want to see the current documentation.

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):

See also

MongoDB Documentation: Configuration File Options

Data files created by one storage engine are not compatible with other storage engines, because each one has its own data model.

When changing the storage engine, the mongod node requires an empty dbPath data directory when it is restarted. Though Percona Memory Engine stores all data in memory, some metadata files, diagnostics logs and statistics metrics are still written to disk. This is controlled using the --inMemoryStatisticsLogDelaySecs option.

To change a storage engine, you have the following options:

  • If you simply want to temporarily test Percona Memory Engine, set a different data directory for the dbPath variable in the configuration file. Make sure that the user running mongod has read and write permissons for the new data directory.

    $ service mongod stop
    $ # In the configuration file, set the inmemory
    $ # value for the storage.engine variable
    $ # Set the <newDataDir> for the dbPath variable
    $ service mongod start
    
  • If you want to permanently switch to Percona Memory Engine and do not have any valuable data in your database, clean out the dbPath data directory (by default, /var/lib/mongodb) and edit the configuration file:

    $ service mongod stop
    $ rm -rf <dbpathDataDir>
    $ # Update the configuration file by setting the new
    $ # value for the storage.engine variable
    $ # set the engine-specific settings such as
    $ # storage.inMemory.engineConfig.inMemorySizeGB
    $ service mongod start
    
  • If there is data that you want to migrate and make compatible with Percona Memory Engine, use the following methods:

    • for replicasets, use the “rolling restart” process. Switch to the Percona Memory Engine on the secondary node. Clean out the dbPath data directory and edit the configuration file:

      $ service mongod stop
      $ rm -rf <dbpathDataDir>
      $ # Update the configuration file by setting the new
      $ # value for the storage.engine variable
      $ # set the engine-specific settings such as
      $ # storage.inMemory.engineConfig.inMemorySizeGB
      $ service mongod start
      

      Wait for the node to rejoin with the other nodes and report the SECONDARY status.

      Repeat the procedure to switch the remaining nodes to Percona Memory Engine.

    • for a standalone instance or a single-node replicaset, use the mongodump and mongorestore utilities:

      $ mongodump --out <dumpDir>
      $ service mongod stop
      $ rm -rf <dbpathDataDir>
      $ # Update the configuration file by setting the new
      $ # value for the storage.engine variable
      $ # set the engine-specific settings such as
      $ # storage.inMemory.engineConfig.inMemorySizeGB
      $ 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):

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

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