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> 7 body { 8 font-family:Helvetica,sans-serif; 9 padding:20px; 10 } 11 12 h2 { 13 padding-top:30px; 14 } 15 16 table.bn { 17 width:800px; 18 border-collapse:collapse; 19 border:0; 20 padding:0; 21 } 22 23 table.bnbase { 24 width:650px; 25 } 26 27 table.bn td { 28 padding:2px 0; 29 } 30 31 table.bn td.c1 { 32 font-weight:bold; 33 width:150px; 34 } 35 36 table.bn td.c1 div.e { 37 float:right; 38 font-weight:normal; 39 } 40 41 table.bn td.c2 { 42 width:150px; 43 text-align:right; 44 padding:2px; 45 } 46 47 table.bn td.c3 { 48 width:350px; 49 } 50 51 table.bn td.c4 { 52 width:150px; 53 font-size:small; 54 padding-left:4px; 55 } 56 57 /* chart bars */ 58 div.bldb { 59 background-color:#0255df; 60 } 61 62 div.bkct { 63 background-color:#df5555; 64 } 65 66 div.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 and have hard drive write-caching enabled (using `hdparm -W 1 [device]`). 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 (revision 33). Assertions were disabled.</li> 101 <li>TreeDB: TreeDB was compiled using the <a href="http://www.oberhumer.com/opensource/lzo/">LZO</a> compression library (version 2.03). 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 also enabled SQLite's <a href="http://www.sqlite.org/draft/wal.html">write-ahead logging</a>.</li> 103 </ul> 104 105 <h2>1. Baseline Performance</h2> 106 <p>This section gives the baseline performance of all the 107 databases. Following sections show how performance changes as various 108 parameters 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">383,000 ops/sec</td> 134 <td class="c3"><div class="bsql" style="width:33px"> </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">134,000 ops/sec</td> 146 <td class="c3"><div class="bsql" style="width:310px"> </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">48,600 ops/sec</td> 158 <td class="c3"><div class="bsql" style="width:22px"> </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">9,860 ops/sec</td> 170 <td class="c3"><div class="bsql" style="width:21px"> </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,100 ops/sec</td> 182 <td class="c3"><div class="bldb" style="width:234px"> </div></td></tr> 183 <tr><td class="c1">Kyoto TreeDB</td> 184 <td class="c2">1,000 ops/sec</td> 185 <td class="c3"><div class="bkct" style="width:224px"> </div></td></tr> 186 <tr><td class="c1">SQLite3</td> 187 <td class="c2">1,600 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:105px"> </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:240px"> </div></td></tr> 198 <tr><td class="c1">SQLite3</td> 199 <td class="c2">1,600 ops/sec</td> 200 <td class="c3"><div class="bsql" style="width:350px"> </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. 203 With larger values, LevelDB's per-operation efficiency is swamped by the 204 cost 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">124,000 entries/sec</td> 215 <td class="c3"><div class="bsql" style="width:52px"> </div></td> 216 <td class="c4">(2.55x 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">22,000 entries/sec</td> 226 <td class="c3"><div class="bsql" style="width:34px"> </div></td> 227 <td class="c4">(2.23x baseline)</td></tr> 228 </table> 229 230 <p>Because of the way LevelDB persistent storage is organized, batches of 231 random writes are not much slower (only a factor of 4x) than batches 232 of sequential writes.</p> 233 234 <h3>C. Synchronous Writes</h3> 235 <p>In the following benchmark, we enable the synchronous writing modes 236 of all of the databases. Since this change significantly slows down the 237 benchmark, we stop after 10,000 writes. For synchronous write tests, we've 238 disabled hard drive write-caching (using `hdparm -W 0 [device]`).</p> 239 <ul> 240 <li>For LevelDB, we set WriteOptions.sync = true.</li> 241 <li>In TreeDB, we enabled TreeDB's OAUTOSYNC option.</li> 242 <li>For SQLite3, we set "PRAGMA synchronous = FULL".</li> 243 </ul> 244 <h4>Sequential Writes</h4> 245 <table class="bn"> 246 <tr><td class="c1">LevelDB</td> 247 <td class="c2">100 ops/sec</td> 248 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 249 <td class="c4">(0.003x baseline)</td></tr> 250 <tr><td class="c1">Kyoto TreeDB</td> 251 <td class="c2">7 ops/sec</td> 252 <td class="c3"><div class="bkct" style="width:27px"> </div></td> 253 <td class="c4">(0.0004x baseline)</td></tr> 254 <tr><td class="c1">SQLite3</td> 255 <td class="c2">88 ops/sec</td> 256 <td class="c3"><div class="bsql" style="width:315px"> </div></td> 257 <td class="c4">(0.002x baseline)</td></tr> 258 </table> 259 <h4>Random Writes</h4> 260 <table class="bn"> 261 <tr><td class="c1">LevelDB</td> 262 <td class="c2">100 ops/sec</td> 263 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 264 <td class="c4">(0.015x baseline)</td></tr> 265 <tr><td class="c1">Kyoto TreeDB</td> 266 <td class="c2">8 ops/sec</td> 267 <td class="c3"><div class="bkct" style="width:29px"> </div></td> 268 <td class="c4">(0.001x baseline)</td></tr> 269 <tr><td class="c1">SQLite3</td> 270 <td class="c2">88 ops/sec</td> 271 <td class="c3"><div class="bsql" style="width:314px"> </div></td> 272 <td class="c4">(0.009x baseline)</td></tr> 273 </table> 274 275 <p>Also see the <code>ext4</code> performance numbers below 276 since synchronous writes behave significantly differently 277 on <code>ext3</code> and <code>ext4</code>.</p> 278 279 <h3>D. Turning Compression Off</h3> 280 281 <p>In the baseline measurements, LevelDB and TreeDB were using 282 light-weight compression 283 (<a href="http://code.google.com/p/snappy/">Snappy</a> for LevelDB, 284 and <a href="http://www.oberhumer.com/opensource/lzo/">LZO</a> for 285 TreeDB). SQLite3, by default does not use compression. The 286 experiments below show what happens when compression is disabled in 287 all of the databases (the SQLite3 numbers are just a copy of 288 its baseline measurements):</p> 289 290 <h4>Sequential Writes</h4> 291 <table class="bn"> 292 <tr><td class="c1">LevelDB</td> 293 <td class="c2">594,000 ops/sec</td> 294 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 295 <td class="c4">(0.76x baseline)</td></tr> 296 <tr><td class="c1">Kyoto TreeDB</td> 297 <td class="c2">485,000 ops/sec</td> 298 <td class="c3"><div class="bkct" style="width:239px"> </div></td> 299 <td class="c4">(1.42x baseline)</td></tr> 300 <tr><td class="c1">SQLite3</td> 301 <td class="c2">48,600 ops/sec</td> 302 <td class="c3"><div class="bsql" style="width:29px"> </div></td> 303 <td class="c4">(1.00x baseline)</td></tr> 304 </table> 305 <h4>Random Writes</h4> 306 <table class="bn"> 307 <tr><td class="c1">LevelDB</td> 308 <td class="c2">135,000 ops/sec</td> 309 <td class="c3"><div class="bldb" style="width:296px"> </div></td> 310 <td class="c4">(0.82x baseline)</td></tr> 311 <tr><td class="c1">Kyoto TreeDB</td> 312 <td class="c2">159,000 ops/sec</td> 313 <td class="c3"><div class="bkct" style="width:350px"> </div></td> 314 <td class="c4">(1.80x baseline)</td></tr> 315 <tr><td class="c1">SQLite3</td> 316 <td class="c2">9,860 ops/sec</td> 317 <td class="c3"><div class="bsql" style="width:22px"> </div></td> 318 <td class="c4">(1.00x baseline)</td></tr> 319 </table> 320 321 <p>LevelDB's write performance is better with compression than without 322 since compression decreases the amount of data that has to be written 323 to disk. Therefore LevelDB users can leave compression enabled in 324 most scenarios without having worry about a tradeoff between space 325 usage and performance. TreeDB's performance on the other hand is 326 better without compression than with compression. Presumably this is 327 because TreeDB's compression library (LZO) is more expensive than 328 LevelDB's compression library (Snappy).<p> 329 330 <h3>E. Using More Memory</h3> 331 <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> 332 <h4>Sequential Writes</h4> 333 <table class="bn"> 334 <tr><td class="c1">LevelDB</td> 335 <td class="c2">812,000 ops/sec</td> 336 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 337 <td class="c4">(1.04x baseline)</td></tr> 338 <tr><td class="c1">Kyoto TreeDB</td> 339 <td class="c2">321,000 ops/sec</td> 340 <td class="c3"><div class="bkct" style="width:138px"> </div></td> 341 <td class="c4">(0.94x baseline)</td></tr> 342 <tr><td class="c1">SQLite3</td> 343 <td class="c2">48,500 ops/sec</td> 344 <td class="c3"><div class="bsql" style="width:21px"> </div></td> 345 <td class="c4">(1.00x baseline)</td></tr> 346 </table> 347 <h4>Random Writes</h4> 348 <table class="bn"> 349 <tr><td class="c1">LevelDB</td> 350 <td class="c2">355,000 ops/sec</td> 351 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 352 <td class="c4">(2.16x baseline)</td></tr> 353 <tr><td class="c1">Kyoto TreeDB</td> 354 <td class="c2">284,000 ops/sec</td> 355 <td class="c3"><div class="bkct" style="width:280px"> </div></td> 356 <td class="c4">(3.21x baseline)</td></tr> 357 <tr><td class="c1">SQLite3</td> 358 <td class="c2">9,670 ops/sec</td> 359 <td class="c3"><div class="bsql" style="width:10px"> </div></td> 360 <td class="c4">(0.98x baseline)</td></tr> 361 </table> 362 363 <p>SQLite's performance does not change substantially when compared to 364 the baseline, but the random write performance for both LevelDB and 365 TreeDB increases significantly. LevelDB's performance improves 366 because a larger write buffer reduces the need to merge sorted files 367 (since it creates a smaller number of larger sorted files). TreeDB's 368 performance goes up because the entire database is available in memory 369 for fast in-place updates.</p> 370 371 <h2>3. Read Performance under Different Configurations</h2> 372 <h3>A. Larger Caches</h3> 373 <p>We increased the overall memory usage to 128 MB for each database. 374 For LevelDB, we allocated 8 MB to LevelDB's write buffer and 120 MB 375 to LevelDB's cache. The other databases don't differentiate between a 376 write buffer and a cache, so we simply set their cache size to 128 377 MB.</p> 378 <h4>Sequential Reads</h4> 379 <table class="bn"> 380 <tr><td class="c1">LevelDB</td> 381 <td class="c2">5,210,000 ops/sec</td> 382 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 383 <td class="c4">(1.29x baseline)</td></tr> 384 <tr><td class="c1">Kyoto TreeDB</td> 385 <td class="c2">1,070,000 ops/sec</td> 386 <td class="c3"><div class="bkct" style="width:72px"> </div></td> 387 <td class="c4">(1.06x baseline)</td></tr> 388 <tr><td class="c1">SQLite3</td> 389 <td class="c2">609,000 ops/sec</td> 390 <td class="c3"><div class="bsql" style="width:41px"> </div></td> 391 <td class="c4">(1.59x baseline)</td></tr> 392 </table> 393 394 <h4>Random Reads</h4> 395 <table class="bn"> 396 <tr><td class="c1">LevelDB</td> 397 <td class="c2">190,000 ops/sec</td> 398 <td class="c3"><div class="bldb" style="width:144px"> </div></td> 399 <td class="c4">(1.47x baseline)</td></tr> 400 <tr><td class="c1">Kyoto TreeDB</td> 401 <td class="c2">463,000 ops/sec</td> 402 <td class="c3"><div class="bkct" style="width:350px"> </div></td> 403 <td class="c4">(3.07x baseline)</td></tr> 404 <tr><td class="c1">SQLite3</td> 405 <td class="c2">186,000 ops/sec</td> 406 <td class="c3"><div class="bsql" style="width:141px"> </div></td> 407 <td class="c4">(1.39x baseline)</td></tr> 408 </table> 409 410 <p>As expected, the read performance of all of the databases increases 411 when the caches are enlarged. In particular, TreeDB seems to make 412 very effective use of a cache that is large enough to hold the entire 413 database.</p> 414 415 <h3>B. No Compression Reads </h3> 416 <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> 417 <h4>Sequential Reads</h4> 418 <table class="bn"> 419 <tr><td class="c1">LevelDB</td> 420 <td class="c2">4,880,000 ops/sec</td> 421 <td class="c3"><div class="bldb" style="width:350px"> </div></td> 422 <td class="c4">(1.21x baseline)</td></tr> 423 <tr><td class="c1">Kyoto TreeDB</td> 424 <td class="c2">1,230,000 ops/sec</td> 425 <td class="c3"><div class="bkct" style="width:88px"> </div></td> 426 <td class="c4">(3.60x baseline)</td></tr> 427 <tr><td class="c1">SQLite3</td> 428 <td class="c2">383,000 ops/sec</td> 429 <td class="c3"><div class="bsql" style="width:27px"> </div></td> 430 <td class="c4">(1.00x baseline)</td></tr> 431 </table> 432 <h4>Random Reads</h4> 433 <table class="bn"> 434 <tr><td class="c1">LevelDB</td> 435 <td class="c2">149,000 ops/sec</td> 436 <td class="c3"><div class="bldb" style="width:300px"> </div></td> 437 <td class="c4">(1.16x baseline)</td></tr> 438 <tr><td class="c1">Kyoto TreeDB</td> 439 <td class="c2">175,000 ops/sec</td> 440 <td class="c3"><div class="bkct" style="width:350px"> </div></td> 441 <td class="c4">(1.16x baseline)</td></tr> 442 <tr><td class="c1">SQLite3</td> 443 <td class="c2">134,000 ops/sec</td> 444 <td class="c3"><div class="bsql" style="width:268px"> </div></td> 445 <td class="c4">(1.00x baseline)</td></tr> 446 </table> 447 448 <p>Performance of both LevelDB and TreeDB improves a small amount when 449 compression is disabled. Note however that under different workloads, 450 performance may very well be better with compression if it allows more 451 of the working set to fit in memory.</p> 452 453 <h2>Note about Ext4 Filesystems</h2> 454 <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 ~31 writes / second and TreeDB drops to ~5 writes / second; SQLite3's synchronous writes do not noticeably drop) 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> 455 456 <h2>Acknowledgements</h2> 457 <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> 458 </body> 459 </html> 460