Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decide between SQLite database vs. in-memory usage

I inherited a project from a colleague that left the company. While examining his code, I got confused by something. After he receives quite a big amount of data from the server, he saves this data to a database in the client and then he goes on to work with this data on db. The data is received once at the beginning of the application. What I could not understand that much is, why isn't he just using the data from the memory but needs to store this on db?

Inside the application there are many memory intensive operations like viewing big pdf files using Quartz and so, but isn't the sqlite's size also counted as the memory usage of the app? I mean what do you think the advantage of this could be?

like image 264
aslisabanci Avatar asked Aug 15 '11 16:08

aslisabanci


2 Answers

With SQLite you can quickly and easily query for specific data without having to load the entire dataset into memory and iterate over it.

like image 158
Nathanial Woolls Avatar answered Sep 29 '22 01:09

Nathanial Woolls


SQLite have very small footprint when load itself (~250-400Kb). When SQLite work with on-disk database, there is no memory overhead because of it, it don't even meter size of the file (by default database can hold about 1Tb of data in it's tables). And as you said, it's persistent data storage.

In case of in-memory database store, your application wil consume

memory = database file size + small overhead

Also yo will get some amount of limitations with queries you can perform on in-memory database (I can't remember for time I on the street, but you can't use transactions and vacuum)

Use SQLite with on-disk database and you will gain faster data access and lower footprint than trying to use files to store set of data

like image 22
Serhii Mamontov Avatar answered Sep 29 '22 01:09

Serhii Mamontov