Debian Codegraph @

www/fasterthanfs.html

raw
1 <!DOCTYPE html>
2 <html><head>
3 <meta name="viewport" content="width=device-width, initial-scale=1.0">
4 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5 <link href="sqlite.css" rel="stylesheet">
6 <title>35% Faster Than The Filesystem</title>
7 <!-- path= -->
8 </head>
9 <body>
10 <div class=nosearch>
11 <a href="index.html">
12 <img class="logo" src="images/sqlite370_banner.gif" alt="SQLite" border="0">
13 </a>
14 <div><!-- IE hack to prevent disappearing logo --></div>
15 <div class="tagline desktoponly">
16 Small. Fast. Reliable.<br>Choose any three.
17 </div>
18 <div class="menu mainmenu">
19 <ul>
20 <li><a href="index.html">Home</a>
21 <li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
22 <li class='wideonly'><a href='about.html'>About</a>
23 <li class='desktoponly'><a href="docs.html">Documentation</a>
24 <li class='desktoponly'><a href="download.html">Download</a>
25 <li class='wideonly'><a href='copyright.html'>License</a>
26 <li class='desktoponly'><a href="support.html">Support</a>
27 <li class='desktoponly'><a href="prosupport.html">Purchase</a>
28 <li class='search' id='search_menubutton'>
29 <a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
30 </ul>
31 </div>
32 <div class="menu submenu" id="submenu">
33 <ul>
34 <li><a href='about.html'>About</a>
35 <li><a href='docs.html'>Documentation</a>
36 <li><a href='download.html'>Download</a>
37 <li><a href='support.html'>Support</a>
38 <li><a href='prosupport.html'>Purchase</a>
39 </ul>
40 </div>
41 <div class="searchmenu" id="searchmenu">
42 <form method="GET" action="search">
43 <select name="s" id="searchtype">
44 <option value="d">Search Documentation</option>
45 <option value="c">Search Changelog</option>
46 </select>
47 <input type="text" name="q" id="searchbox" value="">
48 <input type="submit" value="Go">
49 </form>
50 </div>
51 </div>
52 <script>
53 function toggle_div(nm) {
54 var w = document.getElementById(nm);
55 if( w.style.display=="block" ){
56 w.style.display = "none";
57 }else{
58 w.style.display = "block";
59 }
60 }
61 function toggle_search() {
62 var w = document.getElementById("searchmenu");
63 if( w.style.display=="block" ){
64 w.style.display = "none";
65 } else {
66 w.style.display = "block";
67 setTimeout(function(){
68 document.getElementById("searchbox").focus()
69 }, 30);
70 }
71 }
72 function div_off(nm){document.getElementById(nm).style.display="none";}
73 window.onbeforeunload = function(e){div_off("submenu");}
74 /* Disable the Search feature if we are not operating from CGI, since */
75 /* Search is accomplished using CGI and will not work without it. */
76 if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){
77 document.getElementById("search_menubutton").style.display = "none";
78 }
79 /* Used by the Hide/Show button beside syntax diagrams, to toggle the */
80 function hideorshow(btn,obj){
81 var x = document.getElementById(obj);
82 var b = document.getElementById(btn);
83 if( x.style.display!='none' ){
84 x.style.display = 'none';
85 b.innerHTML='show';
86 }else{
87 x.style.display = '';
88 b.innerHTML='hide';
89 }
90 return false;
91 }
92 var antiRobot = 0;
93 function antiRobotGo(){
94 if( antiRobot!=3 ) return;
95 antiRobot = 7;
96 var j = document.getElementById("mtimelink");
97 if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
98 }
99 function antiRobotDefense(){
100 document.body.onmousedown=function(){
101 antiRobot |= 2;
102 antiRobotGo();
103 document.body.onmousedown=null;
104 }
105 document.body.onmousemove=function(){
106 antiRobot |= 2;
107 antiRobotGo();
108 document.body.onmousemove=null;
109 }
110 setTimeout(function(){
111 antiRobot |= 1;
112 antiRobotGo();
113 }, 100)
114 antiRobotGo();
115 }
116 antiRobotDefense();
117 </script>
118 <div class=fancy>
119 <div class=nosearch>
120 <div class="fancy_title">
121 35% Faster Than The Filesystem
122 </div>
123 <div class="fancy_toc">
124 <a onclick="toggle_toc()">
125 <span class="fancy_toc_mark" id="toc_mk">&#x25ba;</span>
126 Table Of Contents
127 </a>
128 <div id="toc_sub"><div class="fancy-toc1"><a href="#summary">1. Summary</a></div>
129 <div class="fancy-toc2"><a href="#caveats">1.1. Caveats</a></div>
130 <div class="fancy-toc2"><a href="#related_studies">1.2. Related Studies</a></div>
131 <div class="fancy-toc1"><a href="#how_these_measurements_are_made">2. How These Measurements Are Made</a></div>
132 <div class="fancy-toc2"><a href="#read_performance_measurements">2.1. Read Performance Measurements</a></div>
133 <div class="fancy-toc2"><a href="#write_performance_measurements">2.2. Write Performance Measurements</a></div>
134 <div class="fancy-toc2"><a href="#variations">2.3. Variations</a></div>
135 <div class="fancy-toc1"><a href="#general_findings">3. General Findings</a></div>
136 <div class="fancy-toc1"><a href="#additional_notes">4. Additional Notes</a></div>
137 <div class="fancy-toc2"><a href="#compiling_and_testing_on_android">4.1. Compiling And Testing on Android</a></div>
138 </div>
139 </div>
140 <script>
141 function toggle_toc(){
142 var sub = document.getElementById("toc_sub")
143 var mk = document.getElementById("toc_mk")
144 if( sub.style.display!="block" ){
145 sub.style.display = "block";
146 mk.innerHTML = "&#x25bc;";
147 } else {
148 sub.style.display = "none";
149 mk.innerHTML = "&#x25ba;";
150 }
151 }
152 </script>
153 </div>
154
155
156
157
158
159 <h1 id="summary"><span>1. </span>Summary</h1>
160
161 <p>SQLite reads and writes small blobs (for example, thumbnail images)
162 <a href="#approx">35% faster&sup1;</a> than the same blobs
163 can be read from or written to individual files on disk using
164 fread() or fwrite().
165
166 </p><p>Furthermore, a single SQLite database holding
167 10-kilobyte blobs uses about 20% less disk space than
168 storing the blobs in individual files.
169
170 </p><p>The performance difference arises (we believe) because when
171 working from an SQLite database, the open() and close() system calls
172 are invoked only once, whereas
173 open() and close() are invoked once for each blob
174 when using blobs stored in individual files. It appears that the
175 overhead of calling open() and close() is greater than the overhead
176 of using the database. The size reduction arises from the fact that
177 individual files are padded out to the next multiple of the filesystem
178 block size, whereas the blobs are packed more tightly into an SQLite
179 database.
180
181 </p><p>
182 The measurements in this article were made during the week of 2017-06-05
183 using a version of SQLite in between 3.19.2 and 3.20.0. You may expect
184 future versions of SQLite to perform even better.
185
186 </p><h2 id="caveats"><span>1.1. </span>Caveats</h2>
187
188 <a name="approx"></a>
189 <p>
190 &sup1;The 35% figure above is approximate. Actual timings vary
191 depending on hardware, operating system, and the
192 details of the experiment, and due to random performance fluctuations
193 on real-world hardware. See the text below for more detail.
194 Try the experiments yourself. Report significant deviations on
195 the <a href="support.html#fx">SQLite forum</a>.
196 </p>
197
198 <p>
199 The 35% figure is based on running tests on every machine
200 that the author has easily at hand.
201 Some reviewers of this article report that SQLite has higher
202 latency than direct I/O on their systems. We do not yet understand
203 the difference. We also see indications that SQLite does not
204 perform as well as direct I/O when experiments are run using
205 a cold filesystem cache.
206
207 </p><p>
208 So let your take-away be this: read/write latency for
209 SQLite is competitive with read/write latency of individual files on
210 disk. Often SQLite is faster. Sometimes SQLite is almost
211 as fast. Either way, this article disproves the common
212 assumption that a relational database must be slower than direct
213 filesystem I/O.
214
215 </p><h2 id="related_studies"><span>1.2. </span>Related Studies</h2>
216
217 <p>
218 A <a href="https://golangexample.com/an-unscientific-benchmark-of-sqlite-vs-the-file-system-btrfs/">2022 study</a>
219 (<a href="https://github.com/chrisdavies/dbench">alternative link on GitHub</a>) found that
220 SQLite is <i>roughly</i> twice as fast at real-world workloads compared to Btrfs and Ext4 on Linux.
221
222 </p><p>
223 <a href="https://www.microsoft.com/en-us/research/people/gray/">Jim Gray</a>
224 and others studied the read performance of BLOBs
225 versus file I/O for Microsoft SQL Server and found that reading BLOBs
226 out of the
227 database was faster for BLOB sizes less than between 250KiB and 1MiB.
228 (<a href="https://www.microsoft.com/en-us/research/publication/to-blob-or-not-to-blob-large-object-storage-in-a-database-or-a-filesystem/">Paper</a>).
229 In that study, the database still stores the filename of the content even
230 if the content is held in a separate file. So the database is consulted
231 for every BLOB, even if it is only to extract the filename. In this
232 article, the key for the BLOB is the filename, so no preliminary database
233 access is required. Because the database is never used at all when
234 reading content from individual files in this article, the threshold
235 at which direct file I/O becomes faster is smaller than it is in Gray's
236 paper.
237
238 </p><p>
239 The <a href="intern-v-extern-blob.html">Internal Versus External BLOBs</a> article on this website is an
240 earlier investigation (circa 2011) that uses the same approach as the
241 Jim Gray paper &mdash; storing the blob filenames as entries in the
242 database &mdash; but for SQLite instead of SQL Server.
243
244
245
246 </p><h1 id="how_these_measurements_are_made"><span>2. </span>How These Measurements Are Made</h1>
247
248 <p>I/O performance is measured using the
249 <a href="https://www.sqlite.org/src/file/test/kvtest.c">kvtest.c</a> program
250 from the SQLite source tree.
251 To compile this test program, first gather the kvtest.c source file
252 into a directory with the <a href="amalgamation.html">SQLite amalgamation</a> source
253 files "sqlite3.c" and "sqlite3.h". Then on unix, run a command like
254 the following:
255
256 </p><div class="codeblock"><pre>gcc -Os -I. -DSQLITE_DIRECT_OVERFLOW_READ &#92;
257 kvtest.c sqlite3.c -o kvtest -ldl -lpthread
258 </pre></div>
259
260 <p>Or on Windows with MSVC:
261
262 </p><div class="codeblock"><pre>cl -I. -DSQLITE_DIRECT_OVERFLOW_READ kvtest.c sqlite3.c
263 </pre></div>
264
265 <p>Instructions for compiling for Android
266 are <a href="#compile-android">shown below</a>.
267
268 </p><p>
269 Use the resulting "kvtest" program to
270 generate a test database with 100,000 random uncompressible
271 blobs, each with a random
272 size between 8,000 and 12,000 bytes
273 using a command like this:
274
275 </p><div class="codeblock"><pre>./kvtest init test1.db --count 100k --size 10k --variance 2k
276 </pre></div>
277
278 <p>
279 If desired, you can verify the new database by running this command:
280
281 </p><div class="codeblock"><pre>./kvtest stat test1.db
282 </pre></div>
283
284 <p>
285 Next, make copies of all the blobs into individual files in a directory
286 using a command like this:
287
288 </p><div class="codeblock"><pre>./kvtest export test1.db test1.dir
289 </pre></div>
290
291 <p>
292 At this point, you can measure the amount of disk space used by
293 the test1.db database and the space used by the test1.dir directory
294 and all of its content. On a standard Ubuntu Linux desktop, the
295 database file will be 1,024,512,000 bytes in size and the test1.dir
296 directory will use 1,228,800,000 bytes of space (according to "du -k"),
297 about 20% more than the database.
298
299 </p><p>
300 The "test1.dir" directory created above puts all the blobs into a single
301 folder. It was conjectured that some operating systems would perform
302 poorly when a single directory contains 100,000 objects. To test this,
303 the kvtest program can also store the blobs in a hierarchy of folders with no
304 more than 100 files and/or subdirectories per folder. The alternative
305 on-disk representation of the blobs can be created using the --tree
306 command-line option to the "export" command, like this:
307
308 </p><div class="codeblock"><pre>./kvtest export test1.db test1.tree --tree
309 </pre></div>
310
311 <p>
312 The test1.dir directory will contain 100,000 files
313 with names like "000000", "000001", "000002" and so forth but the
314 test1.tree directory will contain the same files in subdirectories like
315 "00/00/00", "00/00/01", and so on. The test1.dir and test1.test
316 directories take up approximately the same amount of space, though
317 test1.test is very slightly larger due to the extra directory entries.
318
319 </p><p>
320 All of the experiments that follow operate the same with either
321 "test1.dir" or "test1.tree". Very little performance difference is
322 measured in either case, regardless of operating system.
323
324 </p><p>
325 Measure the performance for reading blobs from the database and from
326 individual files using these commands:
327
328 </p><div class="codeblock"><pre>./kvtest run test1.db --count 100k --blob-api
329 ./kvtest run test1.dir --count 100k --blob-api
330 ./kvtest run test1.tree --count 100k --blob-api
331 </pre></div>
332
333 <p>
334 Depending on your hardware and operating system, you should see that reads
335 from the test1.db database file are about 35% faster than reads from
336 individual files in the test1.dir or test1.tree folders. Results can vary
337 significantly from one run to the next due to caching, so it is advisable
338 to run tests multiple times and take an average or a worst case or a best
339 case, depending on your requirements.
340
341 </p><p>The --blob-api option on the database read test causes kvtest to use
342 the <a href="c3ref/blob_read.html">sqlite3_blob_read()</a> feature of SQLite to load the content of the
343 blobs, rather than running pure SQL statements. This helps SQLite to run
344 a little faster on read tests. You can omit that option to compare the
345 performance of SQLite running SQL statements.
346 In that case, the SQLite still out-performs direct reads, though
347 by not as much as when using <a href="c3ref/blob_read.html">sqlite3_blob_read()</a>.
348 The --blob-api option is ignored for tests that read from individual disk
349 files.
350
351 </p><p>
352 Measure write performance by adding the --update option. This causes
353 the blobs are overwritten in place with another random blob of
354 exactly the same size.
355
356 </p><div class="codeblock"><pre>./kvtest run test1.db --count 100k --update
357 ./kvtest run test1.dir --count 100k --update
358 ./kvtest run test1.tree --count 100k --update
359 </pre></div>
360
361 <p>
362 The writing test above is not completely fair, since SQLite is doing
363 <a href="transactional.html">power-safe transactions</a> whereas the direct-to-disk writing is not.
364 To put the tests on a more equal footing, add either the --nosync
365 option to the SQLite writes to disable calling fsync() or
366 FlushFileBuffers() to force content to disk, or using the --fsync option
367 for the direct-to-disk tests to force them to invoke fsync() or
368 FlushFileBuffers() when updating disk files.
369
370 </p><p>
371 By default, kvtest runs the database I/O measurements all within
372 a single transaction. Use the --multitrans option to run each blob
373 read or write in a separate transaction. The --multitrans option makes
374 SQLite much slower, and uncompetitive with direct disk I/O. This
375 option proves, yet again, that to get the most performance out of
376 SQLite, you should group as much database interaction as possible within
377 a single transaction.
378
379 </p><p>
380 There are many other testing options, which can be seen by running
381 the command:
382
383 </p><div class="codeblock"><pre>./kvtest help
384 </pre></div>
385
386 <h2 id="read_performance_measurements"><span>2.1. </span>Read Performance Measurements</h2>
387
388 <p>The chart below shows data collected using
389 <a href="https://www.sqlite.org/src/file/test/kvtest.c">kvtest.c</a> on five different
390 systems:
391
392 </p><ul>
393 <li><b>Win7</b>: A circa-2009 Dell Inspiron laptop, Pentium dual-core
394 at 2.30GHz, 4GiB RAM, Windows7.
395 </li><li><b>Win10</b>: A 2016 Lenovo YOGA 910, Intel i7-7500 at 2.70GHz,
396 16GiB RAM, Windows10.
397 </li><li><b>Mac</b>: A 2015 MacBook Pro, 3.1GHz intel Core i7, 16GiB RAM,
398 MacOS 10.12.5
399 </li><li><b>Ubuntu</b>: Desktop built from Intel i7-4770K at 3.50GHz, 32GiB RAM,
400 Ubuntu 16.04.2 LTS
401 </li><li><b>Android</b>: Galaxy S3, ARMv7, 2GiB RAM
402 </li></ul>
403
404 <p>All machines use SSD except Win7 which has a
405 hard-drive. The test database is 100K blobs with sizes uniformly
406 distributed between 8K and 12K, for a total of about 1 gigabyte
407 of content. The database page size
408 is 4KiB. The -DSQLITE_DIRECT_OVERFLOW_READ compile-time option was
409 used for all of these tests.
410 Tests were run multiple times.
411 The first run was used to warm up the cache and its timings were discarded.
412
413 </p><p>
414 The chart below shows average time to read a blob directly from the
415 filesystem versus the time needed to read the same blob from the SQLite
416 database.
417 The actual timings vary considerably from one system to another
418 (the Ubuntu desktop is much
419 faster than the Galaxy S3 phone, for example).
420 This chart shows the ratio of the
421 times needed to read blobs from a file divided by the time needed to
422 from the database. The left-most column in the chart is the normalized
423 time to read from the database, for reference.
424
425 </p><p>
426 In this chart, an SQL statement ("SELECT v FROM kv WHERE k=?1")
427 is prepared once. Then for each blob, the blob key value is bound
428 to the ?1 parameter and the statement is evaluated to extract the
429 blob content.
430
431 </p><p>
432 The chart shows that on Windows10, content can be read from the SQLite
433 database about 5 times faster than it can be read directly from disk.
434 On Android, SQLite is only about 35% faster than reading from disk.
435
436 </p><center>
437 <div class="imgcontainer">
438 <img src="images/faster-read-sql.jpg">
439 </div>
440 <br>
441 Chart 1: SQLite read latency relative to direct filesystem reads.<br>
442 100K blobs, avg 10KB each, random order using SQL
443 </center>
444
445 <p>
446 The performance can be improved slightly by bypassing the SQL layer
447 and reading the blob content directly using the
448 <a href="c3ref/blob_read.html">sqlite3_blob_read()</a> interface, as shown in the next chart:
449
450 </p><center>
451 <div class="imgcontainer">
452 <img src="images/faster-read-blobapi.jpg">
453 </div>
454 <br>
455 Chart 2: SQLite read latency relative to direct filesystem reads.<br>
456 100K blobs, avg size 10KB, random order<br>
457 using sqlite3_blob_read().
458 </center>
459
460 <p>
461 Further performance improves can be made by using the
462 <a href="mmap.html">memory-mapped I/O</a> feature of SQLite. In the next chart, the
463 entire 1GB database file is memory mapped and blobs are read
464 (in random order) using the <a href="c3ref/blob_read.html">sqlite3_blob_read()</a> interface.
465 With these optimizations, SQLite is twice as fast as Android
466 or MacOS-X and over 10 times faster than Windows.
467
468 </p><center>
469 <div class="imgcontainer">
470 <img src="images/faster-read-mmap.jpg">
471 </div>
472 <br>
473 Chart 3: SQLite read latency relative to direct filesystem reads.<br>
474 100K blobs, avg size 10KB, random order<br>
475 using sqlite3_blob_read() from a memory-mapped database.
476 </center>
477
478 <p>
479 The third chart shows that reading blob content out of SQLite can be
480 twice as fast as reading from individual files on disk for Mac and
481 Android, and an amazing ten times faster for Windows.
482
483 </p><h2 id="write_performance_measurements"><span>2.2. </span>Write Performance Measurements</h2>
484
485 <p>
486 Writes are slower.
487 On all systems, using both direct I/O and SQLite, write performance is
488 between 5 and 15 times slower than reads.
489
490 </p><p>
491 Write performance measurements were made by replacing (overwriting)
492 an entire blob with a different blob. All of the blobs in these
493 experiment are random and incompressible. Because writes are so much
494 slower than reads, only 10,000 of the 100,000 blobs in the database
495 are replaced. The blobs to be replaced are selected at random and
496 are in no particular order.
497
498 </p><p>
499 The direct-to-disk writes are accomplished using fopen()/fwrite()/fclose().
500 By default, and in all the results shown below, the OS filesystem buffers are
501 never flushed to persistent storage using fsync() or
502 FlushFileBuffers(). In other words, there is no attempt to make the
503 direct-to-disk writes transactional or power-safe.
504 We found that invoking fsync() or FlushFileBuffers() on each file
505 written causes direct-to-disk storage
506 to be about 10 times or more slower than writes to SQLite.
507
508 </p><p>
509 The next chart compares SQLite database updates in <a href="wal.html">WAL mode</a>
510 against raw direct-to-disk overwrites of separate files on disk.
511 The <a href="pragma.html#pragma_synchronous">PRAGMA synchronous</a> setting is NORMAL.
512 All database writes are in a single transaction.
513 The timer for the database writes is stopped after the transaction
514 commits, but before a <a href="wal.html#ckpt">checkpoint</a> is run.
515 Note that the SQLite writes, unlike the direct-to-disk writes,
516 are <a href="transactional.html">transactional</a> and <a href="transactional.html">power-safe</a>, though because the synchronous
517 setting is NORMAL instead of FULL, the transactions are not durable.
518
519 </p><center>
520 <div class="imgcontainer">
521 <img src="images/faster-write-safe.jpg">
522 </div>
523 <br>
524 Chart 4: SQLite write latency relative to direct filesystem writes.<br>
525 10K blobs, avg size 10KB, random order,<br>
526 WAL mode with synchronous NORMAL,<br>
527 exclusive of checkpoint time
528 </center>
529
530 <p>
531 The android performance numbers for the write experiments are omitted
532 because the performance tests on the Galaxy S3 are so random. Two
533 consecutive runs of the exact same experiment would give wildly different
534 times. And, to be fair, the performance of SQLite on android is slightly
535 slower than writing directly to disk.
536
537 </p><p>
538 The next chart shows the performance of SQLite versus direct-to-disk
539 when transactions are disabled (<a href="pragma.html#pragma_journal_mode">PRAGMA journal_mode=OFF</a>)
540 and <a href="pragma.html#pragma_synchronous">PRAGMA synchronous</a> is set to OFF. These settings put SQLite on an
541 equal footing with direct-to-disk writes, which is to say they make the
542 data prone to corruption due to system crashes and power failures.
543
544 </p><center>
545 <div class="imgcontainer">
546 <img src="images/faster-write-unsafe.jpg">
547 </div>
548 <br>
549 Chart 5: SQLite write latency relative to direct filesystem writes.<br>
550 10K blobs, avg size 10KB, random order,<br>
551 journaling disabled, synchronous OFF.
552 </center>
553
554 <p>
555 In all of the write tests, it is important to disable anti-virus software
556 prior to running the direct-to-disk performance tests. We found that
557 anti-virus software slows down direct-to-disk by an order of magnitude
558 whereas it impacts SQLite writes very little. This is probably due to the
559 fact that direct-to-disk changes thousands of separate files which all need
560 to be checked by anti-virus, whereas SQLite writes only changes the single
561 database file.
562
563 </p><h2 id="variations"><span>2.3. </span>Variations</h2>
564
565 <p>The <a href="compile.html#direct_overflow_read">-DSQLITE_DIRECT_OVERFLOW_READ</a> compile-time option causes SQLite
566 to bypass its page cache when reading content from overflow pages. This
567 helps database reads of 10K blobs run a little faster, but not all that much
568 faster. SQLite still holds a speed advantage over direct filesystem reads
569 without the SQLITE_DIRECT_OVERFLOW_READ compile-time option.
570
571 </p><p>Other compile-time options such as using -O3 instead of -Os or
572 using <a href="compile.html#threadsafe">-DSQLITE_THREADSAFE=0</a> and/or some of the other
573 <a href="compile.html#rcmd">recommended compile-time options</a> might help SQLite to run even faster
574 relative to direct filesystem reads.
575
576 </p><p>The size of the blobs in the test data affects performance.
577 The filesystem will generally be faster for larger blobs, since
578 the overhead of open() and close() is amortized over more bytes of I/O,
579 whereas the database will be more efficient in both speed and space
580 as the average blob size decreases.
581
582
583 </p><h1 id="general_findings"><span>3. </span>General Findings</h1>
584
585 <ol type="A">
586 <li>
587 <p>SQLite is competitive with, and usually faster than, blobs stored in
588 separate files on disk, for both reading and writing.
589
590 </p></li><li>
591 <p>SQLite is much faster than direct writes to disk on Windows
592 when anti-virus protection is turned on. Since anti-virus software
593 is and should be on by default in Windows, that means that SQLite
594 is generally much faster than direct disk writes on Windows.
595
596 </p></li><li>
597 <p>Reading is about an order of magnitude faster than writing, for all
598 systems and for both SQLite and direct-to-disk I/O.
599
600 </p></li><li>
601 <p>I/O performance varies widely depending on operating system and hardware.
602 Make your own measurements before drawing conclusions.
603
604 </p></li><li>
605 <p>Some other SQL database engines advise developers to store blobs in separate
606 files and then store the filename in the database. In that case, where
607 the database must first be consulted to find the filename before opening
608 and reading the file, simply storing the entire blob in the database
609 gives much faster read and write performance with SQLite.
610 See the <a href="intern-v-extern-blob.html">Internal Versus External BLOBs</a> article for more information.
611 </p></li></ol>
612
613
614 <h1 id="additional_notes"><span>4. </span>Additional Notes</h1>
615
616 <a name="compile-android"></a>
617 <h2 id="compiling_and_testing_on_android"><span>4.1. </span>Compiling And Testing on Android</h2>
618
619 <p>
620 The kvtest program is compiled and run on Android as follows.
621 First install the Android SDK and NDK. Then prepare a script
622 named "android-gcc" that looks approximately like this:
623
624 </p><div class="codeblock"><pre>#!/bin/sh
625 #
626 NDK=/home/drh/Android/Sdk/ndk-bundle
627 SYSROOT=$NDK/platforms/android-16/arch-arm
628 ABIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
629 GCC=$ABIN/arm-linux-androideabi-gcc
630 $GCC --sysroot=$SYSROOT -fPIC -pie $*
631 </pre></div>
632
633 <p>Make that script executable and put it on your $PATH. Then
634 compile the kvtest program as follows:
635
636 </p><div class="codeblock"><pre>android-gcc -Os -I. kvtest.c sqlite3.c -o kvtest-android
637 </pre></div>
638
639 <p>Next, move the resulting kvtest-android executable to the Android
640 device:
641
642 </p><div class="codeblock"><pre>adb push kvtest-android /data/local/tmp
643 </pre></div>
644
645 <p>Finally use "adb shell" to get a shell prompt on the Android device,
646 cd into the /data/local/tmp directory, and begin running the tests
647 as with any other unix host.
648 </p><p align="center"><small><i>This page last modified on <a href="https://sqlite.org/docsrc/honeypot" id="mtimelink" data-href="https://sqlite.org/docsrc/finfo/pages/fasterthanfs.in?m=0f7552234f">2023-12-05 14:43:20</a> UTC </small></i></p>
649