Another crazy idea is to learn about SQLite file format and just write the pages to disk.
Another crazy idea is to learn about SQLite file format and just write the pages to disk.
https://www.flamingspork.com/projects/libeatmydata/
libeatmydata shouldn't be used in production environments, generally speaking, as it biases for speed over safety (lib-eat-my-data), by disabling fsync, and associated commands for the running process under it. Disabling those commands results in less I/O pressure, but comes with the risk that the program thinks it has written safely and durably, and that may not be true. It essentially stops programs that are written to be crash proof, from being actually crash proof. Which under the circumstances you're operating on you almost certainly don't care.
I've used this when reloading database replicas from a dump from master before, as it drastically speeds up operations there.
pragma synchronous = off
https://www.sqlite.org/pragma.html#pragma_synchronousGo is one of the programming languages that makes syscalls directly, thus libeatmydata has no effect on it (being an LD_PRELOAD to the libc).
https://github.com/sqlitebrowser/sqlitedatagen
There's some initial work to parallelise it with goroutines here:
https://github.com/sqlitebrowser/sqlitedatagen/blob/multi_ro...
Didn't go very far down that track though, as the mostly single threaded nature of writes in SQLite seemed to prevent that from really achieving much. Well, I _think_ that's why it didn't really help. ;)
I maintain a similar go tool for work, which I use to stuff around 1TB into MariaDB a time:
https://github.com/siara-cc/sqlite_micro_logger_arduino
https://github.com/siara-cc/sqlite_micro_logger_arduino/blob...
This is a heavily subsetted implementation of SQLite3 that can read/write databases (presumably on SD cards) from very small microcontrollers.
It presumably doesn't have the same ACID compliance properties, but with a single <1.5k source file, may represent a particularly efficient way to rapidly learn the intrinsics if you happened to want to directly manipulate files on disk.
Now I'm thinking it could actually be interesting to see what drh thinks of this implementation (and any gotchas in it) because of its small size and accessibility.
However, I think your Rust threaded trial might be a little bit off in subtle ways. I would truly expect it to perform about several times better than single threaded Rust and async Rust (async is generally slower on these workloads, but still faster than Python)
Edit : After reading your rust code, you might have room for some improvements :
- don’t rely on random, simply cycle through your values
- pre-allocate your vecs with ˋwith_capacityˋ
- dont use channels, prefer deques..
- ..or even better, don’t use synchronization primitives and open one connection per thread (not sure if it will work with sqlite?)
> I am also interested in writing the SQLite or PostgreSQL file format straight to disk as a faster way to do ETL.
what exactly you are trying to do here?
Certainly if I was trying to do the same thing in Pg my first thought would be "batched COPY commands".
> The machine I am using is MacBook Pro, 2019 (2.4 GHz Quad Core i5, 8GB, 256GB SSD, Big Sur 11.1)
Given the target schema, 100M rows with only 8GB RAM risks hitting swap hard.