Expand description
A construction that elastically relaxes a given collection.
Kasino aims to improve performance of concurrent datastructures by sharding operations into multiple subqueues.
This process introduces a relaxation of the wrapped datastructure, the specifics depending on the used strategy.
Strategies optimize for performance and relaxation bounds, but can be implemented to optimize for other properties.
Multiple strategies, amenable to different kinds of datastructures and requirements are provided.
Additionally an interface for defining custom strategies is available.
§Usage
use kasino::{InlineBandit, strategy::DCBO};
let bandit = InlineBandit::<MyQueue<i32>, DCBO, 8>::new();
let mut handle = bandit.buy_in();
let mut handle2 = handle.fork();
assert!(handle.offer(42).is_ok());
assert!(handle2.offer(10).is_ok());
assert!(handle.poll(()).is_ok());§Property preservation
§Progress Guarantees:
- Lock Freedom: if the wrapped collection is lock-free,
Banditsare also lock-free. - Obstruction Freedom: if the wrapped collection exposes obstruction-free methods, all corresponding operations on
Banditsare also obstruction-free.
§Ordering and Consistency Guarantees:
- Relaxed Specification: if the wrapped collection has some specification,
Banditsrelax that specification based on the chosen strategy. - Linearizability: if the wrapped collection is linearizable, all operations on
Banditsare also linearizable with respect to their relaxed specification.
§Relaxation
The rank error and delay are in general unbounded. However, the rank error and delay of some strategies are bounded with high probability. The exact bounds here are differing across different strategies.
For more information refer to the strategies documentation and the reference papers.
For an empirical analysis of the rank errors, refer to relaxed-queue-simulations.
§Performance
Sharding operations to multiple sub-collections incurs both memory cost, as well as additional overhead. Under low contention Kasino is slower than the raw collection.
However, scheduling thread access across multiple sub-collections allows to reduce cache-line invalidation at high contention, improving performance as thread count increases.
§Limitations
- Currently an instantiated
Banditcannot be resized. Its capacity is fixed at construction time. - The capacity of each sub-collection is fixed statically. The total capacity of a
Banditis constrained to a multiple of this.
§Advanced Usage
The interfaces for Collection, strategy::Strategy and Bandit are general enough to support the implementation of a large set of datastructures. For examples of this consult examples/.
§Platform Support
All platforms supporting native atomic operations are supported.
The feature atomic-fallback may be used, if no native atomic operations are available.
§Feature Flags
std: Enablesstdsupport.instrumented: Adds telemetry collection to strategiesatomic-fallback: Uses theportable-atomicfallback feature if native atomics are missing. It is discouraged to use this feature, as fallback atomics internally rely on locks.default: None
§Testing
Currently testing is based on:
- Miri - to validate pointer arithmetic and catch undefined behavior.
- Loom and Shuttle - to test for race conditions and non-blocking invariants.
- ASan - to check for memory corruption.
§References
- Performance, Scalability, and Semantics of Concurrent FIFO Queues, Kirsch et al.
- Balanced Allocations over Efficient Queues: A Fast Relaxed FIFO Queue, Geijer et al.
Modules§
- components
- Useful components and helper traits for implementing the
Collectiontrait. - prelude
- Useful types that should suffice for standard usage.
- storage
- Storage abstractions for different kinds of storages
- strategy
- Strategies used in this crate
Structs§
- Bandit
Handle - An owned handle into the core bandit.
- Boxed
Bandit - a subcollection container, which is stored dynamically
- Boxed
Storage - a dynamically stored slice
- Inline
Bandit - A container of
Nsub collections that is stored inline. - Inline
Storage - an array
Traits§
- Collection
- The interface for a generic data structure.
- Signature
- Description about the signature of a failable method
- With
Capacity - A collection that may be created with a static initial capacity N
Type Aliases§
- Boxed
Bandit Handle - a handle to the core subcollection container, which is stored dynamically
- Inline
Bandit Handle - A handle to an
InlineBandit.