1*9507f98cSAndroid Build Coastguard Worker<!DOCTYPE html> 2*9507f98cSAndroid Build Coastguard Worker<html> 3*9507f98cSAndroid Build Coastguard Worker<head> 4*9507f98cSAndroid Build Coastguard Worker<title>LevelDB Benchmarks</title> 5*9507f98cSAndroid Build Coastguard Worker<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 6*9507f98cSAndroid Build Coastguard Worker<style> 7*9507f98cSAndroid Build Coastguard Workerbody { 8*9507f98cSAndroid Build Coastguard Worker font-family:Helvetica,sans-serif; 9*9507f98cSAndroid Build Coastguard Worker padding:20px; 10*9507f98cSAndroid Build Coastguard Worker} 11*9507f98cSAndroid Build Coastguard Worker 12*9507f98cSAndroid Build Coastguard Workerh2 { 13*9507f98cSAndroid Build Coastguard Worker padding-top:30px; 14*9507f98cSAndroid Build Coastguard Worker} 15*9507f98cSAndroid Build Coastguard Worker 16*9507f98cSAndroid Build Coastguard Workertable.bn { 17*9507f98cSAndroid Build Coastguard Worker width:800px; 18*9507f98cSAndroid Build Coastguard Worker border-collapse:collapse; 19*9507f98cSAndroid Build Coastguard Worker border:0; 20*9507f98cSAndroid Build Coastguard Worker padding:0; 21*9507f98cSAndroid Build Coastguard Worker} 22*9507f98cSAndroid Build Coastguard Worker 23*9507f98cSAndroid Build Coastguard Workertable.bnbase { 24*9507f98cSAndroid Build Coastguard Worker width:650px; 25*9507f98cSAndroid Build Coastguard Worker} 26*9507f98cSAndroid Build Coastguard Worker 27*9507f98cSAndroid Build Coastguard Workertable.bn td { 28*9507f98cSAndroid Build Coastguard Worker padding:2px 0; 29*9507f98cSAndroid Build Coastguard Worker} 30*9507f98cSAndroid Build Coastguard Worker 31*9507f98cSAndroid Build Coastguard Workertable.bn td.c1 { 32*9507f98cSAndroid Build Coastguard Worker font-weight:bold; 33*9507f98cSAndroid Build Coastguard Worker width:150px; 34*9507f98cSAndroid Build Coastguard Worker} 35*9507f98cSAndroid Build Coastguard Worker 36*9507f98cSAndroid Build Coastguard Workertable.bn td.c1 div.e { 37*9507f98cSAndroid Build Coastguard Worker float:right; 38*9507f98cSAndroid Build Coastguard Worker font-weight:normal; 39*9507f98cSAndroid Build Coastguard Worker} 40*9507f98cSAndroid Build Coastguard Worker 41*9507f98cSAndroid Build Coastguard Workertable.bn td.c2 { 42*9507f98cSAndroid Build Coastguard Worker width:150px; 43*9507f98cSAndroid Build Coastguard Worker text-align:right; 44*9507f98cSAndroid Build Coastguard Worker padding:2px; 45*9507f98cSAndroid Build Coastguard Worker} 46*9507f98cSAndroid Build Coastguard Worker 47*9507f98cSAndroid Build Coastguard Workertable.bn td.c3 { 48*9507f98cSAndroid Build Coastguard Worker width:350px; 49*9507f98cSAndroid Build Coastguard Worker} 50*9507f98cSAndroid Build Coastguard Worker 51*9507f98cSAndroid Build Coastguard Workertable.bn td.c4 { 52*9507f98cSAndroid Build Coastguard Worker width:150px; 53*9507f98cSAndroid Build Coastguard Worker font-size:small; 54*9507f98cSAndroid Build Coastguard Worker padding-left:4px; 55*9507f98cSAndroid Build Coastguard Worker} 56*9507f98cSAndroid Build Coastguard Worker 57*9507f98cSAndroid Build Coastguard Worker/* chart bars */ 58*9507f98cSAndroid Build Coastguard Workerdiv.bldb { 59*9507f98cSAndroid Build Coastguard Worker background-color:#0255df; 60*9507f98cSAndroid Build Coastguard Worker} 61*9507f98cSAndroid Build Coastguard Worker 62*9507f98cSAndroid Build Coastguard Workerdiv.bkct { 63*9507f98cSAndroid Build Coastguard Worker background-color:#df5555; 64*9507f98cSAndroid Build Coastguard Worker} 65*9507f98cSAndroid Build Coastguard Worker 66*9507f98cSAndroid Build Coastguard Workerdiv.bsql { 67*9507f98cSAndroid Build Coastguard Worker background-color:#aadf55; 68*9507f98cSAndroid Build Coastguard Worker} 69*9507f98cSAndroid Build Coastguard Worker 70*9507f98cSAndroid Build Coastguard Worker.code { 71*9507f98cSAndroid Build Coastguard Worker font-family:monospace; 72*9507f98cSAndroid Build Coastguard Worker font-size:large; 73*9507f98cSAndroid Build Coastguard Worker} 74*9507f98cSAndroid Build Coastguard Worker 75*9507f98cSAndroid Build Coastguard Worker.todo { 76*9507f98cSAndroid Build Coastguard Worker color: red; 77*9507f98cSAndroid Build Coastguard Worker} 78*9507f98cSAndroid Build Coastguard Worker 79*9507f98cSAndroid Build Coastguard Worker</style> 80*9507f98cSAndroid Build Coastguard Worker</head> 81*9507f98cSAndroid Build Coastguard Worker<body> 82*9507f98cSAndroid Build Coastguard Worker<h1>LevelDB Benchmarks</h1> 83*9507f98cSAndroid Build Coastguard Worker<p>Google, July 2011</p> 84*9507f98cSAndroid Build Coastguard Worker<hr> 85*9507f98cSAndroid Build Coastguard Worker 86*9507f98cSAndroid Build Coastguard Worker<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="https://www.sqlite.org/">SQLite3</a> (version 3.7.6.3) and <a href="https://dbmx.net/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*9507f98cSAndroid Build Coastguard Worker 88*9507f98cSAndroid Build Coastguard Worker<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*9507f98cSAndroid Build Coastguard Worker 90*9507f98cSAndroid Build Coastguard Worker<h4>Benchmark Source Code</h4> 91*9507f98cSAndroid Build Coastguard Worker<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*9507f98cSAndroid Build Coastguard Worker<ul> 93*9507f98cSAndroid Build Coastguard Worker <li> <b>LevelDB:</b> <a href="https://github.com/google/leveldb/blob/master/benchmarks/db_bench.cc">benchmarks/db_bench.cc</a>.</li> 94*9507f98cSAndroid Build Coastguard Worker <li> <b>SQLite:</b> <a href="https://github.com/google/leveldb/blob/master/benchmarks/db_bench_sqlite3.cc">benchmarks/db_bench_sqlite3.cc</a>.</li> 95*9507f98cSAndroid Build Coastguard Worker <li> <b>Kyoto TreeDB:</b> <a href="https://github.com/google/leveldb/blob/master/benchmarks/db_bench_tree_db.cc">benchmarks/db_bench_tree_db.cc</a>.</li> 96*9507f98cSAndroid Build Coastguard Worker</ul> 97*9507f98cSAndroid Build Coastguard Worker 98*9507f98cSAndroid Build Coastguard Worker<h4>Custom Build Specifications</h4> 99*9507f98cSAndroid Build Coastguard Worker<ul> 100*9507f98cSAndroid Build Coastguard Worker<li>LevelDB: LevelDB was compiled with the <a href="https://github.com/gperftools/gperftools">tcmalloc</a> library and the <a href="https://github.com/google/snappy">Snappy</a> compression library (revision 33). Assertions were disabled.</li> 101*9507f98cSAndroid Build Coastguard Worker<li>TreeDB: TreeDB was compiled using the <a href="https://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*9507f98cSAndroid Build Coastguard Worker<li>SQLite: We tuned SQLite's performance, by setting its locking mode to exclusive. We also enabled SQLite's <a href="https://www.sqlite.org/draft/wal.html">write-ahead logging</a>.</li> 103*9507f98cSAndroid Build Coastguard Worker</ul> 104*9507f98cSAndroid Build Coastguard Worker 105*9507f98cSAndroid Build Coastguard Worker<h2>1. Baseline Performance</h2> 106*9507f98cSAndroid Build Coastguard Worker<p>This section gives the baseline performance of all the 107*9507f98cSAndroid Build Coastguard Workerdatabases. Following sections show how performance changes as various 108*9507f98cSAndroid Build Coastguard Workerparameters are varied. For the baseline:</p> 109*9507f98cSAndroid Build Coastguard Worker<ul> 110*9507f98cSAndroid Build Coastguard Worker <li> Each database is allowed 4 MB of cache memory.</li> 111*9507f98cSAndroid Build Coastguard Worker <li> Databases are opened in <em>asynchronous</em> write mode. 112*9507f98cSAndroid Build Coastguard Worker (LevelDB's sync option, TreeDB's OAUTOSYNC option, and 113*9507f98cSAndroid Build Coastguard Worker SQLite3's synchronous options are all turned off). I.e., 114*9507f98cSAndroid Build Coastguard Worker every write is pushed to the operating system, but the 115*9507f98cSAndroid Build Coastguard Worker benchmark does not wait for the write to reach the disk.</li> 116*9507f98cSAndroid Build Coastguard Worker <li> Keys are 16 bytes each.</li> 117*9507f98cSAndroid Build Coastguard Worker <li> Value are 100 bytes each (with enough redundancy so that 118*9507f98cSAndroid Build Coastguard Worker a simple compressor shrinks them to 50% of their original 119*9507f98cSAndroid Build Coastguard Worker size).</li> 120*9507f98cSAndroid Build Coastguard Worker <li> Sequential reads/writes traverse the key space in increasing order.</li> 121*9507f98cSAndroid Build Coastguard Worker <li> Random reads/writes traverse the key space in random order.</li> 122*9507f98cSAndroid Build Coastguard Worker</ul> 123*9507f98cSAndroid Build Coastguard Worker 124*9507f98cSAndroid Build Coastguard Worker<h3>A. Sequential Reads</h3> 125*9507f98cSAndroid Build Coastguard Worker<table class="bn bnbase"> 126*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 127*9507f98cSAndroid Build Coastguard Worker <td class="c2">4,030,000 ops/sec</td> 128*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 129*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 130*9507f98cSAndroid Build Coastguard Worker <td class="c2">1,010,000 ops/sec</td> 131*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:95px"> </div></td> 132*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 133*9507f98cSAndroid Build Coastguard Worker <td class="c2">383,000 ops/sec</td> 134*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:33px"> </div></td> 135*9507f98cSAndroid Build Coastguard Worker</table> 136*9507f98cSAndroid Build Coastguard Worker<h3>B. Random Reads</h3> 137*9507f98cSAndroid Build Coastguard Worker<table class="bn bnbase"> 138*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 139*9507f98cSAndroid Build Coastguard Worker <td class="c2">129,000 ops/sec</td> 140*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:298px"> </div></td> 141*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 142*9507f98cSAndroid Build Coastguard Worker <td class="c2">151,000 ops/sec</td> 143*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:350px"> </div></td> 144*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 145*9507f98cSAndroid Build Coastguard Worker <td class="c2">134,000 ops/sec</td> 146*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:310px"> </div></td> 147*9507f98cSAndroid Build Coastguard Worker</table> 148*9507f98cSAndroid Build Coastguard Worker<h3>C. Sequential Writes</h3> 149*9507f98cSAndroid Build Coastguard Worker<table class="bn bnbase"> 150*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 151*9507f98cSAndroid Build Coastguard Worker <td class="c2">779,000 ops/sec</td> 152*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 153*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 154*9507f98cSAndroid Build Coastguard Worker <td class="c2">342,000 ops/sec</td> 155*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:154px"> </div></td> 156*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 157*9507f98cSAndroid Build Coastguard Worker <td class="c2">48,600 ops/sec</td> 158*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:22px"> </div></td> 159*9507f98cSAndroid Build Coastguard Worker</table> 160*9507f98cSAndroid Build Coastguard Worker<h3>D. Random Writes</h3> 161*9507f98cSAndroid Build Coastguard Worker<table class="bn bnbase"> 162*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 163*9507f98cSAndroid Build Coastguard Worker <td class="c2">164,000 ops/sec</td> 164*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 165*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 166*9507f98cSAndroid Build Coastguard Worker <td class="c2">88,500 ops/sec</td> 167*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:188px"> </div></td> 168*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 169*9507f98cSAndroid Build Coastguard Worker <td class="c2">9,860 ops/sec</td> 170*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:21px"> </div></td> 171*9507f98cSAndroid Build Coastguard Worker</table> 172*9507f98cSAndroid Build Coastguard Worker 173*9507f98cSAndroid Build Coastguard Worker<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*9507f98cSAndroid Build Coastguard Worker 175*9507f98cSAndroid Build Coastguard Worker<h2>2. Write Performance under Different Configurations</h2> 176*9507f98cSAndroid Build Coastguard Worker<h3>A. Large Values </h3> 177*9507f98cSAndroid Build Coastguard Worker<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*9507f98cSAndroid Build Coastguard Worker<h4>Sequential Writes</h4> 179*9507f98cSAndroid Build Coastguard Worker<table class="bn bnbase"> 180*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 181*9507f98cSAndroid Build Coastguard Worker <td class="c2">1,100 ops/sec</td> 182*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:234px"> </div></td></tr> 183*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 184*9507f98cSAndroid Build Coastguard Worker <td class="c2">1,000 ops/sec</td> 185*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:224px"> </div></td></tr> 186*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 187*9507f98cSAndroid Build Coastguard Worker <td class="c2">1,600 ops/sec</td> 188*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:350px"> </div></td></tr> 189*9507f98cSAndroid Build Coastguard Worker</table> 190*9507f98cSAndroid Build Coastguard Worker<h4>Random Writes</h4> 191*9507f98cSAndroid Build Coastguard Worker<table class="bn bnbase"> 192*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 193*9507f98cSAndroid Build Coastguard Worker <td class="c2">480 ops/sec</td> 194*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:105px"> </div></td></tr> 195*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 196*9507f98cSAndroid Build Coastguard Worker <td class="c2">1,100 ops/sec</td> 197*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:240px"> </div></td></tr> 198*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 199*9507f98cSAndroid Build Coastguard Worker <td class="c2">1,600 ops/sec</td> 200*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:350px"> </div></td></tr> 201*9507f98cSAndroid Build Coastguard Worker</table> 202*9507f98cSAndroid Build Coastguard Worker<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*9507f98cSAndroid Build Coastguard WorkerWith larger values, LevelDB's per-operation efficiency is swamped by the 204*9507f98cSAndroid Build Coastguard Workercost of extra copies of large values.</p> 205*9507f98cSAndroid Build Coastguard Worker<h3>B. Batch Writes</h3> 206*9507f98cSAndroid Build Coastguard Worker<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*9507f98cSAndroid Build Coastguard Worker<h4>Sequential Writes</h4> 208*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 209*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 210*9507f98cSAndroid Build Coastguard Worker <td class="c2">840,000 entries/sec</td> 211*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 212*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.08x baseline)</td></tr> 213*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 214*9507f98cSAndroid Build Coastguard Worker <td class="c2">124,000 entries/sec</td> 215*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:52px"> </div></td> 216*9507f98cSAndroid Build Coastguard Worker <td class="c4">(2.55x baseline)</td></tr> 217*9507f98cSAndroid Build Coastguard Worker</table> 218*9507f98cSAndroid Build Coastguard Worker<h4>Random Writes</h4> 219*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 220*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 221*9507f98cSAndroid Build Coastguard Worker <td class="c2">221,000 entries/sec</td> 222*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 223*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.35x baseline)</td></tr> 224*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 225*9507f98cSAndroid Build Coastguard Worker <td class="c2">22,000 entries/sec</td> 226*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:34px"> </div></td> 227*9507f98cSAndroid Build Coastguard Worker <td class="c4">(2.23x baseline)</td></tr> 228*9507f98cSAndroid Build Coastguard Worker</table> 229*9507f98cSAndroid Build Coastguard Worker 230*9507f98cSAndroid Build Coastguard Worker<p>Because of the way LevelDB persistent storage is organized, batches of 231*9507f98cSAndroid Build Coastguard Workerrandom writes are not much slower (only a factor of 4x) than batches 232*9507f98cSAndroid Build Coastguard Workerof sequential writes.</p> 233*9507f98cSAndroid Build Coastguard Worker 234*9507f98cSAndroid Build Coastguard Worker<h3>C. Synchronous Writes</h3> 235*9507f98cSAndroid Build Coastguard Worker<p>In the following benchmark, we enable the synchronous writing modes 236*9507f98cSAndroid Build Coastguard Workerof all of the databases. Since this change significantly slows down the 237*9507f98cSAndroid Build Coastguard Workerbenchmark, we stop after 10,000 writes. For synchronous write tests, we've 238*9507f98cSAndroid Build Coastguard Workerdisabled hard drive write-caching (using `hdparm -W 0 [device]`).</p> 239*9507f98cSAndroid Build Coastguard Worker<ul> 240*9507f98cSAndroid Build Coastguard Worker <li>For LevelDB, we set WriteOptions.sync = true.</li> 241*9507f98cSAndroid Build Coastguard Worker <li>In TreeDB, we enabled TreeDB's OAUTOSYNC option.</li> 242*9507f98cSAndroid Build Coastguard Worker <li>For SQLite3, we set "PRAGMA synchronous = FULL".</li> 243*9507f98cSAndroid Build Coastguard Worker</ul> 244*9507f98cSAndroid Build Coastguard Worker<h4>Sequential Writes</h4> 245*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 246*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 247*9507f98cSAndroid Build Coastguard Worker <td class="c2">100 ops/sec</td> 248*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 249*9507f98cSAndroid Build Coastguard Worker <td class="c4">(0.003x baseline)</td></tr> 250*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 251*9507f98cSAndroid Build Coastguard Worker <td class="c2">7 ops/sec</td> 252*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:27px"> </div></td> 253*9507f98cSAndroid Build Coastguard Worker <td class="c4">(0.0004x baseline)</td></tr> 254*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 255*9507f98cSAndroid Build Coastguard Worker <td class="c2">88 ops/sec</td> 256*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:315px"> </div></td> 257*9507f98cSAndroid Build Coastguard Worker <td class="c4">(0.002x baseline)</td></tr> 258*9507f98cSAndroid Build Coastguard Worker</table> 259*9507f98cSAndroid Build Coastguard Worker<h4>Random Writes</h4> 260*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 261*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 262*9507f98cSAndroid Build Coastguard Worker <td class="c2">100 ops/sec</td> 263*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 264*9507f98cSAndroid Build Coastguard Worker <td class="c4">(0.015x baseline)</td></tr> 265*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 266*9507f98cSAndroid Build Coastguard Worker <td class="c2">8 ops/sec</td> 267*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:29px"> </div></td> 268*9507f98cSAndroid Build Coastguard Worker <td class="c4">(0.001x baseline)</td></tr> 269*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 270*9507f98cSAndroid Build Coastguard Worker <td class="c2">88 ops/sec</td> 271*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:314px"> </div></td> 272*9507f98cSAndroid Build Coastguard Worker <td class="c4">(0.009x baseline)</td></tr> 273*9507f98cSAndroid Build Coastguard Worker</table> 274*9507f98cSAndroid Build Coastguard Worker 275*9507f98cSAndroid Build Coastguard Worker<p>Also see the <code>ext4</code> performance numbers below 276*9507f98cSAndroid Build Coastguard Workersince synchronous writes behave significantly differently 277*9507f98cSAndroid Build Coastguard Workeron <code>ext3</code> and <code>ext4</code>.</p> 278*9507f98cSAndroid Build Coastguard Worker 279*9507f98cSAndroid Build Coastguard Worker<h3>D. Turning Compression Off</h3> 280*9507f98cSAndroid Build Coastguard Worker 281*9507f98cSAndroid Build Coastguard Worker<p>In the baseline measurements, LevelDB and TreeDB were using 282*9507f98cSAndroid Build Coastguard Workerlight-weight compression 283*9507f98cSAndroid Build Coastguard Worker(<a href="http://code.google.com/p/snappy/">Snappy</a> for LevelDB, 284*9507f98cSAndroid Build Coastguard Workerand <a href="http://www.oberhumer.com/opensource/lzo/">LZO</a> for 285*9507f98cSAndroid Build Coastguard WorkerTreeDB). SQLite3, by default does not use compression. The 286*9507f98cSAndroid Build Coastguard Workerexperiments below show what happens when compression is disabled in 287*9507f98cSAndroid Build Coastguard Workerall of the databases (the SQLite3 numbers are just a copy of 288*9507f98cSAndroid Build Coastguard Workerits baseline measurements):</p> 289*9507f98cSAndroid Build Coastguard Worker 290*9507f98cSAndroid Build Coastguard Worker<h4>Sequential Writes</h4> 291*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 292*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 293*9507f98cSAndroid Build Coastguard Worker <td class="c2">594,000 ops/sec</td> 294*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 295*9507f98cSAndroid Build Coastguard Worker <td class="c4">(0.76x baseline)</td></tr> 296*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 297*9507f98cSAndroid Build Coastguard Worker <td class="c2">485,000 ops/sec</td> 298*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:239px"> </div></td> 299*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.42x baseline)</td></tr> 300*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 301*9507f98cSAndroid Build Coastguard Worker <td class="c2">48,600 ops/sec</td> 302*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:29px"> </div></td> 303*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.00x baseline)</td></tr> 304*9507f98cSAndroid Build Coastguard Worker</table> 305*9507f98cSAndroid Build Coastguard Worker<h4>Random Writes</h4> 306*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 307*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 308*9507f98cSAndroid Build Coastguard Worker <td class="c2">135,000 ops/sec</td> 309*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:296px"> </div></td> 310*9507f98cSAndroid Build Coastguard Worker <td class="c4">(0.82x baseline)</td></tr> 311*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 312*9507f98cSAndroid Build Coastguard Worker <td class="c2">159,000 ops/sec</td> 313*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:350px"> </div></td> 314*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.80x baseline)</td></tr> 315*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 316*9507f98cSAndroid Build Coastguard Worker <td class="c2">9,860 ops/sec</td> 317*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:22px"> </div></td> 318*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.00x baseline)</td></tr> 319*9507f98cSAndroid Build Coastguard Worker</table> 320*9507f98cSAndroid Build Coastguard Worker 321*9507f98cSAndroid Build Coastguard Worker<p>LevelDB's write performance is better with compression than without 322*9507f98cSAndroid Build Coastguard Workersince compression decreases the amount of data that has to be written 323*9507f98cSAndroid Build Coastguard Workerto disk. Therefore LevelDB users can leave compression enabled in 324*9507f98cSAndroid Build Coastguard Workermost scenarios without having worry about a tradeoff between space 325*9507f98cSAndroid Build Coastguard Workerusage and performance. TreeDB's performance on the other hand is 326*9507f98cSAndroid Build Coastguard Workerbetter without compression than with compression. Presumably this is 327*9507f98cSAndroid Build Coastguard Workerbecause TreeDB's compression library (LZO) is more expensive than 328*9507f98cSAndroid Build Coastguard WorkerLevelDB's compression library (Snappy).<p> 329*9507f98cSAndroid Build Coastguard Worker 330*9507f98cSAndroid Build Coastguard Worker<h3>E. Using More Memory</h3> 331*9507f98cSAndroid Build Coastguard Worker<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*9507f98cSAndroid Build Coastguard Worker<h4>Sequential Writes</h4> 333*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 334*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 335*9507f98cSAndroid Build Coastguard Worker <td class="c2">812,000 ops/sec</td> 336*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 337*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.04x baseline)</td></tr> 338*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 339*9507f98cSAndroid Build Coastguard Worker <td class="c2">321,000 ops/sec</td> 340*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:138px"> </div></td> 341*9507f98cSAndroid Build Coastguard Worker <td class="c4">(0.94x baseline)</td></tr> 342*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 343*9507f98cSAndroid Build Coastguard Worker <td class="c2">48,500 ops/sec</td> 344*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:21px"> </div></td> 345*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.00x baseline)</td></tr> 346*9507f98cSAndroid Build Coastguard Worker</table> 347*9507f98cSAndroid Build Coastguard Worker<h4>Random Writes</h4> 348*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 349*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 350*9507f98cSAndroid Build Coastguard Worker <td class="c2">355,000 ops/sec</td> 351*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 352*9507f98cSAndroid Build Coastguard Worker <td class="c4">(2.16x baseline)</td></tr> 353*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 354*9507f98cSAndroid Build Coastguard Worker <td class="c2">284,000 ops/sec</td> 355*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:280px"> </div></td> 356*9507f98cSAndroid Build Coastguard Worker <td class="c4">(3.21x baseline)</td></tr> 357*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 358*9507f98cSAndroid Build Coastguard Worker <td class="c2">9,670 ops/sec</td> 359*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:10px"> </div></td> 360*9507f98cSAndroid Build Coastguard Worker <td class="c4">(0.98x baseline)</td></tr> 361*9507f98cSAndroid Build Coastguard Worker</table> 362*9507f98cSAndroid Build Coastguard Worker 363*9507f98cSAndroid Build Coastguard Worker<p>SQLite's performance does not change substantially when compared to 364*9507f98cSAndroid Build Coastguard Workerthe baseline, but the random write performance for both LevelDB and 365*9507f98cSAndroid Build Coastguard WorkerTreeDB increases significantly. LevelDB's performance improves 366*9507f98cSAndroid Build Coastguard Workerbecause a larger write buffer reduces the need to merge sorted files 367*9507f98cSAndroid Build Coastguard Worker(since it creates a smaller number of larger sorted files). TreeDB's 368*9507f98cSAndroid Build Coastguard Workerperformance goes up because the entire database is available in memory 369*9507f98cSAndroid Build Coastguard Workerfor fast in-place updates.</p> 370*9507f98cSAndroid Build Coastguard Worker 371*9507f98cSAndroid Build Coastguard Worker <h2>3. Read Performance under Different Configurations</h2> 372*9507f98cSAndroid Build Coastguard Worker<h3>A. Larger Caches</h3> 373*9507f98cSAndroid Build Coastguard Worker<p>We increased the overall memory usage to 128 MB for each database. 374*9507f98cSAndroid Build Coastguard WorkerFor LevelDB, we allocated 8 MB to LevelDB's write buffer and 120 MB 375*9507f98cSAndroid Build Coastguard Workerto LevelDB's cache. The other databases don't differentiate between a 376*9507f98cSAndroid Build Coastguard Workerwrite buffer and a cache, so we simply set their cache size to 128 377*9507f98cSAndroid Build Coastguard WorkerMB.</p> 378*9507f98cSAndroid Build Coastguard Worker<h4>Sequential Reads</h4> 379*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 380*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 381*9507f98cSAndroid Build Coastguard Worker <td class="c2">5,210,000 ops/sec</td> 382*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 383*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.29x baseline)</td></tr> 384*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 385*9507f98cSAndroid Build Coastguard Worker <td class="c2">1,070,000 ops/sec</td> 386*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:72px"> </div></td> 387*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.06x baseline)</td></tr> 388*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 389*9507f98cSAndroid Build Coastguard Worker <td class="c2">609,000 ops/sec</td> 390*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:41px"> </div></td> 391*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.59x baseline)</td></tr> 392*9507f98cSAndroid Build Coastguard Worker</table> 393*9507f98cSAndroid Build Coastguard Worker 394*9507f98cSAndroid Build Coastguard Worker<h4>Random Reads</h4> 395*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 396*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 397*9507f98cSAndroid Build Coastguard Worker <td class="c2">190,000 ops/sec</td> 398*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:144px"> </div></td> 399*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.47x baseline)</td></tr> 400*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 401*9507f98cSAndroid Build Coastguard Worker <td class="c2">463,000 ops/sec</td> 402*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:350px"> </div></td> 403*9507f98cSAndroid Build Coastguard Worker <td class="c4">(3.07x baseline)</td></tr> 404*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 405*9507f98cSAndroid Build Coastguard Worker <td class="c2">186,000 ops/sec</td> 406*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:141px"> </div></td> 407*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.39x baseline)</td></tr> 408*9507f98cSAndroid Build Coastguard Worker</table> 409*9507f98cSAndroid Build Coastguard Worker 410*9507f98cSAndroid Build Coastguard Worker<p>As expected, the read performance of all of the databases increases 411*9507f98cSAndroid Build Coastguard Workerwhen the caches are enlarged. In particular, TreeDB seems to make 412*9507f98cSAndroid Build Coastguard Workervery effective use of a cache that is large enough to hold the entire 413*9507f98cSAndroid Build Coastguard Workerdatabase.</p> 414*9507f98cSAndroid Build Coastguard Worker 415*9507f98cSAndroid Build Coastguard Worker<h3>B. No Compression Reads </h3> 416*9507f98cSAndroid Build Coastguard Worker<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*9507f98cSAndroid Build Coastguard Worker<h4>Sequential Reads</h4> 418*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 419*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 420*9507f98cSAndroid Build Coastguard Worker <td class="c2">4,880,000 ops/sec</td> 421*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:350px"> </div></td> 422*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.21x baseline)</td></tr> 423*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 424*9507f98cSAndroid Build Coastguard Worker <td class="c2">1,230,000 ops/sec</td> 425*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:88px"> </div></td> 426*9507f98cSAndroid Build Coastguard Worker <td class="c4">(3.60x baseline)</td></tr> 427*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 428*9507f98cSAndroid Build Coastguard Worker <td class="c2">383,000 ops/sec</td> 429*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:27px"> </div></td> 430*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.00x baseline)</td></tr> 431*9507f98cSAndroid Build Coastguard Worker</table> 432*9507f98cSAndroid Build Coastguard Worker<h4>Random Reads</h4> 433*9507f98cSAndroid Build Coastguard Worker<table class="bn"> 434*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">LevelDB</td> 435*9507f98cSAndroid Build Coastguard Worker <td class="c2">149,000 ops/sec</td> 436*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bldb" style="width:300px"> </div></td> 437*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.16x baseline)</td></tr> 438*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">Kyoto TreeDB</td> 439*9507f98cSAndroid Build Coastguard Worker <td class="c2">175,000 ops/sec</td> 440*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bkct" style="width:350px"> </div></td> 441*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.16x baseline)</td></tr> 442*9507f98cSAndroid Build Coastguard Worker<tr><td class="c1">SQLite3</td> 443*9507f98cSAndroid Build Coastguard Worker <td class="c2">134,000 ops/sec</td> 444*9507f98cSAndroid Build Coastguard Worker <td class="c3"><div class="bsql" style="width:268px"> </div></td> 445*9507f98cSAndroid Build Coastguard Worker <td class="c4">(1.00x baseline)</td></tr> 446*9507f98cSAndroid Build Coastguard Worker</table> 447*9507f98cSAndroid Build Coastguard Worker 448*9507f98cSAndroid Build Coastguard Worker<p>Performance of both LevelDB and TreeDB improves a small amount when 449*9507f98cSAndroid Build Coastguard Workercompression is disabled. Note however that under different workloads, 450*9507f98cSAndroid Build Coastguard Workerperformance may very well be better with compression if it allows more 451*9507f98cSAndroid Build Coastguard Workerof the working set to fit in memory.</p> 452*9507f98cSAndroid Build Coastguard Worker 453*9507f98cSAndroid Build Coastguard Worker<h2>Note about Ext4 Filesystems</h2> 454*9507f98cSAndroid Build Coastguard Worker<p>The preceding numbers are for an ext3 file system. Synchronous writes are much slower under <a href="https://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*9507f98cSAndroid Build Coastguard Worker 456*9507f98cSAndroid Build Coastguard Worker<h2>Acknowledgements</h2> 457*9507f98cSAndroid Build Coastguard Worker<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*9507f98cSAndroid Build Coastguard Worker</body> 459*9507f98cSAndroid Build Coastguard Worker</html> 460