Multicore DB
OLTP does not benefit from more threads (as we care more about latency) where as OLAP is bound by memory bandwidth and can benefit from some more threads.
1. Prefetching
Prefetching favours sequential access & spacial locality, not branching, function calls or pointer chasing.
Temporal Streaming is a prefetching technique that uses a small buffer to store the next few pages of a stream. This allows for better cache performance, as the next page is likely to be in the buffer.
Software Prefetching is a technique where the compiler inserts prefetch instructions into the code. This allows for better cache performance, as the next page is likely to be in the cache.
2. Cache Consciousness
- Simplified code to reduce instruction footprint.
- Better code layout: minimize jumps for better prefetching.
- Query Compilation: into machine code.
We should also consider data layout: columnar storage is better for OLAP, row storage is better for OLTP. Columnar storage allows for better compression and vectorization, but is worse for point queries. Row storage allows for better point queries, but is worse for compression and vectorization.
Our goal is to maximize cache line utilization and exploiting prefetching.
The volcano model (iterators for each operator) is not cache conscious, as it has a lot of function calls and pointer chasing. The vectorized model (batch processing) is better for cache performance, as it has fewer function calls and better data locality.
3. Exploiting Common Instructions
Computation Spreading is a technique where we exploit common instructions across multiple queries. This allows for better cache performance, as the same instruction is likely to be in the cache.
4. Scaling OLTP
Hot, Shared locks (those that are frequently accessed) cause contention. Speculative lock inheritance reduces lock contention by allowing transactions to commit without immediately releasing hot locks, while pre-seeding the lock list for the next transaction. This improves performance by co-locating atomic counters with data and reducing competition between agent threads.
We can make data access predictable by assigning threads to specific data partitions. This allows for better (& more predictable!) cache performance, as the same data is likely to be in the cache.
Latching is a lock that protects in-memory data structures. Can be reduced with physiological partitioning, where we partition data into smaller chunks and statically assign each chunk to a specific thread. This allows for better cache performance, as the same data is likely to be in the cache.
Aether Hollistic Logging reduces logging overhead by:
- Early Lock Release: releases locks earlier by separating transaction commit from log writing, reducing the time other transactions must wait.
- Flush pipelining reduces context switches by coordinating log writes across threads, while the consolidation array groups log operations to minimise log contention.
Optimal configuration depends on workload and hardware.