xacrimon / dashmap

Blazing fast concurrent HashMap for Rust.
MIT License
2.84k stars 140 forks source link

ensure shard count == # keys #257

Open amilkov3 opened 1 year ago

amilkov3 commented 1 year ago

much like a sharded db, i have keys that are totally independent of each other so it would be nice to have a way to just make sure that writes to a single key do not block reads or writes to any other key. as far as i understand currently the shard count is calculated based off # of cores. and writes to a key in one shard block all ops to the other keys in that shard?

is this or will this be possible?

imagine-hussain commented 1 year ago

Is this method sufficient?

https://docs.rs/dashmap/latest/dashmap/struct.DashMap.html#method.with_shard_amount

Given that #shards needs to be a power of 2 according to the docs, I'm doubtful that having exactly one shard per key is possible but, having shards == capacity may be.

Otherwise would a try_reshard be better for once you exceed capacity?