-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lock free data structures to wsv #984
Conversation
b7386ae
to
ba58d73
Compare
@i1i1 I remember you were doing performance tests for both of the crates, can you publish the results here? |
Benchmark of lockfree vs dashmap: Insert scenario (50000 Inserts per thread):
Generally dashmap 5-10x faster than lockfree. More benchmarks here:
|
c6453a5
to
06b42cc
Compare
0f7b258
to
9a7bae9
Compare
f3f0ff4
to
2158004
Compare
@i1i1 in the benchmarks |
Or you can mark it with * and describe it below. |
@eadventurous looked through every RwLock in iroha_data_model. Unfortunately using HashSet/HashMap there would require removing Ord everywhere. I guess it is better to leave BTreeMap/BTreeSet for this small cases. |
Possible design for wsv (the same as before but with some lifetime wrangling) |
bd2d22e
to
c11ecad
Compare
Signed-off-by: i1i1 <[email protected]>
I was concerned about using dashmap in the async context because of the spinlocks (I thought they might steal computation time from other tasks as they are not cooperating). But I investigated the issue more and it seems they do cooperate. I was testing with Also there is an issue for async support for dashmap, and it is mentioned there that it is fully compatible xacrimon/dashmap#25 |
@eadventurous Yeah it won't make sense as it would require locking and removing spinlocks from datastructure. Let's just keep that in mind and never take mutable refence for dashmap as it might deadlock whole datastructure. |
Mutable references will sometimes be taken, as we do mutate WSV it is just a matter of for how long, but anyway, I checked this and it seems working even in this extreme case, and it does not block the whole thread. |
@eadventurous we don't need to take mutable reference ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally :)
@eadventurous It will live here https://jira.hyperledger.org/browse/IR-1078 |
https://jira.hyperledger.org/browse/IR-1065
https://jira.hyperledger.org/browse/IR-1066
Signed-off-by: i1i1 [email protected]
Description of the Change
Remove lock from WSV and make maps and sets mutable concurrently. It uses dashmap crate for that.
Benefits
This change removes racing for whole wsv and adds locks for its subparts.
Possible Drawbacks
Lockfree actually caused several panics and needs for rework.
Usage Examples or Tests [optional]
Alternate Designs [optional]
dashmap is also good, it offers entry api and some lock free functions, but there are cautions about deadlocks. It is probably a good candidate, but should be used wisely.
lockfree is very generic and good crate, but it seems very unsafe to use it, as it can panic. Also it is quiete slow
flurry is a port of java hashmap, so it seems to be very robust, but it requires using crossbeam epoch in api, so we need to drastically change it in order to use it.