MongoRocks is a storage engine for MongoDB based on the RocksDB key-value store optimized for fast storage. It is developed by Facebook and designed to handle write-intensive workloads.

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

Using MongoRocks

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 MongoRocks, change to a different data directory with the --dbpath command-line option:

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


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

  • If you want to permanently switch to MongoRocks 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: .*rocksdb/s/#//g' /etc/mongod.conf
    $ service mongod start
  • If there is data that you want to migrate and make compatible with MongoRocks, use the mongodump and mongorestore utilities:

    $ mongodump --out <dumpDir>
    $ service mongod stop
    $ rm -rf /var/lib/mongodb/*
    $ sed -i '/engine: .*rocksdb/s/#//g' /etc/mongod.conf
    $ service mongod start
    $ mongorestore <dumpDir>

Configuring MongoRocks

You can configure MongoRocks using either command-line options or corresponding parameters in the /etc/mongod.conf file. The configuration file is formatted in YAML. For example, the following sample configuration is suggested as the default for running Percona Server for MongoDB with MongoRocks:

  engine: rocksdb
    cacheSizeGB: 1
    compression: snappy
    maxWriteMBPerSec: 1024
    crashSafeCounters: false
    counters: true
    singleDeleteIndex: false

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

mongod --storageEngine=rocksdb \
  --rocksdbCacheSizeGB=1 \
  --rocksdbCompression=snappy \
  --rocksdbMaxWriteMBPerSec=1024 \
  --rocksdbCrashSafeCounters=false \
  --rocksdbCounters=true \

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

option --rocksdbCacheSizeGB
Default:30% of physical memory

Specifies the amount of memory (in gigabytes) to allocate for block cache. Block cache is used to store uncompressed pages. Compressed pages are stored in kernel’s page cache.

To configure block cache size dynamically, set the rocksdbRuntimeConfigCacheSizeGB parameter at runtime:

db.adminCommand({setParameter:1, rocksdbRuntimeConfigCacheSizeGB: 10})
option --rocksdbCompression

Specifies the block compression algorithm for data collection. Possible values: none, snappy, zlib, lz4, lz4hc.

option --rocksdbMaxWriteMBPerSec
Default:1024 (1 GB/sec)

Specifies the maximum speed at which MongoRocks writes to storage (in megabytes per second). Decrease this value to reduce read latency spikes during compactions. However, reducing it too much might slow down writes.

To configure write speed dynamically, set the rocksdbRuntimeConfigMaxWriteMBPerSec parameter at runtime:

db.adminCommand({setParameter:1, rocksdbRuntimeConfigMaxWriteMBPerSec:30})
option --rocksdbCrashSafeCounters

Specifies whether to correct counters after a crash. Enabling this can affect write performance.

option --rocksdbCounters

Specifies whether to use advanced counters for MongoRocks. You can disable them to improve write performance.

option --rocksdbSingleDeleteIndex

This is an experimental feature. Enable it only if you know what you are doing.

Contact Us

For free technical help, visit the Percona Community Forum.
To report bugs or submit feature requests, open a JIRA ticket.
For paid support and managed or professional services, contact Percona Sales.