Note: This crate is still in early development and undergoing API changes. Contributions, feature requests, and constructive feedback are warmly welcomed.

sharded   ![Build] ![Crate] [![Docs badge]][docs.rs]

Sharded provides safe, fast, and obvious concurrent collections in Rust. This crate splits the underlying collection into N shards each with its own lock. Calling read(key) or write(key) returns a guard for a single shard.

Features

See Also

Quick Start

```toml [dependencies]

Optionally use parking_lot (or crossbeam), hashbrown, and ahash

by specifing the feature of that name

sharded = { version = "0.0.1", features = ["parking_lot", "hashbrown", "ahash"] } ```

Examples

Use a concurrent HashMap

```rust use sharded::Map; let concurrent = Map::new()

// or use an existing HashMap,

let users = Shard::from(users);

let guard = users.write(32); guard.insert(32, user); ```

Performance Comparison

Disclaimer: I'm no expert in performance testing. Probably the best you can do is benchmark your application using the different implementations in the most realistic setting possible.

These measurements were generated using jonhoo/bustle. To reproduce the charts, see the benchmarks directory. Work is underway to automate testing on a battery of cloud instance types and parameters. Please raise a PR/issue if you have suggestions on how to improve these benchmarks or new workloads to try!

Average Performance by Implementation

This ran each implementation over the presets in bustle::Mix for 5 iterations/random seeds. Lower numbers are better. Approaches using a single std::sync Lock and chashmap were discarded for clarity (they are a lot slower). If you know why chashmap is so slow in this test, please help here.

Read Heavy

All implementations are pretty close but sharded wins by some margin until the high thread counts. At threads=1, sharded shows a significant advantage. dashmap shows the worst overall performance.

Read Heavy Performance)

.. continued in benchmarks/

Acknowledgements

Many thanks to

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in sharded by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.