# Unbranding and Extending the Yahoo Cloud Serving Benchmark

> Introducing the Unum Cloud Serving Benchmark (UCSB), a modernized and extended version of YCSB designed to rigorously evaluate the performance of next-generation storage engines.

[Blog](https://www.unum.cloud/blog.md) [IO](https://www.unum.cloud/blog?tag=IO)

Introducing the Unum Cloud Serving Benchmark (UCSB), a modernized and extended version of YCSB designed to rigorously evaluate the performance of next-generation storage engines.

- By

  Ash Vardanian

- Published

  Mar 22, 2022

2021 was terrific for DataBase Management Software and startups in general. While classical SQL is shrinking, the data-management market as a whole is booming at 17% [CAGR](https://www.investopedia.com/investing/compound-annual-growth-rate-what-you-should-know/) and will reach $150 Billion in 2026, according to Gartner. That and the hype allowed dozens of DBMS startups to raise more capital last year alone than in their entire preceding decade-long history. For 13 companies in our previous extended comparison, it meant [**swallowing $4.5 Billion**](https://www.unum.cloud/blog/dbms-startups.md#the-new-cohort-the-wannabees) of VC money.

---

With so many players and such high-stakes, there must have been an evaluation metric - a way to sort out the wheat from the chaff. There are two:

- [**YCSB**](https://github.com/brianfrankcooper/YCSB): Yahoo Cloud Serving Benchmark,
- [**TPC**](https://www.tpc.org/tpch): Transaction processing Performance Council.

Those cover different workloads. The first is for Key-Value Stores (KVS), and the second is for mostly SQL DBMS systems, built on top KVS. So if you are building a DBMS, it makes sense to use both, one for the persistent data structures and one for the higher-level logic. As expected, we use both and outperform other players in both, but we will skip the TPC for now.

With around 4K ⭐ on GitHub, YCSB is the popular option. In the past, we [have used it extensively](https://www.unum.cloud/blog/ycsb-udisk.md#how-we-benchmark-ycsb), and our previous article covers a lot we can skip this time:

- How 🦄 are built on top of open-source RocksDB and WiredTiger? [jump](https://www.unum.cloud/blog/ycsb-udisk.md#who-is-against-us)
- The liquid-cooled 👹 monster hardware we use for benchmarking: [here](https://www.unum.cloud/blog/ycsb-udisk.md#our-toys)
- 100 MB, 1 GB, 10 GB and 100 GB results [here](https://www.unum.cloud/blog/ycsb-udisk.md#our-results)

As we have previously promised, we are back with expanded datasets and new optimizations, but they are not just inside UDisk! After careful evaluation, we decided to rewrite the original YCSB package, extending and updating it along the way! Oh, and it’s open-source - check it on [GitHub](https://github.com/unum-cloud/ucsb) 🤗 If you just want to see the [**new results - here you go**](#results-). Spoiler:

Benchmark duration

LevelDB 39.3 hours

RocksDB 12.1 hours

WiredTiger 8.3 hours

UDisk 5 hours

---

Overall, **designing new benchmarks isn’t considered a good tone**. Especially if you are going to measure your own (hopefully upcoming) product, it makes it too easy to prioritize the operations you are good at and lessen the others. So we preserved the principal part of YCSB - its canonical random key generators and the three most misleading letters of the name 😅

We will talk about many things, including:

- A benchmark for High-Performance Software must be High-Performance Software in itself.
- Tracking hardware resource usage from a separate process, Valgrind style.
- ACID guarantees and multithreading in Key-Value Stores.
- Cost of running a DBMS in a Docker container.
- SLC vs MLC vs TLC relation on DBMS speed.
- 1 TB results for RocksDB, UDisk and the others.

If it sounds interesting, let’s jump in!

## Performance is a Feature

The original YCSB was published over 10 years ago and targeted isolated DBMS applications. Those run in a separate process, in a different address space and communicate through sockets, often via plain-text commands. It was simple enough to be understandable and diverse enough to be broadly applicable, so it took off. People ~~like us~~ have applied it to systems that are much more “low-level” than, let’s say [Amazon DynamoDB](https://aws.amazon.com/dynamodb/), [Apache Cassandra](https://gitbox.apache.org/repos/asf/cassandra.git) or [ElasticSearch](https://www.elastic.co/enterprise-search/).

In those 10 years, the hardware has changed. Let’s compare AMD CPUs from those two eras:

| | 2012 | 2022 |
| - | - | - |
| Top CPU Model | Athlon II X4 651K | EPYC 7773X |
| Lithography | 32 nm | 7 nm |
| TDP | 100 Watt | 280 Watt |
| Core Count | 4 | 64 |
| Clock Frequency | 3.0 GHz | 2.2 - 3.5 GHz |
| Cache Size | 4 MB | 804 MB |
| PCIe | 20x Gen2 | 128x Gen4 |
| PCIe Bandwidth | 10 GB/s | 256 GB/s |
| RAM | 2x channel DDR3-1866 | 8x channel DDR4-3200 |
| RAM Bandwidth | 30 GB/s | 204 GB/s |

In reality, [not all of that theoretical bandwidth is always available](https://ashvardanian.com/posts/cuda-parallel-reductions), but I guess you don’t need [cpu-world.com](https://www.cpu-world.com/CPUs/K10/AMD-Athlon%20II%20X4%20651K%20-%20AD651KWNZ43GX%20\(AD651KWNGXBOX\).html) to agree that CPUs changed!

The same [applies to SSDs](https://ashvardanian.com/posts/server-supercycle/#persistent-storage) and GPUs. Storage-level technologies are heavily underutilizing the latter. The software must harness all of that speed and parallelism, but it’s only feasible in low-level languages.

### Java & Java-like

All performant KVS are implemented in C++ and YCSB is implemented in Java. This means, that you would need some form of a “Foreign Function Interface” to interact with the KVS. This immediately adds unnecessary work for our CPU, but it’s a minor problem compared to rest.

#### § Example 1

Every language and its ecosystem has different priorities. Java focuses on the simplicity of development, while C++ trades it for higher performance.

```java
private static String getRowKey(String db, String table, String key) {
    return db + ":" + table + ":" + key;
}
```

The above snippet is [from the Apples & SnowFlakes `FoundationDB` adapter](https://github.com/brianfrankcooper/YCSB/blob/ce3eb9ce51c84ee9e236998cdd2cefaeb96798a8/foundationdb/src/main/java/site/ycsb/db/foundationdb/FoundationDBClient.java#L100) inside YCSB, but it’s identical across the entire repo. It’s responsible for generating keys for queries. Here is what a modern recommended C++ version would look like:

```cpp
auto get_row_key(std::string_view db, std::string_view table, std::string_view key) {
    return std::format("{}:{}:{}", db, table, key);
}
```

> My entire Java experience is about 1 week long and happened over 10 years ago. So take the next section with a grain of salt.

From Java 7 onwards, the [Java String Pool lives in the Heap space](https://www.baeldung.com/java-string-pool), which is garbage collected by the JVM. This code will produce a `StringBuilder`, a heap-allocated array of pointers to heap-allocated strings, later materializing in the final concatenated `String`. Of course, on-heap again. And if we know something about High-Performance Computing, the heap is expensive, but together with Garbage Collection and multithreading, it becomes completely intolerable. The same applies to the C++ version. Yes, we are doing only 1 allocation there, but it is also too slow to be called HPC. We need to replace `std::format` with [`std::format_to`](https://en.cppreference.com/w/cpp/utility/format/format_to) and export the result into a reusable buffer.

#### § Example 2

If one example is not enough, below is [the code snippet](https://github.com/brianfrankcooper/YCSB/blob/ce3eb9ce51c84ee9e236998cdd2cefaeb96798a8/core/src/main/java/site/ycsb/generator/ZipfianGenerator.java#L250), which produces random integers before packing them into `String key`.

```java
long nextLong(long itemcount) {
    // from "Quickly Generating Billion-Record Synthetic Databases", Jim Gray et al, SIGMOD 1994
    if (itemcount != countforzeta) {
        synchronized (this) {
            if (itemcount > countforzeta) {
                ...
            else
                ...
        }
    }

    double u = ThreadLocalRandom.current().nextDouble();
    double uz = u * zetan;

    if (uz < 1.0)
        return base;
    if (uz < 1.0 + Math.pow(0.5, theta))
        return base + 1;

    long ret = base + (long) ((itemcount) * Math.pow(eta * u - eta + 1, alpha));
    setLastValue(ret);
    return ret;
}
```

To generate a `long`, we are doing numerous operations on `double` s, by far the most computationally expensive numeric type on modern computers (except for integer division). Aside from that, this PRNG contains 4x `if` statements and `synchronized (this)` mutex. Creating random integers for most distributions is generally within 50 CPU cycles or 10 nanoseconds. In this implementation, every `if` branch may cost that much, and the mutex may cost orders of magnitude more!

It looks like a severe systemic problem to me, so we have searched for C/C++ ports.

### Existing C++ Ports

We are not the first to consider porting:

- [basicthinker/YCSB-C](https://github.com/basicthinker/YCSB-C).
- [ls4154/YCSB-cpp](https://github.com/ls4154/YCSB-cpp).

Those implementations aren’t popular. They solve the first issue, of not needing FFI, to call LevelDB, RocksDB or other C++ persistent data structure libs, but aren’t solving the other problems.

```cpp
inline uint64_t ZipfianGenerator::Next(uint64_t num) {
    assert(num >= 2 && num < kMaxNumItems);
    std::lock_guard<std::mutex> lock(mutex_);

    if (num > n_for_zeta_) {
        RaiseZeta(num);
        eta_ = Eta();
    }

    double u = utils::RandomDouble();
    double uz = u * zeta_n_;

    if (uz < 1.0)
        return last_value_ = 0;
    if (uz < 1.0 + std::pow(0.5, theta_))
        return last_value_ = 1;
    return last_value_ = base_ + num * std::pow(eta_ * u - eta_ + 1, alpha_);
}
```

Again, we are generating random numbers under a `mutex`, which in turn calls a `static std::default_random_engine` [here](https://github.com/basicthinker/YCSB-C/blob/6475c7a5c3c7b229224ce5ca3332a58c994b8a09/core/utils.h#L38). Even the most straightforward functions cause [expensive on-heap copies and throw exceptions](https://github.com/basicthinker/YCSB-C/blob/6475c7a5c3c7b229224ce5ca3332a58c994b8a09/core/utils.h#L60):

```cpp
inline bool StrToBool(std::string str) {
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    if (str == "true" || str == "1") {
        return true;
    } else if (str == "false" || str == "0") {
        return false;
    } else {
        throw Exception("Invalid bool string: " + str);
    }
}
```

Being a step in the right direction, it causes `malloc`-backed heap-allocations in [every](https://github.com/basicthinker/YCSB-C/blob/6475c7a5c3c7b229224ce5ca3332a58c994b8a09/core/db.h#L19) function interface. Exceptions, for reference, are banned in half of the companies using C++, [including Google](https://www.quora.com/Why-are-exceptions-banned-in-Google%E2%80%99s-C++-code).

### Being Future-Proof

In 2023 we will be looking at up to 2 Million Random 4KB Read operations per second on the next-gen Intel Optane. With just 24 drives in a 2U chassis, we will be getting 50 MOps/s or 200 GB/s. Far more than your memory system can sustain with copies, let alone your heap allocator. Even the Linux kernel is expected to choke at 10 MOps/s, let alone JVM and most software ever written. We started by using older C++ ports with wrappers for RocksDB, LevelDB and LMDB. Then:

- We added a WiredTiger backend, which is the foundation of MongoDB.
- We normalized and extended the configuration files.
- We removed a few more of those Java-ish inefficiencies.

It was easier to throw away all except a couple of classes and rebuild the rest using the Google Benchmark suite by that time.

> _In every complicated situation start from scratch!_
>
> Ancient C++ Wisdom

## New Workloads

Before getting into the tedious intricacies, let’s spice things up a little. YCSB had 6 mixed workloads, [from A to F](https://github.com/brianfrankcooper/YCSB/tree/master/workloads), plus initialization. Those mostly do Read+Update, Read+Insert, Read-Only and Write-Only operations.

Good, but not enough. Today State-of-the-Art Language Models are trained on CommonCrawl samples. That dataset contains 300 TB worth of HTML. It’s just one of many datasets used to solve one of many AI problems.

Data size

WSJ 0.03 B words

Wikipedia 2.5 B words

OpenWebText 8.5 B words

C4 35 B words

Model size

GPT 0.1 B parameters

BERT-Large 0.3 B parameters

GPT2-1.5B 1.5 B parameters

RoBERTa 0.4 B parameters

XLNet 0.4 B parameters

ELECTRA-1.75M 0.3 B parameters

MegatronLM 8.3 B parameters

T5-11B 11 B parameters

Turing-NLG 17 B parameters

Training volume

GPT 0.03 T tokens

BERT-Large 0.1 T tokens

GPT2-1.5B 0.5 T tokens

RoBERTa 2.1 T tokens

XLNet 2.1 T tokens

ELECTRA-1.75M 1.8 T tokens

MegatronLM 0.2 T tokens

T5-11B 1 T tokens

Turing-NLG 0.2 T tokens

In NLP, everything is big and getting bigger. Data from AI21 Labs.

To work with such volumes, we wanted more “verbs” than just “set” and “get”, but we had to trim some fat to keep it brief. Instead of 7 initial workloads, we have 8:

- [∅](#0-bulk-initialization): imports monotonically increasing keys 🔄
- [A](#a-50-random-reads--50-random-updates): 50% reads + 50% updates, all random
- [C](#c-100-random-reads): reads, all random
- [D](#d-95-random-reads--5-random-inserts): 95% reads + 5% inserts, all random
- [E](#e-range-select): range scan 🔄
- [✗](#x-batch-reads): batch read 🆕
- [Y](#y-batch-insert): batch insert 🆕
- [Z](#z-scan): scans 🆕

The **∅** was previously implemented as one-by-one inserts, but some KVS support the external construction of its internal representation files. The **E** was [previously](https://github.com/brianfrankcooper/YCSB/blob/master/workloads/workloade) mixed with 5% insertions.

## How We Configured DBs?

We concentrated on benchmarking the following state-of-the-art Key-Value Stores:

1. [WiredTiger](https://github.com/wiredtiger/wiredtiger). Version 10.0.0.
2. [LevelDB](https://github.com/google/leveldb). Version 1.23.
3. [RocksDB](https://github.com/facebook/rocksdb). Version 6.29.3 (fork of LevelDB).
4. UDisk. Version 0.2.
5. [LMDB](https://www.symas.com/lmdb) is also supported, but it was too slow to include into chart. Version 0.9.29.

UDisk is currently in a pre-release form, but we use it internally in a broad set of configurations on terbayte scale collections.

### Memory Limits

Every KVS supports setting a RAM limit, which we choose to be 10% or, more commonly, 5% of the overall database size. It’s a typical server setting, as you generally have at least 10x less RAM than disk space. Desktop setups are even less balanced than that. Many users have just 16 GB of RAM and a 1 TB SSD, meaning a 60x gap.

### Compression

None of the DBs relies on custom compression. They all reuse similar sets of open-source compression libs, like [Snappy](https://github.com/google/snappy) and [Zlib](https://github.com/madler/zlib). We want to benchmark the DBs and not the compression, so we disabled it across all deployments.

### Disk Representation

RocksDB famously has [multiple file formats](https://github.com/EighteenZi/rocksdb_wiki/blob/master/A-Tutorial-of-RocksDB-SST-formats.md). By default, it uses the [`BlockBasedTable`](https://github.com/facebook/rocksdb/wiki/Rocksdb-BlockBasedTable-Format) for SSTs, but also provides the [`PlainTable`](https://github.com/facebook/rocksdb/wiki/PlainTable-Format) and `BlobDB` with separate files for keys and values. The latter ones were unstable and feature-incomplete, so we took the default.

The configuration files for RocksDB, for example, [contain **over a hundred lines**](https://github.com/ls4154/YCSB-cpp/blob/master/rocksdb/options.ini). It includes settings for the Write-Ahead-Log, flushing guarantees, Skip-List Capacity, file sizes, LSM street growth factors, Bloom-filter specs and more. RocksDB has the biggest codebase and is probably the hardest to read, understand and maintain. The `cloc` utility measured it’s codebase to be ≈ 650,000 lines of code. Removing blanks and noise here is what we get:

| | LevelDB | RocksDB | WiredTiger | UDisk |
| - | - | - | - | - |
| Code & Tests | ≈ 20 K | ≈ 375 K | ≈ 130 K | ≈ 19 K |
| Comments | ≈ 4 K | ≈ 107 K | ≈ 95 K | ≈ 3 K |
| Wrappers & Other | ≈ 3 K | ≈ 90 K | ≈ 85 K | ≈ 1 K |

> Even though UDisk is smaller than LevelDB, it’s fair to say that they have the most readable codebase. This, however, comes at the cost of performance.

RocksDB truly stands out in its complexity. So we tried to stick to default configs with [minimal changes](https://github.com/unum-cloud/ucsb/blob/main/bench/configs/rocksdb/1TB.cfg).

### Supported Verbs

KVS variants differ in supported operations. Many are not available natively, so they were simulated using the fastest available functionality.

| | WiredTiger | LevelDB | RocksDB | UDisk |
| - | - | - | - | - |
| Insert | Implemented | Implemented | Implemented | Implemented |
| Select | Implemented | Implemented | Implemented | Implemented |
| Remove | Implemented | Implemented | Implemented | Implemented |
| Scan | Implemented | Implemented | Implemented | Implemented |
| Initialize | Implemented | Not intended | Implemented | Implemented |
| Batch Select | Not intended | Not intended | Implemented | Implemented |
| Batch Insert | Not intended | Implemented | Implemented | Implemented |

There is also asymmetry elsewhere:

- WiredTiger supports fixed size integer keys.
- LevelDB only supports variable length keys and values.
- RocksDB has minimal support for [`fixed_key_len`](https://cs.github.com/facebook/rocksdb?q=fixed_key_len), incompatiable with `BlockBasedTable`.
- UDisk supports both fixed size keys and values.

Just like YCSB, we use 8-byte integer keys and 1000-byte values. Both WiredTiger and UDisk were configured to natively use integer keys. RocksDB wrapper reverts the order of bytes in keys to use the native comparator. None of the DBs was set to use fixed size values, as only UDisk supports that.

## Caveats We Faced

If you use Google Benchmark, you know about its [bunch of nifty tricks](https://github.com/google/benchmark/blob/main/docs/user_guide.md), like `DoNotOptimize` or the automatic resolution of the number of iterations at runtime. It’s widespread in micro-benchmarking, but it begs for extensions when you start profiling a DBMS. The ones shipped with UCSB spawn a sibling process that samples usage statistics from the OS. Like `valgrind`, we read from [`/proc/*` files](https://man7.org/linux/man-pages/man5/proc.5.html) and aggregate stats like SSD I/O and overall RAM usage.

### Durability vs Speed

#### § Unlike humans, [ACID](https://en.wikipedia.org/wiki/ACID) is one of the best things that can happen to DBMS 😁

Like all good things, ACID is unreachable, because of at least one property - Durability. Absolute Durability is practically impossible and high Durability is expensive.

All high-performance DBs are designed as [Log Structured Merge Trees](https://en.wikipedia.org/wiki/Log-structured_merge-tree). It’s a design that essentially bans in-place file overwrites. Instead, it builds layers of immutable files arranged in a Tree-like order. The problem is that until you have enough content to populate an entire top-level file, you keep data in RAM - in structures often called `MemTable` s.

Log-structured merge tree compaction. Six overlapping files on level 0 are merged pairwise into three sorted files on level 1, which are merged into one larger sorted file on level 2.

Compaction continues creating fewer, larger and larger files.

If the lights go off, volatile memory will be discarded. So a copy of every incoming write is generally appended to a Write-Ahead-Log (WAL). Two problems here:

1. You can’t have a full write confirmation before appending to WAL. It’s still a write to disk. A system call. A context switch to kernel space. Want to avoid it with [`io_uring`](https://unixism.net/loti/what_is_io_uring.html) or [`SPDK`](https://spdk.io/), then be ready to change all the above logic to work in an async manner, but fast enough not to create a new bottleneck. Hint: [`std::async`](https://en.cppreference.com/w/cpp/thread/async) will not cut it.
2. WAL is functionally stepping on the toes of a higher-level logic. Every wrapping DBMS, generally implements such mechanisms, so they disable WAL in KVS, to avoid extra stalls and replication. Example: [Yugabyte is a port](https://blog.yugabyte.com/how-we-built-a-high-performance-document-store-on-rocksdb/) of Postgres to RocksDB and disables the embedded WAL.

We generally disable WAL and benchmark the core. Still, you can tweak all of that in the UCSB configuration files yourself.

Furthermore, as widely discussed, [flushing the data still may not guarantee it’s preservation on your SSD](https://twitter.com/xenadu02/status/1495693475584557056?s=20\&t=eG2cIbzMg_rTq379EkkHMQ). So pick you ~~poison~~ hardware wisely and tune your benchmarks cautiously.

### Strict vs Flexible RAM Limits

When users specify a RAM limit for a KVS, they expect all of the required in-memory state to fit into that many bytes. It would be too obvious for modern software, so here is one more problem.

Fast I/O is hard. The faster you want it, the more abstractions you will need to replace.

Four ways an application reaches an NVMe drive. libc passes 4 layers: Userspace buffers, Page cache, Block I/O layer, Device. mmap passes 3 layers: Page cache, Block I/O layer, Device. mmap + O_DIRECT passes 2 layers: Block I/O layer, Device. SPDK passes 1 layer: Device.

Every layer between the application and the drive is another copy, lock or context switch. O_DIRECT skips the page cache; SPDK talks to the device itself.

Generally, OS keeps copies of the requested pages in RAM cache. To avoid it, enable [`O_DIRECT`](https://man7.org/linux/man-pages/man2/open.2.html). It will slow down the app and would require some more engineering. For one, all the disk I/O will have to be aligned to page sizes, [generally 4KB](https://docs.pmem.io/persistent-memory/getting-started-guide/creating-development-environments/linux-environments/advanced-topics/i-o-alignment-considerations), which includes both the address in the file and the address in the userspace buffers. Split-loads should also be managed with an extra code on your side. So most KVS (except for UDisk, of course 😂) solutions don’t bother implementing very fast I/O, like `SPDK`. In that case, they can’t even know how much RAM the underlying OS has reserved for them. So we have to configure them carefully and, ideally, add external constraints:

```sh
systemd-run --scope -p MemoryLimit=100M /path/ucsb
```

Now a question. Let’s say you want to [`mmap`](https://man7.org/linux/man-pages/man2/mmap.2.html) files and be done. Anyways, Linux can do a far better job at managing caches than most DBs. In that case - the memory usage will always be very high but within the limits of that process. As soon as we near the limit - the OS will drop the old caches. Is it better to use the least RAM or the most RAM until the limit?

For our cloud-first offering, we will favour the second option. It will give the users the most value for their money on single-purpose instances.

Furthermore, we allow and enable ”**Workload Isolation**” in UCSB by default. It will create a separate process and a separate address space for each workload of each DB. Between this, we flush the whole system. The caches filled during insertions benchmarks, will be invalidated before the reads begin. This will make the numbers more reliable but limits concurrent benchmarks to one.

> In one of the next articles we will write about the in-hardware Memory Management Unit and the Linux `mmap` implementation, so [subscribe](https://bit.ly/3mG4q0f) 🤗

### Dataset Size & NAND Modes

Large capacity SSDs store multiple bits per cell. If you are buying a Quad Level Cell SSD, you expect each of them to store 4 bits of relevant information. That may be a false expectation.

Four kinds of NAND flash cells. SLC stores 1 bit per cell in 2 levels and lasts 100K program/erase cycles. MLC stores 2 bits per cell in 4 levels and lasts 10K program/erase cycles. TLC stores 3 bits per cell in 8 levels and lasts 3K program/erase cycles. QLC stores 4 bits per cell in 16 levels and lasts 1K program/erase cycles.

Every extra bit doubles the charge levels one cell must tell apart, and cuts how many program/erase (P/E) cycles it survives.

The SSD can switch to SLC mode during intensive writes, where IO is faster, especially if a lot of space is available. In the case of an 8 TB SSD, before we reach 2 TB used space, all [NAND](https://en.wikipedia.org/wiki/Flash_memory) arrays can, in theory, be populated with just one relevant bit.

| | SLC | eMLC | MLC | TLC |
| - | - | - | - | - |
| Bits per cell | 1 | 2 | 2+ | 3-4 |
| P/E cycles | 90,000-100,000 | 20,000-30,000 | 10,000 | 3,000-5,000 |
| Price, speed, endurance | highest | | | lowest |
| Power consumption, cell density | lowest | | | highest |

If you are benchmarking the DBMS, not the SSD, ensure that you did all benchmarks within the same mode. In our case for a 1 TB workload on 8 TB drives, it’s either:

- starting with an empty drive,
- starting with an 80% full drive.

## Listing the Knobs

As you see, there is a lot to take into account, and everyone may be interested in a different setting. To sum things up, here is a functionality comparison between YCSB and UCSB.

| | Present in YCSB | Present in UCSB |
| - | - | - |
| Size of the dataset | Implemented | Implemented |
| DB configuration files | Implemented | Implemented |
| Workload specifications | Implemented | Implemented |
| Tracking hardware usage | Not intended | Implemented |
| Workload Isolation | Not intended | Implemented |
| Concurrency | Not intended | Implemented |
| Batch Operations | Not intended | Implemented |
| Bulk Operations | Not intended | Implemented |
| Support of Transactions | Not intended | Implemented |

There is too much control-flow to tune, so instead of 1,000 CLI arguments, we organize them into a [`run.py`](https://github.com/unum-cloud/ucsb/blob/main/run.py) Python script.

## Results 💥

And then, what’s the point of writing a benchmark if you don’t get to run it! One of the comments to our previous post was wondering, why run small workloads on big machines? The answer is - to upscale the experiment within the same environment and analyze its scaling behaviour.

How we set the Knobs this time:

- Transactions: ❌
- Concurrent: ❌
- Workload Isolation: ✅
- Sizes: 10 GB, 100 GB, 1 TB.

Here is how long one iteration of the benchmark takes:

- 10 GB: 42 minutes.
- 100 GB: 5 hours, 54 minutes.
- 1 TB: 2 days, 10 hours, 6 minutes.

Totalling at 2 days, 16 hours, 42 minutes. Benchmark duration by DBMS:

- WiredTiger: 8 hours, 16 minutes.
- LevelDB: 1 day, 15 hours, 19 minutes.
- RocksDB: 12 hours, 8 minutes.
- UDisk: 4 hours, 59 minutes.

We rerun those benchmarks many times with different settings. Every DBMS received its own 8 TB Samsung SSD, empty. Later we will avoid slower DBs and will focus on bigger setups, that don’t fit on one SSD:

- Transactions: ✅
- Concurrent: ✅
- Workload Isolation: ✅
- Sizes: 10 TB, 50 TB.

The 🥈 and 🥉 place often change, but the 🥇 leader remains constant. With performance difference often being 2x - 5x against the second-best solution in each workload. [Sometimes](#0-bulk-initialization), this speed comes at the cost of using more RAM, but [not always](#x-batch-reads). If the gap between 🥇 and 🥈 is bigger than the gap within any consecutive pair of entries in the leaderboard - we mark the result with 🏅.

### 0: Bulk Initialization

Initializing the KVS is done via monotonically ascending keys. The original YCSB initialization always happens one key at a time. We went one step further and implemented a bulk insert functionality. When possible, it constructs big DB-compatible files externally and then submits them into KVS. [WiredTiger](https://source.wiredtiger.com/10.0.0/tune_bulk_load.html), [RocksDB](http://rocksdb.org/blog/2017/02/17/bulkoad-ingest-sst-file.html) and UDisk natively support that, but LevelDB doesn’t.

Initialized Keys per Second

| | WiredTiger ⊃ MongoDB | LevelDB ⊃ Google | RocksDB ⊃ Facebook | UDisk ⊃ Unum |
| - | - | - | - | - |
| 10 GB | 908,461.44 | 115,077.68 | 375,327.61 | 2,067,638.65 |
| 100 GB | 1,116,918.89 | 53,648.3 | 408,371.84 | 2,172,797.48 |
| 1 TB | 1,109,809.32 | 30,191.98 | 385,250.42 | 2,189,283.93 |

This is vastly faster than inserting data one by one and even in [batches](#y-batch-insert)! Think of it as your zero-to-hero time: how fast can you import all your `Parquet` files from S3 buckets, before starting working with them.

| Brand | CPU usage | RAM Usage | Disk Usage | Speed |
| - | - | - | - | - |
| WiredTiger ⊃ MongoDB | 1.00 cores | 3.99 GiB | 989.77 GiB | 1.1M 🥈 |
| LevelDB ⊃ Google | 0.99 cores | 904.12 MiB | 984.19 GiB | 30.2K |
| RocksDB ⊃ Facebook | 0.89 cores | 2.65 GiB | 976.27 GiB | 385.3K 🥉 |
| UDisk ⊃ Unum | 1.00 cores | 3.90 GiB | 968.58 GiB | 2.2M 🥇🏅 |

### A: 50% Random Reads + 50% Random Updates

50:50 Mixed Requests per Second

| | WiredTiger ⊃ MongoDB | LevelDB ⊃ Google | RocksDB ⊃ Facebook | UDisk ⊃ Unum |
| - | - | - | - | - |
| 10 GB | 67,052.35 | 51,994.59 | 49,822.51 | 131,588.98 |
| 100 GB | 76,890.26 | 69,466.28 | 78,579.18 | 142,664.98 |
| 1 TB | 101,102 | 115,240.65 | 86,825.51 | 197,338.71 |

Every operation is a random single-element operation. Half of them are reads, and half are updates for existing keys.

| Brand | CPU usage | RAM Usage | Disk Usage | Speed |
| - | - | - | - | - |
| WiredTiger ⊃ MongoDB | 3.19 cores | 23.67 GiB | 1.02 TiB | 101.1K 🥉 |
| LevelDB ⊃ Google | 1.78 cores | 2.54 GiB | 989.39 GiB | 115.2K 🥈 |
| RocksDB ⊃ Facebook | 1.50 cores | 4.95 GiB | 978.55 GiB | 86.8K |
| UDisk ⊃ Unum | 1.00 cores | 10.01 GiB | 976.32 GiB | 197.3K 🥇🏅 |

### C: 100% Random Reads

Read Requests per Second

| | WiredTiger ⊃ MongoDB | LevelDB ⊃ Google | RocksDB ⊃ Facebook | UDisk ⊃ Unum |
| - | - | - | - | - |
| 10 GB | 93,979.43 | 50,470.09 | 72,655.74 | 156,756.5 |
| 100 GB | 106,734.67 | 32,655.08 | 153,095.24 | 166,620.71 |
| 1 TB | 146,596.86 | 30,580.54 | 160,715.63 | 175,737.23 |

Again, not a particularly interesting benchmark, but a common case when dealing with poorly optimized software. Use the [batched](#x-batch-reads) approach whenever possible.

| Brand | CPU usage | RAM Usage | Disk Usage | Speed |
| - | - | - | - | - |
| WiredTiger ⊃ MongoDB | 1.39 cores | 17.43 GiB | 989.77 GiB | 146.6K 🥉 |
| LevelDB ⊃ Google | 1.12 cores | 105.41 MiB | 984.40 GiB | 30.6K |
| RocksDB ⊃ Facebook | 0.97 cores | 4.72 GiB | 976.27 GiB | 160.7K 🥈 |
| UDisk ⊃ Unum | 0.98 cores | 1.42 GiB | 972.30 GiB | 175.7K 🥇 |

### D: 95% Random Reads + 5% Random Inserts

Unlike [A](#a-50-random-reads--50-random-updates) this benchmark inserts new key-value pairs instead of updating the previously existing ones.

95:5 Mixed Requests per Second

| | WiredTiger ⊃ MongoDB | LevelDB ⊃ Google | RocksDB ⊃ Facebook | UDisk ⊃ Unum |
| - | - | - | - | - |
| 10 GB | 126,435.23 | 45,967.22 | 108,348.36 | 137,175.94 |
| 100 GB | 181,344.73 | 24,731.93 | 168,811.99 | 184,921.76 |
| 1 TB | 182,444.73 | 20,090.19 | 173,254.77 | 189,921.1 |

| Brand | CPU usage | RAM Usage | Disk Usage | Speed |
| - | - | - | - | - |
| WiredTiger ⊃ MongoDB | 2.03 cores | 18.48 GiB | 1.02 TiB | 182.4K 🥈 |
| LevelDB ⊃ Google | 1.85 cores | 232.08 MiB | 1.01 TiB | 20.1K |
| RocksDB ⊃ Facebook | 0.99 cores | 5.04 GiB | 1.00 TiB | 173.3K 🥉 |
| UDisk ⊃ Unum | 1.01 cores | 17.71 GiB | 1022.78 GiB | 189.9K 🥇 |

### E: Range Select

Here we randomly select a key and then retrieve the following 100 values. One can easily change the scan length through settings and even define it through provided probability distributions.

Range-Pulled Keys per Second

| | WiredTiger ⊃ MongoDB | LevelDB ⊃ Google | RocksDB ⊃ Facebook | UDisk ⊃ Unum |
| - | - | - | - | - |
| 10 GB | 633,159.32 | 629,545.78 | 232,887.9 | 912,253.78 |
| 100 GB | 283,999.11 | 340,528.12 | 169,758.46 | 866,139.78 |
| 1 TB | 250,222.68 | 236,279.77 | 177,329.99 | 384,273.06 |

| Brand | CPU usage | RAM Usage | Disk Usage | Speed |
| - | - | - | - | - |
| WiredTiger ⊃ MongoDB | 0.38 cores | 4.54 GiB | 989.77 GiB | 250.2K 🥈 |
| LevelDB ⊃ Google | 0.32 cores | 50.79 MiB | 983.99 GiB | 236.3K 🥉 |
| RocksDB ⊃ Facebook | 0.34 cores | 4.72 GiB | 976.27 GiB | 177.3K |
| UDisk ⊃ Unum | 0.52 cores | 344.49 MiB | 972.30 GiB | 384.3K 🥇🏅 |

### X: Batch Reads

It is a benchmark of “batch selections”, where instead of submitting one read operation at a time and waiting for it synchronously, you request a batch of, let’s say, 256 random keys. It enables the DBMS to execute them in a batch-asynchronous fashion, reordering separate operations internally for speed.

Batch-Pulled Keys per Second

| | WiredTiger ⊃ MongoDB | LevelDB ⊃ Google | RocksDB ⊃ Facebook | UDisk ⊃ Unum |
| - | - | - | - | - |
| 10 GB | 104,124.28 | 50,997.36 | 91,850.46 | 445,783.36 |
| 100 GB | 44,835.47 | 20,994.94 | 58,356.76 | 204,170.09 |
| 1 TB | 40,902.08 | 16,463.71 | 51,769.24 | 303,836.38 |

This workload is significant for BI and analytical workloads, network/graph analysis being a perfect example. At every step of your dataset exploration, you are fetching data from very different parts of your dataset to provide insights, and this requires fast “batch selections”!

| Brand | CPU usage | RAM Usage | Disk Usage | Speed |
| - | - | - | - | - |
| WiredTiger ⊃ MongoDB | 0.50 cores | 14.29 GiB | 989.77 GiB | 40.9K 🥉 |
| LevelDB ⊃ Google | 0.64 cores | 55.87 MiB | 983.99 GiB | 16.5K |
| RocksDB ⊃ Facebook | 0.35 cores | 9.07 GiB | 976.27 GiB | 51.8K 🥈 |
| UDisk ⊃ Unum | 0.37 cores | 830.48 MiB | 972.30 GiB | 303.8K 🥇🏅 |

Moreover, today AI researchers mostly train their neural networks after uniformly shuffling the datasets. It is a simple approach, but is it the best strategy if we can rapidly sample batches?

### Y: Batch Insert

Instead of inserting one value at a time, like in [C](#c-100-random-reads), we submit batches of up to 10,000 values, depending on the DB size. It’s natively supported only by LevelDB and UDisk.

Inserted Keys per Second

| | WiredTiger ⊃ MongoDB | LevelDB ⊃ Google | RocksDB ⊃ Facebook | UDisk ⊃ Unum |
| - | - | - | - | - |
| 10 GB | 658,223 | 566,856.63 | 1,194,362.39 | 1,194,662.34 |
| 100 GB | 519,867.74 | 112,332.33 | 806,019.97 | 908,697.16 |
| 1 TB | 450,326.88 | 41,142.89 | 690,191.84 | 813,225.36 |

This is different from a transaction with 256 new entries in it, as if one of the operations fails, we want the remaining to proceed. Transactions add the rollback functionality and will be the subject of future publications.

| Brand | CPU usage | RAM Usage | Disk Usage | Speed |
| - | - | - | - | - |
| WiredTiger ⊃ MongoDB | 1.00 cores | 227.22 MiB | 1.02 TiB | 450.3K 🥉 |
| LevelDB ⊃ Google | 0.99 cores | 602.71 MiB | 1.11 TiB | 41.1K |
| RocksDB ⊃ Facebook | 1.71 cores | 5.63 GiB | 1.10 TiB | 690.2K 🥈 |
| UDisk ⊃ Unum | 1.00 cores | 2.38 GiB | 1.04 TiB | 813.2K 🥇 |

### Z: Scan

Scanned Keys per Second

| | WiredTiger ⊃ MongoDB | LevelDB ⊃ Google | RocksDB ⊃ Facebook | UDisk ⊃ Unum |
| - | - | - | - | - |
| 10 GB | 1,385,404.44 | 1,154,489.39 | 83,544.9 | 1,636,819.2 |
| 100 GB | 1,389,004.11 | 1,221,020.58 | 84,370.42 | 1,632,407.42 |
| 1 TB | 1,379,971.43 | 1,207,505.79 | 84,450.43 | 1,671,307.32 |

It streams all the data present in the store, which may be later sampled and forwarded into some neural-network training procedure.

| Brand | CPU usage | RAM Usage | Disk Usage | Speed |
| - | - | - | - | - |
| WiredTiger ⊃ MongoDB | 1.22 cores | 16.80 GiB | 989.77 GiB | 1.4M 🥈 |
| LevelDB ⊃ Google | 0.59 cores | 7.36 GiB | 983.99 GiB | 1.2M 🥉 |
| RocksDB ⊃ Facebook | 0.14 cores | 4.72 GiB | 976.27 GiB | 84.5K |
| UDisk ⊃ Unum | 0.34 cores | 16.89 GiB | 968.58 GiB | 1.7M 🥇 |

---

When comparing LevelDB and RocksDB, we see their rivalry. One is a lot better for sequential scan-like workloads. In contrast, the other one is better at randomized operations. The most astonishing result for UDisk - it is better at both! WiredTiger often also performs well, but almost always uses the most energy and memory to get there.

| Brand | 0 | A | C | D | E | X | Y | Z |
| - | - | - | - | - | - | - | - | - |
| WiredTiger | 🥈 | 🥉 | 🥉 | 🥈 | 🥈 | 🥉 | 🥉 | 🥈 |
| LevelDB | | 🥈 | | | 🥉 | | | 🥉 |
| RocksDB | 🥉 | | 🥈 | 🥉 | | 🥈 | 🥈 | |
| UDisk | 🥇🏅 | 🥇🏅 | 🥇 | 🥇 | 🥇🏅 | 🥇🏅 | 🥇 | 🥇 |

This may not sound relevant, but it is. Most companies operate **2 data stores separately** - one for small **real-time** transactions and another for big **analytical** queries. This means more engineers, complex synchronization and outdated analytics. We hope to replace that entire mess with a single solution.

## Is this the limit? ⚡

Far from it! We run those benchmarks with our hands essentially cuffed. Here is a broader picture:

- when put in a **Docker** container, most KVS slow down by 15%, UDisk - by around 7%.
- on **ARM**, the gap between UDisk and the second-best solution is generally more prominent than on [x86](https://en.wikipedia.org/wiki/X86) due to our adoption of the [Neon](https://developer.arm.com/architectures/instruction-sets/simd-isas/neon) instruction family.
- **multithreaded** and transactional operations are again a lot faster, as we invest heavily into concurrent in-memory data structures far more performant and memory-efficient than a concurrent [Skip-List](https://en.wikipedia.org/wiki/Skip_list) can be.
- **initialization order** has unprecedented affect on the speed of measured operations - when the keys aren’t monotonically rising other DBs can often be 2x-5x slower.
- with **GPUs** enabled, the gap becomes astronomical, but it’s not a fair comparison, as GPUs would draw more power. 400W per GPU vs 300W when fully loading a 64-core CPU.

So prepare to see broader benchmarks soon! Anyways, our KVS performance seems solid for now, and we are focusing on:

- horizontal scaling and cloud deployment,
- going from string values to a higher-level type system,
- supporting arbitrary JSON-like inputs,
- an SQL-compatibility layer,
- bindings for dynamic scripting languages.

It might seem too ambitious for a side-project of an AI-oriented team, but we are not stopping any time soon! It’s not just about examining more data faster. It’s also about studying the same data efficiently. In 2020 alone:

- data transmission networks consumed 260-340 TWh.
- data centre electricity use was 200-250 TWh.
- cryptocurrency mining consumed \~100 TWh.

Totalling at [600-700 TWh](https://www.iea.org/reports/data-centres-and-data-transmission-networks), or what the entire 1.26 Billion population of Africa consumed in that same year. Or over 100x the [energy consumption](https://en.wikipedia.org/wiki/Electricity_sector_in_Armenia) of our [home country](https://www.unum.cloud/about.md).

With that in mind, we invite everyone to think twice about the tools we use. At least if we are genuinely committed to making the world a better place through software. It takes only a couple of search queries to realize that [CuPy can be 1’000x faster than NumPy](https://www.unum.cloud/blog/cupy.md). Similarly, other startups modernize the streaming layer, like [RedPanda](https://redpanda.com/) replacing Apache Kafka. We have already [announced](https://www.unum.cloud/blog/dbms-startups.md#2021-for-unum--udisk) our non-DBMS research directions for 2022, but all the solutions we are releasing this year [target the storage layer](https://www.unum.cloud/blog/why-build-dbms.md). Any computer takes at least [100 microseconds to fetch](https://gist.github.com/jboner/2841832) anything from a fast SSD, meaning that accessing data can be over 200’000x more expensive than processing it. It’s the slowest piece of the modern computer, so our UDisk should impact millions of applications widening their most critical bottleneck!

![C++ Meetups in Yerevan](https://www.unum.cloud/blog/ucsb/meetups.jpg)

So far, I have been personally spending millions on our research since 2015. Offices, high-end servers, R\&D teams, you name it 😋 Now, we are expanding further, attracting brilliant, inspiring researchers and organizing more technical conferences than ever. What previously felt like an impossible dream of making 🇦🇲 the second 🇮🇱, almost feels like a passed step! If you want to do [research with us](mailto:info@unum.cloud?subject=Research), [join C++ conferences](mailto:info@unum.cloud?subject=Conferences) as a speaker or [invest](mailto:invest@unum.cloud), just let us know! Anyways, who would need Oracle or MongoDB once there is UDisk? 😉
