Skip to content

Optimize gossip score calculation #184

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

Merged
merged 12 commits into from
Mar 26, 2021

Conversation

Nashatyrev
Copy link
Collaborator

Description

On every inbound message GossipRouter checks the peer score against graylistThreshold to decide whether a message should be processed or ignored.
The score calculation is not too cheap for extensive inbound message flow.

The following optimizations were made:

  • Cache PeerHandler.getIP()
  • Cache topic score unless any of input values changed or time changed more than timeInMeshQuantum. Ideally that should be made on something like Rx ObservableValues and Bindings to look nicer but that seems like an overkill for this change
  • Maintain whitelist with expiration and message count for acceptRequestsFrom for peers with non-negative score to avoid score recalculation for every inbound message. The basic idea behind is that graylistThreshold should be far below 0 and if a peer has the score 0 or above we could unconditionally accept some reasonable amount of its messages for say 1 second.

Performance

Profiling graph of AbstractRouter.onInbound()

Before

изображение

After

изображение

@Nashatyrev Nashatyrev merged commit fd324a3 into libp2p:develop Mar 26, 2021
@mbaxter mbaxter mentioned this pull request Mar 31, 2021
@Nashatyrev Nashatyrev deleted the optimize/gossip-score branch August 16, 2022 08:40
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.

2 participants