-
Notifications
You must be signed in to change notification settings - Fork 161
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
Test: add example of singlethreaded kv-store #989
Test: add example of singlethreaded kv-store #989
Conversation
9abee80
to
65e3284
Compare
This example `examples/raft-kv-memstore-singlethreaded` illustrates building a single threaded Openraft application. By enabling feature flag `singlethreaded`, Openraft does not require the data types to be `Send`, which enables using `Rc` in place of `Arc` to gain a performance improvement.
65e3284
to
936e70b
Compare
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.
On the first look, it looks good, thanks. I didn't do a very thorough review, though, since I suppose it's mostly copy&paste from another example anyway :-).
Some minor comments below.
Reviewed 14 of 14 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ariesdevil, @drmingdrmer, and @lichuang)
examples/raft-kv-memstore-singlethreaded/src/network.rs
line 25 at r1 (raw file):
// NOTE: This could be implemented also on `Arc<ExampleNetwork>`, but since it's empty, implemented // directly.
?
Suggestion:
// NOTE: This could be implemented also on `Rc<ExampleNetwork>`, but since it's empty, implemented
// directly.
examples/raft-kv-memstore-singlethreaded/src/router.rs
line 17 at r1 (raw file):
#[derive(Default)] pub struct Router { pub targets: Rc<Mutex<BTreeMap<NodeId, RequestTx>>>,
Since it's all running in a single thread, why the lock? A RefCell
or so would be sufficient, right?
examples/raft-kv-memstore-singlethreaded/src/store.rs
line 106 at r1 (raw file):
pub state_machine: RwLock<StateMachineData>, snapshot_idx: Arc<Mutex<u64>>,
Same here - a Rc<Cell<u64>>
or so should be sufficient, right?
examples/raft-kv-memstore-singlethreaded/tests/cluster/test_cluster.rs
line 27 at r1 (raw file):
let backtrace = { format!("{:?}", Backtrace::force_capture()) // #[cfg(feature = "bt")]
Why the commented-out code?
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.
Thank you. The following fixup commit replaced these multi-threaded primitives.
Reviewed 6 of 6 files at r2, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ariesdevil and @lichuang)
examples/raft-kv-memstore-singlethreaded/tests/cluster/test_cluster.rs
line 27 at r1 (raw file):
Previously, schreter wrote…
Why the commented-out code?
Not used codes. Removed:(
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.
Reviewed 6 of 6 files at r2, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved
examples/raft-kv-memstore-singlethreaded/src/store.rs
line 104 at r2 (raw file):
pub state_machine: RefCell<StateMachineData>, snapshot_idx: RefCell<u64>,
BTW, any Copy
values can be also stored as Cell
, which incurs less overhead (especially, no need for runtime checking). Then, you can use simple get()
/set()
interface to read/write the cell.
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.
Reviewable status: complete! all files reviewed, all discussions resolved
examples/raft-kv-memstore-singlethreaded/src/store.rs
line 104 at r2 (raw file):
Previously, schreter wrote…
BTW, any
Copy
values can be also stored asCell
, which incurs less overhead (especially, no need for runtime checking). Then, you can use simpleget()
/set()
interface to read/write the cell.
Thank you for the suggestion.
I have given thought to employing Cell
in the implementation. However, for the sake of simplicity in this example application, I'm aiming to minimize the number of types used. :)
Changelog
Test: add example of singlethreaded kv-store
This example
examples/raft-kv-memstore-singlethreaded
illustratesbuilding a single threaded Openraft application.
By enabling feature flag
singlethreaded
, Openraft does not require thedata types to be
Send
, which enables usingRc
in place ofArc
togain a performance improvement.
This change is