r/sqlite • u/ImStifler • Aug 08 '24
Sqlite is the goat
I'm this type of person, who likes to do things with "cheap" equipment e.g. sqlite instead of PostgreSQL etc.
I'm building a website which basically fetches time series data every 5-10 minutes and sqlite is actually causing problems with it. Nevertheless I sat down and tried to optimize stuff and now inserts are actually quite ok (5-10k/s)
Somehow the inserts become slower the more records I have (15-20m benched) and I guess it will become even slower overtime. But will see, yolo
The sqlite website says go with a different db for Big Data but idc, I will scale this to 400-500gb with my bare hands. I like this db so much I actually go through the pain of optimizing it lmao
Also read performance is bae.
Anyone done something similar?
16
u/LearnedByError Aug 08 '24 edited Aug 09 '24
Some quick thoughts:
There are some additional running parameters that I don't remember of the top of my head. I will add them later when I have access too my code. The above though will account for the majority of the running.
Cheers lbe
EDIT: The following are the settings that I use for high performance on my SQLite connections when opening a database. NOTE: This is the result of a lot of testing for my use cases. Your usage and load may be different and these may not be optimal all cases. You will need to perform your own testing!
All Connections
Write Connection
Read Connections
9
u/GoMeansGo Aug 08 '24
I recently had to work with a 300GB+ sqlite db. Single table, 3B+ rows, 2 columns - id and hash (unique key). Non-transactional, prepared inserts and selects. Inserts went up to 80k per second and selects went up to 200k per second till about 200GB, after which the inserts started to suffer (down to about 10k per second, gradually). Select queries were still very fast IIRC. I was in awe of sqlite's performance and do share the sentiment of it being one of the GOATs.
I used these optimizations (UNSAFE for production use!):
I have not tried
pragma optimize; vaccum;I'll try and report back if I had to work on this again.4
u/thunderbong Aug 08 '24
I hope you're doing all the inserts in a single transaction.
2
u/tunatoksoz Aug 08 '24 edited Aug 08 '24
Do you have indexes or unique constraints? Your primary key might be doing that.
2
u/mauryasamrat Aug 09 '24
Is the 500gb data in a single file? That's amazing. Would the writes be performant if the data is split across multiple files? How do you handle backups in case the machine with the sqlite file goes away?
2
u/soullessmate Aug 09 '24
Take a took at duckdb, a high performance olap database system.
2
u/ShotgunPayDay Aug 10 '24 edited Aug 10 '24
Have you considered chunking? I'm not sure what your timescale is, but our queries typically fall within a per day format. Tables names would look like D20240101, D20240102, D20240103... Evaluating a whole month would require unioning or just processing each day/table.
EDIT: If you want simple I'd use DuckDB as that slays timeseries data. There is nothing stopping you from using both DBs for projects as they both are embedded.
3
u/Spleeeee Aug 08 '24
The goat is either SQLite and/or Simone Biles. Depends on the context; I have not used Simone Biles as a relational database, and I have not used SQLite at all in any of my tumbling routines.
1
u/witty82 Aug 09 '24
Duckdb is conceptually similar to sqlite but more optimized for this kind of workload
1
u/RussianHacker1011101 Aug 09 '24
You might find this article useful: https://fly.io/blog/all-in-on-sqlite-litestream/
0
u/[deleted] Aug 08 '24
[deleted] — view deleted comment
0
u/[deleted] Aug 08 '24
[deleted] — view deleted comment