What is concurrently readable and when to use it
masterConcurrently readable data structures (often called Copy-On-Write or Multi-Version-Concurrency-Control) allow multiple readers to proceed with transactions while a single writer operates.
Key Characteristics
- Non-blocking Readers: Readers are guaranteed that content remains consistent for the duration of the read. Readers do not block writers, and writers do not block readers.
- Serialized Writers: Writers are serialized, behaving similarly to a
Mutex. - Transactional Behavior: Unlike Lock-Free structures that rely on atomics and may show immediate/partial updates, Concread provides consistent state from the start to the end of an operation.
- Space-Time Trade-off: This approach uses more memory (to hold copies of data during updates) to achieve higher parallel throughput by reducing thread stalls.
When to use Concread
- Replace
RwLock: Use Concread when you want to improve parallel throughput in scenarios where readers hold locks for non-trivial amounts of time. If a reader holds anRwLockfor a long time, it stalls writers; if a writer holds it, it stalls readers. Concread avoids this. - Avoid for trivial operations: If you are using an
RwLockwhere the lock is taken, data is changed/read, and dropped immediately, Concread likely won't provide benefits. - Map/Cache usage: Use the provided
BTreeMap,HashMap, orAdaptive Replacement Cache(ARC) when you have at least 512 bytes of data in yourCell, as these structures only copy the required portions for an update.