[][src]Crate sharded

A generic sharded locking mechanism for hash based collections to speed up concurrent reads/writes. Shard::new splits the underlying collection into N shards each with its own lock. Calling read(key) or write(key) returns a guard for only a single shard. The underlying locks should be generic, so you can use it with any Mutex or RwLock in std::sync or parking_lot.

In a probably wrong and unscientific test of concurrent readers/single writer, shard_lock is 100-∞∞x faster (deadlocks?) than dashmap, and 13x faster than a single parking_lot::RwLock. Carrying Shard<RwLock<T>> is possibly more obvious and simpler than other approaches. The library has a very small footprint at ~100 loc and optionally no dependencies.

shard_lock is flexible enough to shard any hash based collection such as HashMap, HashSet, BTreeMap, and BTreeSet.

Warning: shard_lock is in early development and unsuitable for production. The API is undergoing changes and is not dependable.

Structs

Shard

The sharded lock collection. This is the main data type in the crate. See also the type aliases Map, Set, and so on.

Traits

Collection

Basic methods needing implemented for shard construction

ExtractShardKey

Teases out the sharding key for example from an IntoIterator value.

Lock

Generic locking implementation.

Type Definitions

Map

Sharded lock-based concurrent map using the crate default lock and map implementations.

RwLock
Set

Sharded lock-based concurrent set using the crate default lock and set implementations.