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

perf(p2p): Change channel.recentlySent to be based on num_messages #2957

Conversation

ValarDragon
Copy link
Collaborator

@ValarDragon ValarDragon commented Apr 30, 2024

Closes #2954

This should make block part gossip not be bottom priority. (though more work is needed to make it match the prioritization expectation)


PR checklist

@ValarDragon ValarDragon requested review from a team as code owners April 30, 2024 22:36
@ValarDragon ValarDragon changed the title Change recently sent to be based on num_messages perf(p2p/connection): Change recently sent to be based on num_messages Apr 30, 2024
@ValarDragon ValarDragon changed the title perf(p2p/connection): Change recently sent to be based on num_messages perf(p2p): Change channel.recentlySent to be based on num_messages Apr 30, 2024
Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

Thanks @ValarDragon ❤️

@melekes melekes added backport-to-v0.37.x Tell Mergify to backport the PR to v0.37.x backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x backport-to-v1.x Tell Mergify to backport the PR to v1.x labels May 1, 2024
@melekes
Copy link
Contributor

melekes commented May 3, 2024

We'll need to test this somehow through our e2e framework or local net to avoid relying on pure reasoning.

@ValarDragon
Copy link
Collaborator Author

Agreed, I also think that in practice this may also need #2955

Copy link
Contributor

@cason cason left a comment

Choose a reason for hiding this comment

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

The problem is not solved by this PR.

The original code compute priorities based on the number of bytes sent in each channel.

The proposed changes update the computation to be based on the number of packets sent in each channel. While it is true that not every packet is full (i.e., contains MaxPacketMsgPayloadSize, default to 1024 bytes), when full packets are exchanged, there is not difference in behavior.

In any case, messages are split into multiple packets to be sent in the channel. If a message is 10x larger than the other, it would be split into about 10x more packets than the other, and the proposed changes won't have any real effect.

@@ -0,0 +1,3 @@
- `[p2p]` Improve the prioritization of which channel to gossip from, by changing channel deprioritization
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `[p2p]` Improve the prioritization of which channel to gossip from, by changing channel deprioritization
- `[p2p]` Change the prioritization of which channel to send packets from, by having de-prioritization

@@ -0,0 +1,3 @@
- `[p2p]` Improve the prioritization of which channel to gossip from, by changing channel deprioritization
to be based on the number of messages in the channel, rather than the size of messages communicated on the channel.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
to be based on the number of messages in the channel, rather than the size of messages communicated on the channel.
to be based on the number of messages rather than the byte size of packets recently sent on the channel.

@@ -755,7 +757,10 @@ type Channel struct {
sendQueueSize int32 // atomic.
recving []byte
sending []byte
recentlySent int64 // exponential moving average
// recentlySent is an exponential moving average of the number of messages sent.
// This is used by the mconnection for choosing what channel to send from next.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// This is used by the mconnection for choosing what channel to send from next.
// This is used for choosing from which channel to send the next packet.

recentlySent int64 // exponential moving average
// recentlySent is an exponential moving average of the number of messages sent.
// This is used by the mconnection for choosing what channel to send from next.
// The exponential decay is done in updateStats.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The exponential decay is done in updateStats.
// The exponential decay is applied every updateStats inverval.

@@ -856,7 +861,8 @@ func (ch *Channel) writePacketMsgTo(w io.Writer) (n int, err error) {
err = ErrPacketWrite{Source: err}
}

atomic.AddInt64(&ch.recentlySent, int64(n))
// increment recentlySent by 1, to denote we sent another message.
Copy link
Contributor

Choose a reason for hiding this comment

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

But this is not a message, but a packet. A message is composed of multiple packets.

@@ -31,7 +31,9 @@ const (
numBatchPacketMsgs = 10
minReadBufferSize = 1024
minWriteBufferSize = 65536
updateStats = 2 * time.Second

updateStats = 2 * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
updateStats = 2 * time.Second
recentlySentDecayInterval = 2 * time.Second

Copy link
Contributor

Choose a reason for hiding this comment

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

Need to rename elsewhere in the code.

Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale For use by stalebot label May 21, 2024
@github-actions github-actions bot closed this May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-v0.37.x Tell Mergify to backport the PR to v0.37.x backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x backport-to-v1.x Tell Mergify to backport the PR to v1.x stale For use by stalebot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make channel prioritization based on number of messages in channel (vs number of bytes sent)
3 participants