Skip to content
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

[TECH DEBT] Improve ConnectedNetwork - recv_message #3671

Merged
merged 4 commits into from
Sep 12, 2024
Merged

Conversation

rob-maron
Copy link
Collaborator

@rob-maron rob-maron commented Sep 12, 2024

Is part of #3672
Closes #2558

This PR:

1. Changes recv_msgs to recv_message, allowing us to receive a single message for each call.

This simplifies the receiving layer and allows us to remove the async_sleep that we were using.

2. Improves the message receiving loop

Doesn't do the unfold/pin/stream anymore. Instead, selects between the shutdown stream and our recv_messages future.

3. Improves performance of the combined_network loop by:

Changing it to use a synchronous lock. It will also now keep going until it receives something deserializable, instead of returning an empty message

This PR does not:

Make any further improvements to ConnectedNetwork

Key places to review:

combined_network.rs
network.rs for handle_message()

Testing

Running the examples locally I get a 10x speedup (only tested with combined so far) due to the rewrite of the loop and the removal of the sleep. Now, the combined_network loop will keep receiving until it receives an uncached message instead of sleeping

Comment on lines +180 to +184
MessageKind::Data(message) => match message {
DataMessage::SubmitTransaction(transaction, _) => {
broadcast_event(
Event {
view_number: TYPES::Time::new(1),
event: EventType::ExternalMessageReceived(data),
},
&self.external_event_stream,
Arc::new(HotShotEvent::TransactionsRecv(vec![transaction])),
&self.internal_event_stream,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this was the whole reason for the batching of messages, to collect transactions. Doesn't seem worth keeping to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was also to potentially increase throughput by decreasing context switching, but we were not really making use of it in the way we could have. If we end up having better facilities in later for batching (e.g. a message type that is a vec of messages), I might consider reintroducing some form of batching

@@ -106,7 +108,7 @@ impl<TYPES: NodeType> CombinedNetworks<TYPES> {

Self {
networks,
message_cache: Arc::new(RwLock::new(LruCache::new(
message_cache: Arc::new(PlRwLock::new(LruCache::new(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the switch to parking lot library?

Copy link
Collaborator Author

@rob-maron rob-maron Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original was an async lock, which is slower and we would really only need if we were holding across .await points.

parking_lot is kind of std++ when it comes to RwLocks/Mutexes, it performs better in most cases and is my goto for a sync lock

Difference is probably negligible, but I was already in there

@rob-maron rob-maron merged commit 2bd0696 into main Sep 12, 2024
36 checks passed
@rob-maron rob-maron deleted the rm/recv-msg branch September 12, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TECH_DEBT] - Don't Sleep When Waiting for Message
3 participants