SQLite: serving the database from RAM versus serving it from disk
I have taken a look at the effect of querying a SQLite database in memory, and serving the content via memory, versus querying and serving content from a disk-based SQLite database.
My sample database was populated with 37.863 unique words from the english dictionary. Each entry is between three and sixteen characters. I ran successive queries in a loop for words matching a wildcard letter and returning a count of the result set. The result below is the mean time of the test. Permalink for this article http://mirror.magicode.org/content/sqlite_in_memory_versus_disk
Result for the database stored on disk:
Loop: 1 query: 0.00127 seconds 500 queries: 0.52 seconds 1000 queries: 1.26 seconds 1500 queries: 3.69 seconds 5000 queries: 5.01 seconds 15000 queries: 14.58 seconds 45000 queries: 39.88 seconds Concurrency 10 concurrent clients: 0.255 seconds 20 concurrent clients: 0.143 seconds 30 concurrent clients: 0.148 secondsResult for the database stored in memory:
Loop: 1 query: 0.00173 seconds 500 queries: 0.37 seconds 1000 queries: 1.09 seconds 1500 queries: 3.24 seconds 5000 queries: 3.6 seconds 15000 queries: 10.74 seconds 45000 queries: 32.27 seconds Concurrency 10 concurrent clients: 0.266 seconds 20 concurrent clients: 0.129 seconds 30 concurrent clients: 0.139 secondsThis text was originally written for http://blog.magicode.org
As the numbers will tell you, serving the sqlite-database from RAM does give a pretty sizable performance boost. However, on small load with low concurrency, the difference is not very significant. If you see this notice on any site other than magicode.org, it's probably been lifted without consent
