How SQLite scales read concurrency
fly.io
fly.io
When you run "PRAGMA journal_mode=wal;" against a database file the mode is permanently changed for that file - and the .db-wal and .db-shm files for that database will appear in the same directory as it.
Any future connections to that database will use it in WAL mode - until you switch the mode on it back, at which point it will go back to journal mode.
It makes sense when you think about it - of course a database can only be in one or the other modes, not both, so the setting must be at the database file level. But it took me a while to understand.
I wrote some notes on this here: https://til.simonwillison.net/sqlite/enabling-wal-mode
"Transactions involving multiple attached databases are atomic, assuming that the main database is not ":memory:" and the journal_mode is not WAL. If the main database is ":memory:" or if the journal_mode is WAL, then transactions continue to be atomic within each individual database file. But if the host computer crashes in the middle of a COMMIT where two or more database files are updated, some of those files might get the changes where others might not."
https://sqlite.org/lang_attach.html
Systems designed for DML against multiple database files should eschew WAL mode.
https://www.sqlite.org/cgi/src/doc/begin-concurrent/doc/begi...
I really hope these two branches get merged into the mainline sometime soon. I'm not sure what's the blocker, since both branches have existed for literally years and are refreshed frequently.
WAL2 + BEGIN CONCURRENT would solve probably 99.9% of developer scaling needs.
Stability is vastly more important than new functionality in that context.
Can you document that? I was under the impression that they used SQLite for on ground simulations?
Rockwell-Collins is the organization that prompted Dr. Hipp to obtain DO-178B. I actually worked at Rockwell-Collins in the early 90s.
I do generally prefer airlines flying Airbus, BTW.
"Airbus confirms that SQLite is being used in the flight software for the A350 XWB family of aircraft."
See also: eglSwapBuffers, https://katatunix.wordpress.com/2014/09/17/lets-talk-about-e...
It's obviously easier to manage and maintain due to it being an embedded database, but that seems to be a very separate issue from the data structure involved, which definitely has disadvantages compared to a typical SQL system.
This is true. However, in my testing with a relatively old NVMe device, I can push well over a gigabyte/second to the database with that single connection. One trick I employ is to only ever maintain 1 connection and to use an inter-thread messaging framework like Disruptor to serialize everything beforehand to a single batched writer. Another, much simpler option, would be to just lean on the fact that SQLite serializes all writes by default and to take a little bit of a performance hit on the lock contention (assuming a small # of writers).
I know for a fact that I can get more write throughput out of SQLite in an in-process setting than I could if I had to go across the network to a hosted SQL instance. In many cases this difference can be measured as more than 1 order of magnitude, both in latency and throughput figures.
Going vertical on hardware in 2022 is an extremely viable strategy.
These appear to be page-level locks, and row-level locks should not be expected for this effort.
https://www.sqlite.org/cgi/src/doc/begin-concurrent/doc/begi...
Are there any useful situations where they wouldn't be set to the same value?
- SQLite has pretty limited builtin functions: https://news.ycombinator.com/item?id=32557672
- Turning SQLite into a Distributed Database: https://news.ycombinator.com/item?id=32539360
- SQLite is not a toy database: https://news.ycombinator.com/item?id=32478907
- SQLite: Wal2 Mode Notes: https://news.ycombinator.com/item?id=32435601
- SQLite-HTTP: A SQLite extension for making HTTP requests: https://news.ycombinator.com/item?id=32417410
in same vein as all those articles comparing time to process data on single laptop vs hadoop cluster or whatever
Technologies have waves on HN. A couple years ago there were a ton of Go articles. Lately there's always a Rust article on the front page. Right now, I feel like SQLite is a refreshing escape from many of the complex deployments that have been in vogue lately.
We were using SQLite in production way before it was cool on HN. I remember back in 2017-2018 describing how we use SQLite as the principal database engine for our multi-user product, and was basically tarred and feathered by the hosted SQL crowd.
I think the most intoxicating thing about SQLite is that you don't have to install or configure even one goddamn thing. It's a lot more work and unknowns to go down this path, but you can wind up with a far more robust product as a result.
I hope this trend continues aggressively.
There are a lot of configuration options when compiling SQLite, and some of its defaults are pretty conservative (e.g. assuming no usleep and default to `sleep` unless `HAVE_USLEEP` specified). Generally I recommend looking into how Apple configures its SQLite (SQLite provides https://www.sqlite.org/c3ref/compileoption_get.html to query) and modify to your needs.
Definitely look into compilation options if you plan to embed SQLite into your application.
The creator says it like Escue Ell-ite emphasis on the Es- and -ite. [0]
Case in point:
Blue Origin wants people to refer to it by the nickname "Blue". But you kind of have to be in the industry to know that. Everyone else just uses the initialism instead, which is most commonly used to abbreviate "body odor".
On a related topic, anyone have an idea of the breakdown of people that say Sequel vs S.Q.L. and are there people that look down on others for their usage? Of course ignoring the opinion of anyone that says Jif.
The macbook I'm typing this on has 113 sqlite databases open right now. I'd call that a lot of deployment. The name doesn't seem to have held sqlite back much!
IMO database names are incredibly bland, outside of Cockroachdb, and not a driving factor to adoption given the critical nature of the decision.
I recently ran an experiment with Node and was able to take writes from around 750 / second to around 24K / second just by coordinating them using Node IPC. That is, I had the main thread own the sole write connection and all other threads sent their writes operations to it, thread-local connections were read-only.
It's pretty cool how far you can push SQLite and it just keeps humming right along.
Thanks
[1] https://nodejs.org/api/process.html#processsendmessage-sendh...
I was planning on turning that into a library, but Bun nerd sniped me.
You need the “hey” tool to run the benchmarks[1] the way that I was running them.
EDIT:Lots of devs have (unfounded) doubts about performance regarding SQLite for web apps, a single machine benchmark against postgres (with postgres and the app in the same server) would clear many doubts and create awareness that SQLite is going to be more than enough for many apps.. The app doesn't have to be a web app (we are not testing web servers) but maybe some code with some semi-complex domain models.
Redis looks like it would struggle with this requirement also without some serious hardware, tweaks, or configuration. https://redis.io/docs/reference/optimization/benchmarks/
By the end it ran fast enough that it was able to saturate the kernel's paging infrastructure and make my mouse cursor stutter, and I was able to take 1-2 snapshots per second of a full running Firefox process with real webpages in it, so it was satisfactory. SQLite couldn't process the amount of data I was pumping in at that rate (but it still performed pretty well - maybe a few snapshots per minute)
At the time I did investigate other data stores and the only good candidates I ran across used incompatible open source licenses, so I was stuck doing it myself. Fun excuse to learn how to write and optimize btrees for throughput :-)
This benchmark requires concurrent writes in a massive OLTP client-server model.
SQLite shines in SQL92 compliance (without grant/revoke or other permission-based aspects), but it was simply not designed to compete in any of the TPC tests.
The current holder of the top TPC-C score is OceanBase, which defeated Oracle's previous record with 11g/Solaris/SPARC.
https://www.tpc.org/tpcc/results/tpcc_perf_results5.asp?resu...