.. _inmemory: ===================== 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. .. contents:: :local: :depth: 1 The *Percona Memory Engine* is available in |PSMDB| 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, |PSMDB| 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, :file:`/etc/mongod.conf`): .. seealso:: |mongodb| Documentation: Configuration File Options - `storage.engine Options `_ - `storage.wiredTiger Options `_ - `storage.inmemory 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 |inmemory| stores all data in memory, some metadata files, diagnostics logs and statistics metrics are still written to disk. This is controlled using the :option:`--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. .. code-block:: bash $ service mongod stop $ # In the configuration file, set the inmemory $ # value for the storage.engine variable $ # Set the for the dbPath variable $ service mongod start * If you want to permanently switch to |inmemory| and do not have any valuable data in your database, clean out the ``dbPath`` data directory (by default, :file:`/var/lib/mongodb`) and edit the configuration file: .. code-block:: bash $ service mongod stop $ rm -rf $ # 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 |inmemory| on the secondary node. Clean out the ``dbPath`` data directory and edit the configuration file: .. code-block:: bash $ service mongod stop $ rm -rf $ # 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 |inmemory|. - for a standalone instance or a single-node replicaset, use the ``mongodump`` and ``mongorestore`` utilities: .. code-block:: bash $ mongodump --out $ service mongod stop $ rm -rf $ # 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 .. _`MMAPv1`: https://docs.mongodb.org/manual/core/mmapv1/ .. _`WiredTiger`: https://docs.mongodb.org/manual/core/wiredtiger/ .. _`MongoRocks`: http://rocksdb.org Configuring Percona Memory Engine ================================= You can configure the Percona Memory Engine using either command-line options or corresponding parameters in the :file:`/etc/mongod.conf` file. The configuration file is formatted in YAML. For example: .. code-block:: text 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: .. code-block:: bash 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. .. |inmemory| replace:: Percona Memory Engine .. |mongod| replace:: ``mongod``