News for hackers. Stuff that matters.
Re:Sqlite 3.30.0 by bob1029 on Saturday October 05, 2019 @10:29AM (#21165683)
I am glad to see other SQLite advocates out here.

>Many modern startups could get pretty far with SQLite + aggressive caching

Not only did we get "pretty far", we got to what is effectively a final destination for this generation of our product. We don't even need "aggressive caching" beyond what the filesystem provides to us by way of accessing the SQLite db file.

Today, we have a single SQLite database persisting stateful data for an application that is used concurrently by 100+ users. I have benchmarked 512KB state update writes in a multithreaded scenario at >500 per second. 64KB updates exceed 1000 per second. It took us a lot of time and understanding to get to this point. At the end of the day with SQLite, less is always more. The first attempts we did involved connection pools, queues and all kinds of other fancy over-engineering in an attempt to extract more performance. We finally ended up with just the following:

- Enable Write Ahead Logging

- Set Synchronous to Normal

- Use a single SQLiteConnection

Justification for a single connection: We are using .NET with application-level locking and an RWLS where appropriate. This is in contrast to relying on the database to push these transactional scopes to disk. For us, losing an in-flight transaction tracked in memory is not catastrophic so we can tolerate this 1-100ms danger zone for the huge upside we get in throughput. This is a great example of something you can only do with SQLite. No hosted database solution offers this degree of exclusivity over your data store from an application perspective.

One other application note to keep in mind is that SQLite (by default) operates in serialized mode, so the above approach is consistent regardless of the fact that we are hitting a single connection from multiple threads at once. The usages of RWLS are required in our case simply because we need to do multiple dependent sequential operations (select+modify+update) or insertion of new items (insert+last insert row id from connection). It is hypothetically possible to avoid locking altogether (aside from the implicit SQLite serialization) if you can structure your database such that you perform all operations in a single command - E.g.: Use application-generated keys upon insertion rather than waiting for the DB to generate one.

Also, backups and restores are super trivial as mentioned elsewhere in this discussion. I have considered writing a backup agent directly into our software that is transactionally-aware. E.g.: During a backup request, I can take out a write lock on the RWLS for the SQLiteConnection while copying the database to a backup destination. Alternatively, since the DB lives on the same machine as the application, you can just take a single VM snapshot throughout the day, but this won't be as consistent a backup (tolerable for our use case though).

The biggest advantage we see with using SQLite as our principal data store is that it has allowed us to completely avoid operational annoyances regarding how we actually ship our stack to various environments. .NET Self-Contained Deployments + SQLite = one bin folder that "just works". We were able to build custom deployment tooling because of the simplicity of this model, rather than relying on off-the-shelf tech that doesn't quite fit 100% into our use case.

Re:Sqlite 3.30.0 by asdkhadsj on Saturday October 05, 2019 @10:38AM (#21165755)
Recently I heard[1] that SQLite does not offer concurrent access safety. That is to say, the premise was that if you were to use it as a database backing something multi user, like a forum, SQLite would suffer due to the concurrent access of users against the DB.

While I've not had time to research it yet, I'd be curious on your (or anyones) knowledge / experience in this context.

My plan, if SQLite didn't offer concurrent access safety, was simply to put concurrent primitives around SQLite to ensure safety. However I'm not doing anything until I can make heads or tails of that original comment[1].

Thoughts?

[1]: https://news.ycombinator.com/item?id=21041433

Re:Sqlite 3.30.0 by thijsvandien on Saturday October 05, 2019 @12:44PM (#21166480)
I don’t have much experience with this, but I’ve been reading a bit about it last days. As far as I can tell:

- Concurrent reading has always been possible.

- Reading while writing is possible when the relatively new WAL mode is enabled, at no significant cost.

- Writing still results in a lock, and other writers can decide how long they’re willing to wait on it.

Re:Sqlite 3.30.0 by meddlepal on Saturday October 05, 2019 @11:08AM (#21165930)
Why not just devise a test rather than waiting for someone to hand you the answer? It's not a hard thing to simulate...
Re:Sqlite 3.30.0 by asdkhadsj on Saturday October 05, 2019 @01:15PM (#21166685)
I'm not expecting someone to hand me an answer. I was merely asking for experiences in this area. You think I'm going to rely merely on internet stranger to decide course of action on production systems?

God forbid I ask for experiences from people who seem seasoned in this area on Hacker News of all places. The gall I must have, right?

Re:Sqlite 3.30.0 by porker on Saturday October 05, 2019 @03:32PM (#21167441)
What is RWLS in this context please?
Re:Sqlite 3.30.0 by bob1029 on Saturday October 05, 2019 @05:13PM (#21167999)