1<!DOCTYPE html> 2<html> 3<head> 4<title>LevelDB Benchmarks</title> 5<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 6<style> 7body { 8 font-family:Helvetica,sans-serif; 9 padding:20px; 10} 11 12h2 { 13 padding-top:30px; 14} 15 16table.bn { 17 width:800px; 18 border-collapse:collapse; 19 border:0; 20 padding:0; 21} 22 23table.bnbase { 24 width:650px; 25} 26 27table.bn td { 28 padding:2px 0; 29} 30 31table.bn td.c1 { 32 font-weight:bold; 33 width:150px; 34} 35 36table.bn td.c1 div.e { 37 float:right; 38 font-weight:normal; 39} 40 41table.bn td.c2 { 42 width:150px; 43 text-align:right; 44 padding:2px; 45} 46 47table.bn td.c3 { 48 width:350px; 49} 50 51table.bn td.c4 { 52 width:150px; 53 font-size:small; 54 padding-left:4px; 55} 56 57/* chart bars */ 58div.bldb { 59 background-color:#0255df; 60} 61 62div.bkct { 63 background-color:#df5555; 64} 65 66div.bsql { 67 background-color:#aadf55; 68} 69 70.code { 71 font-family:monospace; 72 font-size:large; 73} 74 75.todo { 76 color: red; 77} 78 79</style> 80</head> 81<body> 82<h1>LevelDB Benchmarks</h1> 83<p>Google, July 2011</p> 84<hr> 85 86<p>In order to test LevelDB's performance, we benchmark it against other well-established database implementations. We compare LevelDB (revision 39) against <a href="http://www.sqlite.org/">SQLite3</a> (version 3.7.6.3) and <a href="http://fallabs.com/kyotocabinet/spex.html">Kyoto Cabinet's</a> (version 1.2.67) TreeDB (a B+Tree based key-value store). We would like to acknowledge Scott Hess and Mikio Hirabayashi for their suggestions and contributions to the SQLite3 and Kyoto Cabinet benchmarks, respectively.</p> 87 88<p>Benchmarks were all performed on a six-core Intel(R) Xeon(R) CPU X5650 @ 2.67GHz, with 12288 KB of total L3 cache and 12 GB of DDR3 RAM at 1333 MHz. (Note that LevelDB uses at most two CPUs since the benchmarks are single threaded: one to run the benchmark, and one for background compactions.) We ran the benchmarks on two machines (with identical processors), one with an Ext3 file system and one with an Ext4 file system. The machine with the Ext3 file system has a SATA Hitachi HDS721050CLA362 hard drive. The machine with the Ext4 file system has a SATA Samsung HD502HJ hard drive. Both hard drives spin at 7200 RPM. The numbers reported below are the median of three measurements.</p> 89 90<h4>Benchmark Source Code</h4> 91<p>We wrote benchmark tools for SQLite and Kyoto TreeDB based on LevelDB's <span class="code">db_bench</span>. The code for each of the benchmarks resides here:</p> 92<ul> 93 <li> <b>LevelDB:</b> <a href="http://code.google.com/p/leveldb/source/browse/trunk/db/db_bench.cc">db/db_bench.cc</a>.</li> 94 <li> <b>SQLite:</b> <a href="http://code.google.com/p/leveldb/source/browse/#svn%2Ftrunk%2Fdoc%2Fbench%2Fdb_bench_sqlite3.cc">doc/bench/db_bench_sqlite3.cc</a>.</li> 95 <li> <b>Kyoto TreeDB:</b> <a href="http://code.google.com/p/leveldb/source/browse/#svn%2Ftrunk%2Fdoc%2Fbench%2Fdb_bench_tree_db.cc">doc/bench/db_bench_tree_db.cc</a>.</li> 96</ul> 97 98<h4>Custom Build Specifications</h4> 99<ul> 100<li>LevelDB: LevelDB was compiled with the <a href="http://code.google.com/p/google-perftools">tcmalloc</a> library and the <a href="http://code.google.com/p/snappy/">Snappy</a> compression library. Assertions were disabled.</li> 101<li>TreeDB: TreeDB was compiled using the <a href="http://www.oberhumer.com/opensource/lzo/">LZO</a> compression library. Furthermore, we enabled the TSMALL and TLINEAR options when opening the database in order to reduce the footprint of each record.</li> 102<li>SQLite: We tuned SQLite's performance, by setting its locking mode to exclusive. We left SQLite's <a href="http://www.sqlite.org/draft/wal.html">write-ahead logging</a> disabled since that is the default configuration. (Enabling write-ahead-logging improves SQLite's write performance by roughly 30%, but the character of the comparisons below does not change significantly.)</li> 103</ul> 104 105<h2>1. Baseline Performance</h2> 106<p>This section gives the baseline performance of all the 107databases. Following sections show how performance changes as various 108parameters are varied. For the baseline:</p> 109<ul> 110 <li> Each database is allowed 4 MB of cache memory.</li> 111 <li> Databases are opened in <em>asynchronous</em> write mode. 112 (LevelDB's sync option, TreeDB's OAUTOSYNC option, and 113 SQLite3's synchronous options are all turned off). I.e., 114 every write is pushed to the operating system, but the 115 benchmark does not wait for the write to reach the disk.</li> 116 <li> Keys are 16 bytes each.</li> 117 <li> Value are 100 bytes each (with enough redundancy so that 118 a simple compressor shrinks them to 50% of their original 119 size).</li> 120 <li> Sequential reads/writes traverse the key space in increasing order.</li> 121 <li> Random reads/writes traverse the key space in random order.</li> 122</ul> 123 124<h3>A. Sequential Reads</h3> 125<table class="bn bnbase"> 126<tr><td class="c1">LevelDB</td> 127 <td class="c2">4,030,000 ops/sec</td> 128 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 129<tr><td class="c1">Kyoto TreeDB</td> 130 <td class="c2">1,010,000 ops/sec</td> 131 <td class="c3"><div class="bkct" style="width:95px"> </div></td> 132<tr><td class="c1">SQLite3</td> 133 <td class="c2">186,000 ops/sec</td> 134 <td class="c3"><div class="bsql" style="width:16px"> </div></td> 135</table> 136<h3>B. Random Reads</h3> 137<table class="bn bnbase"> 138<tr><td class="c1">LevelDB</td> 139 <td class="c2">129,000 ops/sec</td> 140 <td class="c3"><div class="bldb" style="width:298px"> </div></td> 141<tr><td class="c1">Kyoto TreeDB</td> 142 <td class="c2">151,000 ops/sec</td> 143 <td class="c3"><div class="bkct" style="width:350px"> </div></td> 144<tr><td class="c1">SQLite3</td> 145 <td class="c2">146,000 ops/sec</td> 146 <td class="c3"><div class="bsql" style="width:337px"> </div></td> 147</table> 148<h3>C. Sequential Writes</h3> 149<table class="bn bnbase"> 150<tr><td class="c1">LevelDB</td> 151 <td class="c2">779,000 ops/sec</td> 152 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 153<tr><td class="c1">Kyoto TreeDB</td> 154 <td class="c2">342,000 ops/sec</td> 155 <td class="c3"><div class="bkct" style="width:154px"> </div></td> 156<tr><td class="c1">SQLite3</td> 157 <td class="c2">26,900 ops/sec</td> 158 <td class="c3"><div class="bsql" style="width:12px"> </div></td> 159</table> 160<h3>D. Random Writes</h3> 161<table class="bn bnbase"> 162<tr><td class="c1">LevelDB</td> 163 <td class="c2">164,000 ops/sec</td> 164 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 165<tr><td class="c1">Kyoto TreeDB</td> 166 <td class="c2">88,500 ops/sec</td> 167 <td class="c3"><div class="bkct" style="width:188px"> </div></td> 168<tr><td class="c1">SQLite3</td> 169 <td class="c2">420 ops/sec</td> 170 <td class="c3"><div class="bsql" style="width:1px"> </div></td> 171</table> 172 173<p>LevelDB outperforms both SQLite3 and TreeDB in sequential and random write operations and sequential read operations. Kyoto Cabinet has the fastest random read operations.</p> 174 175<h2>2. Write Performance under Different Configurations</h2> 176<h3>A. Large Values </h3> 177<p>For this benchmark, we start with an empty database, and write 100,000 byte values (~50% compressible). To keep the benchmark running time reasonable, we stop after writing 1000 values.</p> 178<h4>Sequential Writes</h4> 179<table class="bn bnbase"> 180<tr><td class="c1">LevelDB</td> 181 <td class="c2">1,060 ops/sec</td> 182 <td class="c3"><div class="bldb" style="width:127px"> </div></td></tr> 183<tr><td class="c1">Kyoto TreeDB</td> 184 <td class="c2">1,020 ops/sec</td> 185 <td class="c3"><div class="bkct" style="width:122px"> </div></td></tr> 186<tr><td class="c1">SQLite3</td> 187 <td class="c2">2,910 ops/sec</td> 188 <td class="c3"><div class="bsql" style="width:350px"> </div></td></tr> 189</table> 190<h4>Random Writes</h4> 191<table class="bn bnbase"> 192<tr><td class="c1">LevelDB</td> 193 <td class="c2">480 ops/sec</td> 194 <td class="c3"><div class="bldb" style="width:77px"> </div></td></tr> 195<tr><td class="c1">Kyoto TreeDB</td> 196 <td class="c2">1,100 ops/sec</td> 197 <td class="c3"><div class="bkct" style="width:350px"> </div></td></tr> 198<tr><td class="c1">SQLite3</td> 199 <td class="c2">2,200 ops/sec</td> 200 <td class="c3"><div class="bsql" style="width:175px"> </div></td></tr> 201</table> 202<p>LevelDB doesn't perform as well with large values of 100,000 bytes each. This is because LevelDB writes keys and values at least twice: first time to the transaction log, and second time (during a compaction) to a sorted file. 203With larger values, LevelDB's per-operation efficiency is swamped by the 204cost of extra copies of large values.</p> 205<h3>B. Batch Writes</h3> 206<p>A batch write is a set of writes that are applied atomically to the underlying database. A single batch of N writes may be significantly faster than N individual writes. The following benchmark writes one thousand batches where each batch contains one thousand 100-byte values. TreeDB does not support batch writes and is omitted from this benchmark.</p> 207<h4>Sequential Writes</h4> 208<table class="bn"> 209<tr><td class="c1">LevelDB</td> 210 <td class="c2">840,000 entries/sec</td> 211 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 212 <td class="c4">(1.08x baseline)</td></tr> 213<tr><td class="c1">SQLite3</td> 214 <td class="c2">100,000 entries/sec</td> 215 <td class="c3"><div class="bsql" style="width:43px"> </div></td> 216 <td class="c4">(3.72x baseline)</td></tr> 217</table> 218<h4>Random Writes</h4> 219<table class="bn"> 220<tr><td class="c1">LevelDB</td> 221 <td class="c2">221,000 entries/sec</td> 222 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 223 <td class="c4">(1.35x baseline)</td></tr> 224<tr><td class="c1">SQLite3</td> 225 <td class="c2">1,000 entries/sec</td> 226 <td class="c3"><div class="bsql" style="width:2px"> </div></td> 227 <td class="c4">(2.38x baseline)</td></tr> 228</table> 229 230<p>Because of the way LevelDB persistent storage is organized, batches of 231random writes are not much slower (only a factor of 4x) than batches 232of sequential writes. However SQLite3 sees a significant slowdown 233(factor of 100x) when switching from sequential to random batch 234writes. This is because each random batch write in SQLite3 has to 235update approximately as many pages as there are keys in the batch.</p> 236 237<h3>C. Synchronous Writes</h3> 238<p>In the following benchmark, we enable the synchronous writing modes 239of all of the databases. Since this change significantly slows down the 240benchmark, we stop after 10,000 writes.</p> 241<ul> 242 <li>For LevelDB, we set WriteOptions.sync = true.</li> 243 <li>In TreeDB, we enabled TreeDB's OAUTOSYNC option.</li> 244 <li>For SQLite3, we set "PRAGMA synchronous = FULL".</li> 245</ul> 246<h4>Sequential Writes</h4> 247<table class="bn"> 248<tr><td class="c1">LevelDB</td> 249 <td class="c2">2,400 ops/sec</td> 250 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 251 <td class="c4">(0.003x baseline)</td></tr> 252<tr><td class="c1">Kyoto TreeDB</td> 253 <td class="c2">140 ops/sec</td> 254 <td class="c3"><div class="bkct" style="width:21px"> </div></td> 255 <td class="c4">(0.0004x baseline)</td></tr> 256<tr><td class="c1">SQLite3</td> 257 <td class="c2">430 ops/sec</td> 258 <td class="c3"><div class="bsql" style="width:61px"> </div></td> 259 <td class="c4">(0.016x baseline)</td></tr> 260</table> 261<h4>Random Writes</h4> 262<table class="bn"> 263<tr><td class="c1">LevelDB</td> 264 <td class="c2">2,400 ops/sec</td> 265 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 266 <td class="c4">(0.015x baseline)</td></tr> 267<tr><td class="c1">Kyoto TreeDB</td> 268 <td class="c2">100 ops/sec</td> 269 <td class="c3"><div class="bkct" style="width:14px"> </div></td> 270 <td class="c4">(0.001x baseline)</td></tr> 271<tr><td class="c1">SQLite3</td> 272 <td class="c2">110 ops/sec</td> 273 <td class="c3"><div class="bsql" style="width:16px"> </div></td> 274 <td class="c4">(0.26x baseline)</td></tr> 275</table> 276 277<p>Also see the <code>ext4</code> performance numbers below 278since synchronous writes behave significantly differently 279on <code>ext3</code> and <code>ext4</code>.</p> 280 281<h3>D. Turning Compression Off</h3> 282 283<p>In the baseline measurements, LevelDB and TreeDB were using 284light-weight compression 285(<a href="http://code.google.com/p/snappy/">Snappy</a> for LevelDB, 286and <a href="http://www.oberhumer.com/opensource/lzo/">LZO</a> for 287TreeDB). SQLite3, by default does not use compression. The 288experiments below show what happens when compression is disabled in 289all of the databases (the SQLite3 numbers are just a copy of 290its baseline measurements):</p> 291 292<h4>Sequential Writes</h4> 293<table class="bn"> 294<tr><td class="c1">LevelDB</td> 295 <td class="c2">594,000 ops/sec</td> 296 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 297 <td class="c4">(0.76x baseline)</td></tr> 298<tr><td class="c1">Kyoto TreeDB</td> 299 <td class="c2">485,000 ops/sec</td> 300 <td class="c3"><div class="bkct" style="width:239px"> </div></td> 301 <td class="c4">(1.42x baseline)</td></tr> 302<tr><td class="c1">SQLite3</td> 303 <td class="c2">26,900 ops/sec</td> 304 <td class="c3"><div class="bsql" style="width:13px"> </div></td> 305 <td class="c4">(1.00x baseline)</td></tr> 306</table> 307<h4>Random Writes</h4> 308<table class="bn"> 309<tr><td class="c1">LevelDB</td> 310 <td class="c2">135,000 ops/sec</td> 311 <td class="c3"><div class="bldb" style="width:296px"> </div></td> 312 <td class="c4">(0.82x baseline)</td></tr> 313<tr><td class="c1">Kyoto TreeDB</td> 314 <td class="c2">159,000 ops/sec</td> 315 <td class="c3"><div class="bkct" style="width:350px"> </div></td> 316 <td class="c4">(1.80x baseline)</td></tr> 317<tr><td class="c1">SQLite3</td> 318 <td class="c2">420 ops/sec</td> 319 <td class="c3"><div class="bsql" style="width:1px"> </div></td> 320 <td class="c4">(1.00x baseline)</td></tr> 321</table> 322 323<p>LevelDB's write performance is better with compression than without 324since compression decreases the amount of data that has to be written 325to disk. Therefore LevelDB users can leave compression enabled in 326most scenarios without having worry about a tradeoff between space 327usage and performance. TreeDB's performance on the other hand is 328better without compression than with compression. Presumably this is 329because TreeDB's compression library (LZO) is more expensive than 330LevelDB's compression library (Snappy).<p> 331 332<h3>E. Using More Memory</h3> 333<p>We increased the overall cache size for each database to 128 MB. For LevelDB, we partitioned 128 MB into a 120 MB write buffer and 8 MB of cache (up from 2 MB of write buffer and 2 MB of cache). For SQLite3, we kept the page size at 1024 bytes, but increased the number of pages to 131,072 (up from 4096). For TreeDB, we also kept the page size at 1024 bytes, but increased the cache size to 128 MB (up from 4 MB).</p> 334<h4>Sequential Writes</h4> 335<table class="bn"> 336<tr><td class="c1">LevelDB</td> 337 <td class="c2">812,000 ops/sec</td> 338 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 339 <td class="c4">(1.04x baseline)</td></tr> 340<tr><td class="c1">Kyoto TreeDB</td> 341 <td class="c2">321,000 ops/sec</td> 342 <td class="c3"><div class="bkct" style="width:138px"> </div></td> 343 <td class="c4">(0.94x baseline)</td></tr> 344<tr><td class="c1">SQLite3</td> 345 <td class="c2">26,200 ops/sec</td> 346 <td class="c3"><div class="bsql" style="width:11px"> </div></td> 347 <td class="c4">(0.97x baseline)</td></tr> 348</table> 349<h4>Random Writes</h4> 350<table class="bn"> 351<tr><td class="c1">LevelDB</td> 352 <td class="c2">355,000 ops/sec</td> 353 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 354 <td class="c4">(2.16x baseline)</td></tr> 355<tr><td class="c1">Kyoto TreeDB</td> 356 <td class="c2">284,000 ops/sec</td> 357 <td class="c3"><div class="bkct" style="width:280px"> </div></td> 358 <td class="c4">(3.21x baseline)</td></tr> 359<tr><td class="c1">SQLite3</td> 360 <td class="c2">450 ops/sec</td> 361 <td class="c3"><div class="bsql" style="width:0px"> </div></td> 362 <td class="c4">(1.07x baseline)</td></tr> 363</table> 364 365<p>SQLite's performance does not change substantially when compared to 366the baseline, but the random write performance for both LevelDB and 367TreeDB increases significantly. LevelDB's performance improves 368because a larger write buffer reduces the need to merge sorted files 369(since it creates a smaller number of larger sorted files). TreeDB's 370performance goes up because the entire database is available in memory 371for fast in-place updates.</p> 372 373 <h2>3. Read Performance under Different Configurations</h2> 374<h3>A. Larger Caches</h3> 375<p>We increased the overall memory usage to 128 MB for each database. 376For LevelDB, we allocated 8 MB to LevelDB's write buffer and 120 MB 377to LevelDB's cache. The other databases don't differentiate between a 378write buffer and a cache, so we simply set their cache size to 128 379MB.</p> 380<h4>Sequential Reads</h4> 381<table class="bn"> 382<tr><td class="c1">LevelDB</td> 383 <td class="c2">5,210,000 ops/sec</td> 384 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 385 <td class="c4">(1.29x baseline)</td></tr> 386<tr><td class="c1">Kyoto TreeDB</td> 387 <td class="c2">1,070,000 ops/sec</td> 388 <td class="c3"><div class="bkct" style="width:72px"> </div></td> 389 <td class="c4">(1.06x baseline)</td></tr> 390<tr><td class="c1">SQLite3</td> 391 <td class="c2">221,000 ops/sec</td> 392 <td class="c3"><div class="bsql" style="width:15px"> </div></td> 393 <td class="c4">(1.19x baseline)</td></tr> 394</table> 395 396<h4>Random Reads</h4> 397<table class="bn"> 398<tr><td class="c1">LevelDB</td> 399 <td class="c2">190,000 ops/sec</td> 400 <td class="c3"><div class="bldb" style="width:144px"> </div></td> 401 <td class="c4">(1.47x baseline)</td></tr> 402<tr><td class="c1">Kyoto TreeDB</td> 403 <td class="c2">463,000 ops/sec</td> 404 <td class="c3"><div class="bkct" style="width:350px"> </div></td> 405 <td class="c4">(3.07x baseline)</td></tr> 406<tr><td class="c1">SQLite3</td> 407 <td class="c2">197,000 ops/sec</td> 408 <td class="c3"><div class="bsql" style="width:149px"> </div></td> 409 <td class="c4">(1.35x baseline)</td></tr> 410</table> 411 412<p>As expected, the read performance of all of the databases increases 413when the caches are enlarged. In particular, TreeDB seems to make 414very effective use of a cache that is large enough to hold the entire 415database.</p> 416 417<h3>B. No Compression Reads </h3> 418<p>For this benchmark, we populated a database with 1 million entries consisting of 16 byte keys and 100 byte values. We compiled LevelDB and Kyoto Cabinet without compression support, so results that are read out from the database are already uncompressed. We've listed the SQLite3 baseline read performance as a point of comparison.</p> 419<h4>Sequential Reads</h4> 420<table class="bn"> 421<tr><td class="c1">LevelDB</td> 422 <td class="c2">4,880,000 ops/sec</td> 423 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 424 <td class="c4">(1.21x baseline)</td></tr> 425<tr><td class="c1">Kyoto TreeDB</td> 426 <td class="c2">1,230,000 ops/sec</td> 427 <td class="c3"><div class="bkct" style="width:88px"> </div></td> 428 <td class="c4">(3.60x baseline)</td></tr> 429<tr><td class="c1">SQLite3</td> 430 <td class="c2">186,000 ops/sec</td> 431 <td class="c3"><div class="bsql" style="width:13px"> </div></td> 432 <td class="c4">(1.00x baseline)</td></tr> 433</table> 434<h4>Random Reads</h4> 435<table class="bn"> 436<tr><td class="c1">LevelDB</td> 437 <td class="c2">149,000 ops/sec</td> 438 <td class="c3"><div class="bldb" style="width:300px"> </div></td> 439 <td class="c4">(1.16x baseline)</td></tr> 440<tr><td class="c1">Kyoto TreeDB</td> 441 <td class="c2">175,000 ops/sec</td> 442 <td class="c3"><div class="bkct" style="width:350px"> </div></td> 443 <td class="c4">(1.16x baseline)</td></tr> 444<tr><td class="c1">SQLite3</td> 445 <td class="c2">146,000 ops/sec</td> 446 <td class="c3"><div class="bsql" style="width:292px"> </div></td> 447 <td class="c4">(1.00x baseline)</td></tr> 448</table> 449 450<p>Performance of both LevelDB and TreeDB improves a small amount when 451compression is disabled. Note however that under different workloads, 452performance may very well be better with compression if it allows more 453of the working set to fit in memory.</p> 454 455<h2>Note about Ext4 Filesystems</h2> 456<p>The preceding numbers are for an ext3 file system. Synchronous writes are much slower under <a href="http://en.wikipedia.org/wiki/Ext4">ext4</a> (LevelDB drops to ~34 writes / second, TreeDB drops to ~5 writes / second; SQLite3 drops to ~24 writes / second) due to ext4's different handling of <span class="code">fsync</span> / <span class="code">msync</span> calls. Even LevelDB's asynchronous write performance drops somewhat since it spreads its storage across multiple files and issues <span class="code">fsync</span> calls when switching to a new file.</p> 457 458<h2>Acknowledgements</h2> 459<p>Jeff Dean and Sanjay Ghemawat wrote LevelDB. Kevin Tseng wrote and compiled these benchmarks. Mikio Hirabayashi, Scott Hess, and Gabor Cselle provided help and advice.</p> 460</body> 461</html> 462