-
Notifications
You must be signed in to change notification settings - Fork 5.5k
very dumb leader selection #425
very dumb leader selection #425
Conversation
src/bin/fullnode.rs
Outdated
| "t", | ||
| "", | ||
| "testnet; connec to the network at this gossip entry point", | ||
| "host:port", |
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.
recommend HOST:PORT
src/bin/fullnode.rs
Outdated
| opts.optopt( | ||
| "t", | ||
| "", | ||
| "testnet; connec to the network at this gossip entry point", |
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.
s/connec to/connect to at gossip entry point HOST:PORT
rob-solana
left a comment
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.
nits, otherwise LGTM
garious
left a comment
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.
"When in Rome" please. Using full words and no one letter prefixes would be much appreciated.
src/bin/fullnode.rs
Outdated
| opts.optopt( | ||
| "t", | ||
| "", | ||
| "testnet; connec to the network at this gossip entry point", |
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.
Connect
src/crdt.rs
Outdated
| blob_sender.send(q)?; | ||
| Ok(()) | ||
| } | ||
| /// FIXME: This is obviously the wrong way to do this. Need to implement leader selection |
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.
Let's consistently used TODO or FIXME. Codebase currently uses TODO. If you prefer FIXME, can you change the others?
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.
I thought FIXME was a higher priority TODO :)
src/bin/fullnode.rs
Outdated
| let file = File::open(path.clone()).expect(&format!("file not found: {}", path)); | ||
| let leader = serde_json::from_reader(file).expect("parse"); | ||
| let taddr = testnet.parse().unwrap(); | ||
| let entry = ReplicatedData::new_entry_point(taddr); |
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.
The term entry is already actively used throughout the codebase. Can you find another?
src/bin/fullnode.rs
Outdated
| ); | ||
| let file = File::open(path.clone()).expect(&format!("file not found: {}", path)); | ||
| let leader = serde_json::from_reader(file).expect("parse"); | ||
| let taddr = testnet.parse().unwrap(); |
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.
testnet_addr?
| } | ||
|
|
||
| /// FIXME: This is obviously the wrong way to do this. Need to implement leader selection | ||
| /// A t-shirt for the first person to actually use this bad behavior to attack the alpha testnet |
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.
Seems fair :)
src/crdt.rs
Outdated
| /// FIXME: This is obviously the wrong way to do this. Need to implement leader selection | ||
| /// A t-shirt for the first person to actually use this bad behavior to attack the alpha testnet | ||
| fn update_leader(&mut self) { | ||
| if let Some(lid) = self.top_leader() { |
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.
id would be a better name since lid is a word. If not specific enough, use leader_id
src/crdt.rs
Outdated
| fn test_update_leader() { | ||
| logger::setup(); | ||
| let me = ReplicatedData::new_leader(&"127.0.0.1:1234".parse().unwrap()); | ||
| let lead = ReplicatedData::new_leader(&"127.0.0.1:1234".parse().unwrap()); |
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.
leader0 and leader1 would be consistent with naming elsewhere
src/crdt.rs
Outdated
| let lead = ReplicatedData::new_leader(&"127.0.0.1:1234".parse().unwrap()); | ||
| let lead2 = ReplicatedData::new_leader(&"127.0.0.1:1234".parse().unwrap()); | ||
| let mut crdt = Crdt::new(me.clone()); | ||
| assert_matches!(crdt.top_leader(), None); |
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.
assert_eq
src/crdt.rs
Outdated
| let _ = obj.write().unwrap().update_leader(); | ||
| let elapsed = timestamp() - start; | ||
| if GOSSIP_SLEEP_MILLIS > elapsed { | ||
| let left = GOSSIP_SLEEP_MILLIS - elapsed; |
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.
left is unnecessarily ambiguous. time_left or remaining would be better.
src/crdt.rs
Outdated
| } | ||
| let mut sorted: Vec<_> = table.iter().collect(); | ||
| sorted.sort_by_key(|a| a.1); | ||
| sorted.last().map(|a| *(*(*a).0)) |
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.
Can that be simplified?
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.
hehe, its borrow checker all the way down. I am not sure it can be without copying the generic array key. and there is no way to sort an iterator.
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.
I was wrong
|
@garious still blocked? |
|
@aeyakovenko, if you're happy with #427, can you merge it, rebase this PR on it, and remove that |
@aeyakovenko, this one failed on Rust stable.
|
Merged in #430 |
Bumps [eslint](https://github.com/eslint/eslint) from 7.7.0 to 7.8.1. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md) - [Commits](eslint/eslint@v7.7.0...v7.8.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
… (#425) implements weighted shuffle using binary tree (#185) This is partial port of firedancer's implementation of weighted shuffle: https://github.com/firedancer-io/firedancer/blob/3401bfc26/src/ballet/wsample/fd_wsample.c Though Fenwick trees use less space, inverse queries require an additional O(log n) factor for binary search resulting an overall O(n log n log n) performance for weighted shuffle. This commit instead uses a binary tree where each node contains the sum of all weights in its left sub-tree. The weights themselves are implicitly stored at the leaves. Inverse queries and updates to the tree all can be done O(log n) resulting an overall O(n log n) weighted shuffle implementation. Based on benchmarks, this results in 24% improvement in WeightedShuffle::shuffle: Fenwick tree: test bench_weighted_shuffle_new ... bench: 36,686 ns/iter (+/- 191) test bench_weighted_shuffle_shuffle ... bench: 342,625 ns/iter (+/- 4,067) Binary tree: test bench_weighted_shuffle_new ... bench: 59,131 ns/iter (+/- 362) test bench_weighted_shuffle_shuffle ... bench: 260,194 ns/iter (+/- 11,195) Though WeightedShuffle::new is now slower, it generally can be cached and reused as in Turbine: https://github.com/anza-xyz/agave/blob/b3fd87fe8/turbine/src/cluster_nodes.rs#L68 Additionally the new code has better asymptotic performance. For example with 20_000 weights WeightedShuffle::shuffle is 31% faster: Fenwick tree: test bench_weighted_shuffle_new ... bench: 255,071 ns/iter (+/- 9,591) test bench_weighted_shuffle_shuffle ... bench: 2,466,058 ns/iter (+/- 9,873) Binary tree: test bench_weighted_shuffle_new ... bench: 830,727 ns/iter (+/- 10,210) test bench_weighted_shuffle_shuffle ... bench: 1,696,160 ns/iter (+/- 75,271) (cherry picked from commit b6d2237) Co-authored-by: behzad nouri <[email protected]>
…ana-labs#185) (solana-labs#425) implements weighted shuffle using binary tree (solana-labs#185) This is partial port of firedancer's implementation of weighted shuffle: https://github.com/firedancer-io/firedancer/blob/3401bfc26/src/ballet/wsample/fd_wsample.c Though Fenwick trees use less space, inverse queries require an additional O(log n) factor for binary search resulting an overall O(n log n log n) performance for weighted shuffle. This commit instead uses a binary tree where each node contains the sum of all weights in its left sub-tree. The weights themselves are implicitly stored at the leaves. Inverse queries and updates to the tree all can be done O(log n) resulting an overall O(n log n) weighted shuffle implementation. Based on benchmarks, this results in 24% improvement in WeightedShuffle::shuffle: Fenwick tree: test bench_weighted_shuffle_new ... bench: 36,686 ns/iter (+/- 191) test bench_weighted_shuffle_shuffle ... bench: 342,625 ns/iter (+/- 4,067) Binary tree: test bench_weighted_shuffle_new ... bench: 59,131 ns/iter (+/- 362) test bench_weighted_shuffle_shuffle ... bench: 260,194 ns/iter (+/- 11,195) Though WeightedShuffle::new is now slower, it generally can be cached and reused as in Turbine: https://github.com/anza-xyz/agave/blob/b3fd87fe8/turbine/src/cluster_nodes.rs#L68 Additionally the new code has better asymptotic performance. For example with 20_000 weights WeightedShuffle::shuffle is 31% faster: Fenwick tree: test bench_weighted_shuffle_new ... bench: 255,071 ns/iter (+/- 9,591) test bench_weighted_shuffle_shuffle ... bench: 2,466,058 ns/iter (+/- 9,873) Binary tree: test bench_weighted_shuffle_new ... bench: 830,727 ns/iter (+/- 10,210) test bench_weighted_shuffle_shuffle ... bench: 1,696,160 ns/iter (+/- 75,271) (cherry picked from commit b6d2237) Co-authored-by: behzad nouri <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.