Skip to main content
RocksDB provides extensive configuration options to tune performance for different workloads. This guide covers the most important configuration settings.

Basic Configuration

DBOptions vs ColumnFamilyOptions

RocksDB has two main option classes:
  • DBOptions: Database-wide settings (threads, WAL, compaction)
  • ColumnFamilyOptions: Per-column family settings (memtable, compaction style, compression)
  • Options: Combines both DBOptions and ColumnFamilyOptions
#include "rocksdb/options.h"

using ROCKSDB_NAMESPACE::Options;
using ROCKSDB_NAMESPACE::DBOptions;
using ROCKSDB_NAMESPACE::ColumnFamilyOptions;

// For simple single-column-family databases
Options options;

// For multi-column-family databases
DBOptions db_options;
ColumnFamilyOptions cf_options;

Essential Settings

Create Database if Missing

options.create_if_missing = true;
Set this to true to automatically create a new database if it doesn’t exist.

Parallelism

Increase background threads for better performance on multi-core systems:
// Easiest way: let RocksDB decide based on CPU cores
options.IncreaseParallelism();

// Or manually configure
options.max_background_jobs = 8;  // Total background threads
IncreaseParallelism() sets max_background_jobs to the number of CPU cores and is recommended for most workloads.

Compaction Style

RocksDB offers multiple compaction strategies:
// Level-style compaction (default, recommended for most workloads)
options.OptimizeLevelStyleCompaction();

// Universal-style compaction (optimized for read-heavy workloads)
options.OptimizeUniversalStyleCompaction();

Level-Style Compaction

  • Better space amplification
  • Predictable performance
  • Default choice for most workloads

Universal-Style Compaction

  • Lower write amplification
  • Higher space amplification
  • Good for read-heavy workloads

Memory Configuration

Write Buffer

The write buffer (memtable) holds recent writes in memory:
// Size of each memtable (default: 64MB)
options.write_buffer_size = 64 << 20;  // 64MB

// Maximum number of memtables (default: 2)
options.max_write_buffer_number = 3;

// Total memory across all column families
options.db_write_buffer_size = 512 << 20;  // 512MB
Memory usage calculation:
Total = write_buffer_size × max_write_buffer_number × num_column_families
Larger write buffers improve write performance but increase memory usage and recovery time after crashes.

Block Cache

The block cache caches uncompressed data blocks:
#include "rocksdb/table.h"
#include "rocksdb/cache.h"

using ROCKSDB_NAMESPACE::BlockBasedTableOptions;
using ROCKSDB_NAMESPACE::NewLRUCache;

BlockBasedTableOptions table_options;
table_options.block_cache = NewLRUCache(512 << 20);  // 512MB cache

options.table_factory.reset(
    NewBlockBasedTableFactory(table_options));

Compression

Configure compression for different levels:
#include "rocksdb/compression_type.h"

using ROCKSDB_NAMESPACE::CompressionType;
using ROCKSDB_NAMESPACE::kSnappyCompression;
using ROCKSDB_NAMESPACE::kZSTD;

// Default compression for most levels
options.compression = kSnappyCompression;

// Stronger compression for bottommost level
options.bottommost_compression = kZSTD;

// Per-level compression
options.compression_per_level = {
    kNoCompression,      // Level 0
    kNoCompression,      // Level 1
    kSnappyCompression,  // Level 2
    kSnappyCompression,  // Level 3
    kZSTD,               // Level 4
    kZSTD,               // Level 5
    kZSTD                // Level 6
};
  • Fast compression/decompression
  • Moderate compression ratio
  • Recommended for most levels

Write Options

Synchronous Writes

Control durability vs performance tradeoff:
using ROCKSDB_NAMESPACE::WriteOptions;

WriteOptions write_options;

// Synchronous write (durable but slower)
write_options.sync = true;
db->Put(write_options, "key", "value");

// Asynchronous write (faster but less durable)
write_options.sync = false;  // default
db->Put(write_options, "key", "value");
With sync = false, recent writes may be lost in case of a system crash. Use sync = true for critical data or implement periodic manual syncing with DB::SyncWAL().

Disable WAL

For ephemeral data or when durability is not required:
write_options.disableWAL = true;
db->Put(write_options, "key", "value");

Read Options

Read Caching

using ROCKSDB_NAMESPACE::ReadOptions;

ReadOptions read_options;

// Skip block cache for this read (useful for large scans)
read_options.fill_cache = false;

// Verify checksums
read_options.verify_checksums = true;

Snapshot Reads

const Snapshot* snapshot = db->GetSnapshot();
ReadOptions read_options;
read_options.snapshot = snapshot;

// Read from snapshot
std::string value;
db->Get(read_options, "key", &value);

// Release snapshot when done
db->ReleaseSnapshot(snapshot);

Performance Tuning

File Opening

// Keep all files open for faster access (-1 = unlimited)
options.max_open_files = -1;

// Number of threads for opening files
options.max_file_opening_threads = 16;

Compaction Triggers

// Trigger level-0 compaction when this many files exist
options.level0_file_num_compaction_trigger = 4;

// Maximum bytes for level-1
options.max_bytes_for_level_base = 256 << 20;  // 256MB

// Multiplier for each level
options.max_bytes_for_level_multiplier = 10;

Rate Limiting

Control I/O rate for compaction and flush:
#include "rocksdb/rate_limiter.h"

using ROCKSDB_NAMESPACE::NewGenericRateLimiter;

// Limit to 100 MB/s
options.rate_limiter.reset(
    NewGenericRateLimiter(
        100 << 20  // bytes_per_sec
    ));

Configuration Templates

High Write Throughput

Options GetHighWriteOptions() {
    Options options;
    
    // Large write buffers
    options.write_buffer_size = 128 << 20;  // 128MB
    options.max_write_buffer_number = 4;
    
    // More background jobs
    options.IncreaseParallelism(16);
    
    // Level compaction
    options.OptimizeLevelStyleCompaction(1024 << 20);  // 1GB memtable budget
    
    // Fast compression
    options.compression = CompressionType::kLZ4Compression;
    
    return options;
}

Low Latency Reads

Options GetLowLatencyOptions() {
    Options options;
    
    // Keep all files open
    options.max_open_files = -1;
    
    // Large block cache
    BlockBasedTableOptions table_options;
    table_options.block_cache = NewLRUCache(2048 << 20);  // 2GB
    options.table_factory.reset(
        NewBlockBasedTableFactory(table_options));
    
    // Enable bloom filters
    table_options.filter_policy.reset(
        NewBloomFilterPolicy(10, false));
    
    return options;
}

Small Database (< 1GB)

Options GetSmallDbOptions() {
    Options options;
    options.OptimizeForSmallDb();
    return options;
}

Configuration Best Practices

1

Start with defaults

Use IncreaseParallelism() and OptimizeLevelStyleCompaction() for good initial performance.
2

Measure performance

Use db_bench or your application’s workload to establish baseline performance.
3

Tune incrementally

Change one setting at a time and measure the impact.
4

Monitor resources

Watch memory usage, CPU utilization, and I/O patterns.

Next Steps

Performance Tuning

Deep dive into performance optimization techniques

Basic Operations

Learn basic CRUD operations

Build docs developers (and LLMs) love