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

feat(networking): drop SwarmCmds when under load #1898

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions sn_networking/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,39 @@ pub enum SwarmCmd {
FetchCompleted(RecordKey),
}

impl SwarmCmd {
/// Check if the command can be dropped safely in times of high load.
pub(crate) fn can_be_dropped_safely(&self) -> bool {
match self {
SwarmCmd::Dial { .. } => true,
SwarmCmd::DialWithOpts { .. } => true,
SwarmCmd::GetAllLocalPeers { .. } => false,
SwarmCmd::GetKBuckets { .. } => true,
SwarmCmd::GetClosestKLocalPeers { .. } => false,
SwarmCmd::GetClosestPeersToAddressFromNetwork { .. } => true,
SwarmCmd::GetCloseGroupLocalPeers { .. } => false,
SwarmCmd::GetSwarmLocalState { .. } => false,
SwarmCmd::SendRequest { .. } => true,
SwarmCmd::SendResponse { .. } => true,
SwarmCmd::RecordStoreHasKey { .. } => true,
Copy link
Member

@RolandSherwin RolandSherwin Jun 20, 2024

Choose a reason for hiding this comment

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

SwarmCmd::RecordStoreHasKey, GetNetworkRecord are used during put_validation (when accpeting payments), we'd want these in probably, as we seem to prioritize PutRecord commands here.

SwarmCmd::GetAllLocalRecordAddresses { .. } => true,
SwarmCmd::GetNetworkRecord { .. } => true,
SwarmCmd::GetLocalStoreCost { .. } => true,
SwarmCmd::PaymentReceived => false,
SwarmCmd::GetLocalRecord { .. } => true,
SwarmCmd::PutRecord { .. } => false,
SwarmCmd::PutRecordTo { .. } => false,
SwarmCmd::PutLocalRecord { .. } => false,
SwarmCmd::RemoveFailedLocalRecord { .. } => false,
SwarmCmd::AddLocalRecordAsStored { .. } => false,
SwarmCmd::TriggerIntervalReplication => true,
SwarmCmd::RecordNodeIssue { .. } => false,
SwarmCmd::IsPeerShunned { .. } => true,
SwarmCmd::QuoteVerification { .. } => false,
SwarmCmd::FetchCompleted { .. } => false,
}
}
}
/// Debug impl for SwarmCmd to avoid printing full Record, instead only RecodKey
/// and RecordKind are printed.
impl Debug for SwarmCmd {
Expand Down
5 changes: 5 additions & 0 deletions sn_networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,11 @@ pub(crate) fn send_swarm_cmd(swarm_cmd_sender: Sender<SwarmCmd>, cmd: SwarmCmd)
let capacity = swarm_cmd_sender.capacity();

if capacity == 0 {
if cmd.can_be_dropped_safely() {
warn!("Dropping {cmd:?} as we're at max capacity");
return;
}

error!(
"SwarmCmd channel is full. Await capacity to send: {:?}",
cmd
Expand Down
Loading