Skip to content

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 default MongoDB engine WiredTiger.

Usage

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

storage:
  dbPath: <dataDir>
  engine: inMemory

Configuration

You can configure Percona Memory Engine using either command-line options or corresponding parameters in the /etc/mongod.conf file. The following are the configuration examples:

The configuration file is formatted in YAML

storage:
  engine: inMemory
  inMemory:
    engineConfig:
      inMemorySizeGB: 140
      statisticsLogDelaySecs: 0

Setting parameters in the configuration file is the same as starting the mongod daemon with the following options:

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

Options

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

Configuration file storage.inMemory.engineConfig.inMemorySizeGB
Command line inMemorySizeGB()
Default 50% of total memory minus 1024 MB, but not less than 256 MB
Description Specifies the maximum memory in gigabytes to use for data
Configuration file storage.inMemory.engineConfig.statisticsLogDelaySecs
Command line inMemoryStatisticsLogDelaySecs()()
Default 0
Description Specifies the number of seconds between writes to statistics log. A 0 value means statistics are not logged

Switching storage engines

Considerations

If you have data files in your database and want to change to Percona Memory Engine, consider the following:

  • Data files created by one storage engine are not compatible with other 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 with the --inMemoryStatisticsLogDelaySecs option.

Creating a new dbPath data directory for a different storage engine is the simplest solution. Yet when you switch between disk-using storage engines (e.g. from WiredTiger to Percona Memory Engine), you may have to delete the old data if there is not enough disk space for both. Double-check that your backups are solid and/or the replica set nodes are healthy before you switch to the new storage engine.

Procedure

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

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 permissions for the new data directory.

  1. Stop mongod

    $ service mongod stop
    
  2. Edit the configuration file

    storage:
      dbPath: <newDataDir>
      engine: inmemory
    
  3. Start mongod

    $ service mongod start
    

Permanent switch to Percona Memory Engine without any valuable data in your database

Clean out the dbPath data directory (by default, /var/lib/mongodb) and edit the configuration file:

  1. Stop mongod

    $ service mongod stop
    
  2. Clean out the dbPath data directory

    $ sudo rm -rf <dbpathDataDir>
    
  3. Edit the configuration file

    storage:
      dbPath: <newDataDir>
      engine: inmemory
    
  4. Start mongod

    $ service mongod start
    

Switch to Percona Memory Engine with data migration and compatibility

For a standalone instance or a single-node replica set, use the mongodump and mongorestore utilities:

  1. Export the dataDir contents

    $ mongodump --out <dumpDir>
    
  2. Stop mongod

    $ service mongod stop
    
  3. Clean out the dbPath data directory

    $ sudo rm -rf <dbpathDataDir>
    
  4. 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

  5. Start mongod

    $ service mongod start
    
  6. Restore the database

    $ mongorestore <dumpDir>
    

Use the “rolling restart” process.

  1. Switch to the Percona Memory Engine on the secondary node. Clean out the dbPath data directory and edit the configuration file:

  2. Stop mongod

    $ service mongod stop
    
  3. Clean out the dbPath data directory

    $ sudo rm -rf <dbpathDataDir>
    
  4. Edit the configuration file

    storage:
      dbPath: <newDataDir>
      engine: inmemory
    
  5. Start mongod

    $ service mongod start
    
  6. Wait for the node to rejoin with the other nodes and report the SECONDARY status.

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

Data at rest encryption

Using Data at Rest Encryption means using the same storage.\* configuration options as for WiredTiger. To change from normal to Data at Rest Encryption mode or backward, you must clean up the dbPath data directory, just as if you change the storage engine. This is because mongod cannot convert the data files to an encrypted format ‘in place’. It must get the document data again either via the initial sync from another replica set member, or from imported backup dump.

Get expert help

If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services.