by jiggawatts · 1mo ago · 0 comments
Most of the DB engines out there still seem to use a "n-threads" style parallelism with exchange operations and poor async I/O management.
DuckDB is improving on this front, but in some sense is catching up to R&D (and implementation!) that is now decades old.
A "rhetorical challenge" I like to give software developers working on systems like this is the following: If I gave you a computer with 1,024 cores and matching network and storage bandwidth -- but with significant latency -- could you keep a system like this 100% utilised with one query?
The answer for almost all software is "no".
For example, SQL Server tops out at 64 hardware threads for any one query: https://learn.microsoft.com/en-us/sql/database-engine/config...
GPU codes are starting to get there, but CPU codes are way behind on this frontier of computer science.
It's not just databases! Can you (de)compress a file in parallel? Verify its hash in parallel? Upload/download from storage with CPU and I/O task parallelism? Can you overlap all of these operation so nothing is ever waiting on anything else it doesn't have to?
This matters! I ran some tests with bioinformatics codes and found that most got stuck in tar pits. Many could not scale to modern SSDs with millions of IOPS or modern networking with hundreds of gigabits of throughput, no matter how many CPU cores were thrown at them.
PS: AMD's Zen 6 era EPYC 9006 processors will have 512 cores and 1,024 threads per two-socket system, so this is not hypothetical: https://www.amd.com/en/products/processors/server/epyc/9006-...
You can hash chunks, or maybe use different kind of hashes though.
The leaves and then all nodes can be computed in parallel.
With a typical node size of say 4 KB any file that is at least 4 MB in size can utilise 1,024 cores.
Same for objects stores like S3 or Google Drive, they only give you a single hash, you can't parallelize that, you need to add your own merkle tree on top.
Also, the tree can be based on any underlying hash function, so the root hash can be literally "just" a SHA256 hash, but instead of hashing the whole file, it hashes a list of hashes.
You don't even need to store those intermediate nodes! They must be recomputed on-the-fly to verify the root hash anyway.
Last, but not least, the temporary space required is logarithmic in the size of the data, typically with a large exponent, so in practice this all fits on the stack. No heap memory allocations required, compatible with embedded devices, and can re-use cryptographic acceleration primitives like the AES-NI instruction set.
Conversely, tree-based hash constructions allow:
- Parallel generation and verification.
- Incremental repair of partially corrupted data.
- Extension of an existing hash (efficient append & prepend).
- Patricia hashes also allow efficient mutation in the middle of the data.
- Various deduplication and efficient incremental sync scenarios.