September 19, 2018
amberwilsonla
Introducing HaloDB, a fast, embedded key-value storage engine written in Java
<p><a href="https://yahoodevelopers.tumblr.com/post/178250134648/introducing-halodb-a-fast-embedded-key-value" class="tumblr_blog">yahoodevelopers</a>:</p><blockquote>
<p>By Arjun Mannaly, Senior Software Engineer </p>
<p>At <a href="https://www.oath.com/our-brands/">Oath</a>, multiple ad platforms use a high throughput, low latency distributed key-value database that runs in data centers all over the world. The database stores billions of records and handles millions of read and write requests per second at millisecond latencies. The data we have in this database must be persistent, and the working set is larger than what we can fit in memory. Therefore, a key component of the database performance is a fast storage engine. Our current solution had served us well, but it was primarily designed for a read-heavy workload and its write throughput started to be a bottleneck as write traffic increased. </p>
<p>There were other additional concerns as well; it took hours to repair a corrupted DB, or iterate over and delete records. The storage engine also didn’t expose enough operational metrics. The primary concern though was the write performance, which based on our projections, would have been a major obstacle for scaling the database. With these concerns in mind, we began searching for an alternative solution.</p>
<p>We searched for a key-value storage engine capable of dealing with IO-bound workloads, with submillisecond read latencies under high read and write throughput. After concluding our research and benchmarking alternatives, we didn’t find a solution that worked for our workload, thus we were inspired to build <a href="https://github.com/yahoo/HaloDB">HaloDB</a>. Now, we’re glad to announce that it’s also open source and available to use under the terms of the Apache license.</p>
<p>HaloDB has given our production boxes a 50% improvement in write capacity while consistently maintaining a submillisecond read latency at the 99th percentile.</p>
<p><b>Architecture</b></p>
<figure data-orig-width="2368" data-orig-height="1368" class="tmblr-full"><img src="https://66.media.tumblr.com/04e736daa5dde2107603a9dd3dc0731c/tumblr_inline_pf9yuxWhcu1w911gs_540.png" alt="image" data-orig-width="2368" data-orig-height="1368"/></figure><p><a href="https://github.com/yahoo/HaloDB">HaloDB</a> primarily consists of append-only log files on disk and an index of keys in memory. All writes are sequential writes which go to an append-only log file and the file is rolled-over once it reaches a configurable size. Older versions of records are removed to make space by a background compaction job. </p>
<p>The in-memory index in HaloDB is a hash table which stores all keys and their associated metadata. The size of the in-memory index, depending on the number of keys, can be quite large, hence for performance reasons, is stored outside the Java heap, in native memory. When looking up the value for a key, corresponding metadata is first read from the in-memory index and then the value is read from disk. Each lookup request requires at most a single read from disk.</p>
<p><b>Performance </b></p>
<p>The chart below shows the results of performance tests with real production data. The read requests were kept at 50,000 QPS while the write QPS was increased. HaloDB scaled very well as we increased the write QPS while consistently maintaining submillisecond read latencies at the 99th percentile. </p>
<figure data-orig-width="1952" data-orig-height="1070" class="tmblr-full"><img src="https://66.media.tumblr.com/7efd59fbfac8948311bd06b94bb13a3d/tumblr_inline_pf9yw2U2pf1w911gs_540.png" alt="image" data-orig-width="1952" data-orig-height="1070"/></figure><p>The chart below shows the 99th percentile latency from a production server before and after migration to HaloDB.</p>
<figure data-orig-width="2092" data-orig-height="852" class="tmblr-full"><img src="https://66.media.tumblr.com/04498b8293449c7b5cec6052fa80d6e4/tumblr_inline_pf9yzvzNGz1w911gs_540.png" alt="image" data-orig-width="2092" data-orig-height="852"/></figure><p> If <a href="https://github.com/yahoo/HaloDB">HaloDB</a> sounds like a helpful solution to you, please feel free to use it, open <a href="https://github.com/yahoo/halodb/issues">issues</a>, and <a href="https://github.com/yahoo/HaloDB/blob/master/CONTRIBUTING.md">contribute</a>!</p>
</blockquote>