Blog IO

Yahoo Cloud Serving Benchmark for Key-Value Stores

A deep dive into the Yahoo Cloud Serving Benchmark to evaluate NoSQL database performance, identifying the strengths and weaknesses of RocksDB, LevelDB, and WiredTiger.

By
Ash Vardanian
Published
Oct 27, 2021

No matter what kind of DB you take, it will almost always be a set of key-value pairs collections. Every table in your SQL DB, every index, every document DB and Graph DB relies on a fast underlying Key-Value Store (KVS) Engine. Those are generally implemented as persistent tree datastructures, such as B-Trees, B+-Trees or LSM Trees. Having faster KVS is an essential prerequisite to building fast DBMS and is of insane value itself.

To compare those, we used the Yahoo Cloud Serving Benchmark (YCSB), which has been the industry standard since 2010. It randomly generates data on the fly and compares DBs in a broad variety of mixed read/write/scan workloads.

Reproduce Our Results

§ Trees All the Way Down

Take any database you know and peel off the query language, the network protocol and the replication. What remains is a KVS: a sorted mapping from binary keys to binary values, which can insert, find, update, delete and iterate in order. MySQL’s InnoDB keeps every table as a B+-Tree. MongoDB has been running on WiredTiger by default since version 3.2. Facebook put MySQL on top of RocksDB with MyRocks, and TiKV uses RocksDB to hold its data as well. So when a database is slow, the KVS underneath is the first suspect.

There are two main families of such engines, and they make opposite bets.

B-Trees and B+-Trees, dating back to 1970, keep data sorted in fixed-size pages on disk and update those pages in place. A lookup costs a few page reads, one per level of the tree. Every update, however, must rewrite at least a whole page, even if it only changes a hundred bytes, and random insertions split pages, leaving them partially empty.

Log-Structured Merge Trees (O’Neil et al., 1996) never update in place. They buffer writes in memory, flush them to disk as immutable sorted files, and merge those files in the background, a process called compaction. Writes become cheap and sequential, but a lookup may have to check several files, and old versions of a key occupy disk space until compaction catches up.

Researchers have formalized this trade-off as the RUM Conjecture (Athanassoulis et al., 2016): you can optimize for any two of Read overhead, Update overhead and Memory (or space) overhead, but not all three. Keep it in mind while reading the tables below - every engine is making that choice somewhere.

§ The Contenders

We compared five engines. Four of them are open-source and power a large chunk of the world’s data:

  • WiredTiger was written by the people behind Berkeley DB and acquired by MongoDB in 2014. It is a B-Tree engine with multi-version concurrency control, compression and checkpoints, and it is the default storage engine of MongoDB.
  • LevelDB was open-sourced by Google in 2011. It is a compact LSM Tree implementation, derived from the ideas behind Bigtable.
  • RocksDB is Facebook’s fork of LevelDB, heavily optimized for flash storage and multi-core servers, with multi-threaded compactions and countless tuning knobs.
  • LMDB is the Lightning Memory-Mapped Database from Symas, designed for OpenLDAP. It is a copy-on-write B+-Tree that maps the whole database file into memory, allowing a single writer and lock-free readers.

The fifth is UDisk, our own engine, here in its early v0.1 form. We won’t go into its internals today, but it doesn’t follow the textbook designs above, and it was built from day one for NVMe SSDs and many-core CPUs.

§ How YCSB Works

YCSB was introduced by Brian Cooper and colleagues at Yahoo! Research in the paper ”Benchmarking Cloud Serving Systems with YCSB” at SoCC 2010. Back then it compared Cassandra, HBase, PNUTS and sharded MySQL, but the workloads it defined are simple enough to apply to any system that can store and retrieve records by key.

Every run consists of two phases:

  1. The load phase, which we call “Initialization”, inserts all records into an empty database.
  2. The transaction phase then runs a mix of operations against the loaded data.

By default, a record has 10 fields of 100 bytes each, so roughly 1 KB per entry. That’s why a 100 MB dataset holds about 100,000 records, and a 1 GB dataset - about a million. Keys are not inserted in order: YCSB hashes the record number to produce the key, so even the load phase lands in random positions of the keyspace. That is a nightmare for B-Trees, which have to split pages all over the place, and a non-issue for LSM Trees, which sort everything in memory before writing.

Which keys are requested in the second phase is governed by a probability distribution: uniform, Zipfian, where a small set of keys is extremely popular, or “latest”, where the recently inserted keys are the hottest. The Zipfian generator scatters the popular keys across the keyspace, so the hot set isn’t one neat contiguous range that a single cached page could absorb.

The standard workloads are named by letters:

  • A: 50% reads, 50% updates. Update-heavy, like a session store.
  • B: 95% reads, 5% updates. Read-mostly, like photo tagging.
  • C: 100% reads. Read-only, like a cache or a user-profile lookup.
  • D: 95% reads, 5% inserts, favoring the latest records. Like a feed of status updates.
  • E: 95% short range scans, 5% inserts. Like threaded conversations.
  • F: 50% reads, 50% read-modify-writes.

In this first round, we focus on the two that stress the storage the most: the load phase and Workload A. The first is pure writes into a growing structure, the second is a mixed read-write stream over an existing one, and together they already say a lot.

Next to throughput, we report three more metrics for every engine:

  • CPUs: the average CPU utilization of the process, where 100% means one fully-busy hardware thread, including all the background flushing and compaction.
  • Avg MEM: the average memory the process consumed during the run.
  • Size on Disk: how much space the database occupies once the phase is over.

§ Setup

§ Device

  • CPU:
    • Model: 2x AMD Epyc 7302.
    • Cores: 32 (64 threads @ 3 Ghz).
  • RAM Space: 256 GB.
  • Disk Space: 2 TB.

The Epyc 7302 is a 16-core Zen 2 “Rome” part from 2019, with a 3.0 GHz base clock, 128 MB of L3 cache, eight channels of DDR4-3200 and PCIe 4.0 lanes for NVMe drives (AMD). Two of them give us 64 hardware threads - far more than any of the engines above can keep busy, as we will see.

Two things to keep in mind about this machine. First, it has two sockets, so a thread may be accessing memory attached to the other CPU, paying for an extra hop across the inter-socket link. Second, 256 GB of RAM is 256x larger than our largest dataset today, so the operating system can easily keep the entire database in its page cache. In other words, at these sizes, we are mostly measuring how efficiently each engine organizes data and uses the CPU, rather than how well it copes with a slow disk.

§ Working with 100 MB data

§ 100MB: Initialization

NameCPUsAvg MEMSize on DiskThroughput (ops/s)
WiredTiger312.4%106 MB131 MB31,306
RocksDB71.2%53 MB118 MB50,358
LevelDB105.8%54 MB118 MB58,153
LMDB89.8%100 MB215 MB32,396
UDisk303.4%57 MB116 MB81,877

UDisk loads the dataset 1.41x faster than the runner-up, LevelDB, and 2.62x faster than WiredTiger. The two LSM engines are the next best, exactly as the theory predicts for random-order insertions. The two B-Tree engines trail behind, and they pay in different currencies: LMDB ends up occupying 215 MB for a 100 MB dataset, as random insertions split its pages and leave them partially empty, while WiredTiger keeps the size in check at 131 MB but burns over three cores doing so.

§ 100MB: Read/Update (50/50)

NameCPUsAvg MEMSize on DiskThroughput (ops/s)
WiredTiger237.9%131 MB243 MB55,588
RocksDB85.5%67 MB177 MB45,379
LevelDB116.4%122 MB177 MB53,973
LMDB81.8%182 MB215 MB64,162
UDisk254.5%12 MB120 MB169,512

Here, the order flips. Reads are where B+-Trees shine, and LMDB becomes the fastest of the open-source engines. The LSM engines drop to the bottom, as every read may now have to consult several levels of files. UDisk leaves everyone far behind, running 2.64x faster than LMDB and 3.74x faster than RocksDB, while using the least memory of all - just 12 MB on average.

Now compare the “Size on Disk” column with the previous table. Both LSM engines grew by 50%, from 118 MB to 177 MB: updated values are appended as new versions, and the old ones wait for compaction. WiredTiger grew by 85%, from 131 MB to 243 MB: its checkpoints write modified pages to new locations, and the space of the old ones is only reused later, so its files tend to grow under updates. LMDB didn’t grow at all, reusing its freed pages, but it was already the largest. UDisk grew by just 3%, from 116 MB to 120 MB.

§ Working with 1 GB data

§ 1GB: Initialization

NameCPUsAvg MEMSize on DiskThroughput (ops/s)
WiredTiger408.4%192 MB1.32 GB35,338
RocksDB141.2%267 MB1.18 GB66,444
LevelDB167.8%216 MB1.40 GB55,298
LMDB99.8%989 MB2.06 GB40,408
UDisk480.4%126 MB1.16 GB132,744

With ten times more data, RocksDB overtakes LevelDB and becomes the runner-up, while using less CPU. Still, UDisk is 2.00x faster than RocksDB and 3.76x faster than WiredTiger. LMDB’s memory footprint grew almost tenfold, to 989 MB, and that’s an artifact of its design worth explaining. LMDB maps the whole file into its address space, so every page it touches is counted as its own memory. Engines that go through the OS page cache get part of their caching “off the books”, so the “Avg MEM” column is a lower bound for them, not an exact figure.

§ 1GB: Read/Update (50/50)

NameCPUsAvg MEMSize on DiskThroughput (ops/s)
WiredTiger295.9%223 MB2.44 GB46,670
RocksDB135.5%239 MB1.55 GB52,538
LevelDB182.4%135 MB1.59 GB55,688
LMDB96.8%1.99 GB2.07 GB77,656
UDisk469.5%70 MB1.19 GB225,632

This is the widest gap in today’s results: UDisk runs 2.91x faster than LMDB, 4.29x faster than RocksDB and 4.83x faster than WiredTiger, using the least RAM and the least disk space. WiredTiger’s file has again grown by 85% during the mixed workload, reaching 2.44 GB - more than twice the size of the data it holds. RocksDB grew by 31% and LevelDB by 14%, while UDisk added only 3%.

§ Reading Between the Lines

Let’s step back from individual tables.

UDisk leads everywhere, and the gap grows with size. Between the 100 MB and 1 GB runs, UDisk’s throughput grew by 62% on initialization and 33% on the mixed workload. Some of that growth, for every engine, is simply because longer runs amortize the start-up costs better, but UDisk benefited from it the most. WiredTiger, on the other hand, became 16% slower on the mixed workload as the data grew.

Space amplification is the hidden cost. Throughput numbers get the headlines, but a database that doubles in size after a few minutes of updates needs twice the SSDs, and every extra byte written shortens their life. At 1 GB, WiredTiger needed 2.44 GB and LMDB 2.07 GB, while UDisk stayed within 1.2x of the nominal dataset size in all four runs.

We use more cores, and we are not yet the most frugal per core. Divide throughput by CPU utilization, and you get the number of operations each busy core delivers per second. On the 1 GB mixed workload, that’s around 48K for UDisk, 39K for RocksDB, 31K for LevelDB and 16K for WiredTiger. But LMDB, with its single-writer design and zero-copy reads, gets 80K out of a single core. On initialization, RocksDB is the most efficient per core, at around 47K operations per core-second at 1 GB, while UDisk is at 28K. We are not ashamed of that. A server with 64 hardware threads that runs a database on one of them is mostly idle, and scaling across cores is exactly what the other engines struggle with. But it tells us where to look for the next optimizations.

§ What’s Next?

These results are an early snapshot, and we know their limits well:

  • 100 MB and 1 GB comfortably fit in RAM, so the SSD barely matters. Real datasets don’t fit, and that’s where storage engines are truly tested.
  • We only covered the load phase and Workload A. Read-only and read-latest workloads will tell a different part of the story.
  • Our dual-socket machine adds NUMA noise, which is hard to separate from the engines’ own behavior.
  • UDisk v0.1 is exactly that - a v0.1.

So, in the next part, we will scale the datasets further, limit how much of them every engine can keep in RAM, cover more workloads and move to a dedicated benchmarking machine. UDisk itself isn’t standing still either, and the next version should be noticeably faster.

There’s one more thing YCSB doesn’t cover: batches. In our Machine Learning pipelines, we almost never fetch a single key. We fetch hundreds of random keys at once to assemble a training batch, and a KVS that knows the whole batch in advance can schedule its disk accesses far better than one that sees the requests one by one. We’ll get back to that soon.