Article content

SQLite: serving the database from RAM versus serving it from disk

Tagged in sqlite, memory, database

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 seconds
Result 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 seconds       
This 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

Discussion
18.06.2009 14:27
Are there really any advantages to using sqlite over mysql, or postgresql? matt
23.06.2009 12:54
Hi Matt!

It's apples and oranges. If you need a simple and very fast database for your web site, and you have low concurrency, then SQLite is a good choice. If you have high concurrency and need to spread your database over several volums or networks, then a client/server database like MySQl is required. Sven

Submit your comment

Text:

Your name:

Your email:

Show my mailaddress (spam protected)

Your website:

Show my website

Featured Article

PHP Variables and strings

A variable is a means of storing a value, such as a text string or a number. In PHP you do not have to declare your variable, as it's automatically declared when you set it. Since you do not need to declare the variable, you do not have to specify what kind of data it contains either.

Topics
Magicode's own open source project
From the forum / Latest comments
You may also want to to check out these links: sendanonmail.com, superstrongpassword.com.