Inserting 130M SQLite rows per minute from a scripting language
blog.metaobject.com
blog.metaobject.com
Also check out DuckDB, which is a similar tool tailored for data science; I haven’t used it but I’ve heard good things. https://duckdb.org/
* Ensure you're in WAL mode. https://sqlite.org/wal.html
* Use prepared statements and transactions.
* Set the cache pragma to ideally hold the DB in RAM.
* Run optimize and vacuum periodically (especially if the data is transactional): https://sqlite.org/pragma.html#pragma_optimize
* Pick the synchronous mode you're comfortable with: https://sqlite.org/pragma.html#pragma_synchronous
That was what I thought as well, but in this case non-WAL turned out to be faster. Not yet sure why that is.
WAL could have faster writes for small amounts of data, but once you have enough contents that the WAL has to be flushed during processing you're better off skipping the WAL entirely.
/fast-sqlite3-inserts (master)> time make busy-rust
Sun Jul 18 17:04:59 UTC 2021 [RUST] busy.rs (100_000_000) iterations
real 0m9.816s
user 0m9.380s
sys 0m0.433s
________________________________________________________
Executed in 9.92 secs fish external
usr time 9.43 secs 0.20 millis 9.43 secs
sys time 0.47 secs 1.07 millis 0.47 secs
fast-sqlite3-inserts (master)> time make busy-rust-thread
Sun Jul 18 17:04:48 UTC 2021 [RUST] threaded_busy.rs (100_000_000) iterations
real 0m2.104s
user 0m13.640s
sys 0m0.724s
________________________________________________________
Executed in 2.33 secs fish external
usr time 13.68 secs 0.20 millis 13.68 secs
sys time 0.78 secs 1.18 millis 0.78 secs
I'm probably doing something wrong. Or I'm getting the pace needed for the billion?This is on a M1 MacBook Air.
Yes, it turns out. :-)
The "busy-*" programs just run the loops without doing any SQLite operations, in order to test loop overhead.
On my M1 Air, this is the fastest time I get from Rust:
> ./bench-threaded-rust.sh
Sun Jul 25 07:52:46 CEST 2021 [RUST] threaded_batched.rs (100_000_000) inserts
real 0m20.765s
user 0m25.916s
sys 0m2.303sI am surprised M1 Air taking 20 seconds, on my old machine its 7seconds ish.
Not bad really. Objective-S is impressive.
The built-in SSD can write that in under a second, if written optimally.