For certain applications, a millisecond is too long to wait for a trip to the database. I've got some control loops written around SQLite that operate at 1kHz and beyond.
For certain applications, a millisecond is too long to wait for a trip to the database. I've got some control loops written around SQLite that operate at 1kHz and beyond.
https://www.sqlite.org/pragma.html#pragma_synchronous
https://www.sqlite.org/pragma.html#pragma_journal_mode
I set them to "NORMAL" and "WAL" respectively.
That's a pretty big failure to preserve durability.
> When synchronous is NORMAL (1), the SQLite database engine will still sync at the most critical moments, but less often than in FULL mode. There is a very small (though non-zero) chance that a power failure at just the wrong time could corrupt the database in journal_mode=DELETE on an older filesystem. WAL mode is safe from corruption with synchronous=NORMAL, and probably DELETE mode is safe too on modern filesystems. WAL mode is always consistent with synchronous=NORMAL, but WAL mode does lose durability. A transaction committed in WAL mode with synchronous=NORMAL might roll back following a power loss or system crash. Transactions are durable across application crashes regardless of the synchronous setting or journal mode. The synchronous=NORMAL setting is a good choice for most applications running in WAL mode.
It seems extremely reasonable to use WAL with synchronous=NORMAL
If you do not care about system crashes, why sync at all?
If you do not care about system crashes, why sync at all?
Well, you have to sync sometime if you care about persist your data at all, right?And there are scads of use cases where you want to:
- persist data
- enforce some sort of schema (even though SQLite is lax here)
- query/join it in SQL-y ways
- are willing to trade ACID-compliant journaled durability in exchange for performance
Cache stores are maybe the most obvious use case. This is roughly how Redis is configured out of the box after all (sans the SQL) IIRC. Not ideal if your cache is trashed but also, not a huge deal.
There are also a lot of logging/timeseries type applications where it's just not a big deal if you lose, say, a few minutes of data per year.
Transactions on WAL mode databases must use only a single database file to maintain ACID.
The near impossibility of achieving ACI semantics on modern filesystems (other than ZFS) is one of my biggest pet peeves with how data is being handled. Servers may need ACID, but practically no home computers do.
Makes integrating computation and data very easy for domain experts.