From 7128350746f2070ebddcbdd21782c56b1bd7375a Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Fri, 4 Oct 2024 18:35:23 -0400 Subject: [PATCH] fds limit fixes --- kinode/src/net/mod.rs | 7 ++++--- kinode/src/net/types.rs | 9 ++++----- kinode/src/vfs.rs | 6 ++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/kinode/src/net/mod.rs b/kinode/src/net/mod.rs index 52bc2216..11226dc2 100644 --- a/kinode/src/net/mod.rs +++ b/kinode/src/net/mod.rs @@ -71,7 +71,7 @@ pub async fn networking( active_passthroughs, max_peers, max_passthroughs, - fds_limit: 100, // TODO blocking request to fd_manager to get max num of fds at boot + fds_limit: 10, // small hardcoded limit that gets replaced by fd_manager soon after boot }; let mut tasks = JoinSet::>::new(); @@ -349,9 +349,10 @@ async fn handle_fdman(km: &KernelMessage, request_body: &[u8], data: &mut NetDat if data.max_passthroughs > fds_limit { data.max_passthroughs = fds_limit; } - // TODO cull passthroughs too? + // TODO cull passthroughs too if data.peers.peers().len() >= data.fds_limit as usize { - data.peers.cull(2).await; + let diff = data.peers.peers().len() - data.fds_limit as usize; + data.peers.cull(diff).await; } } _ => return, diff --git a/kinode/src/net/types.rs b/kinode/src/net/types.rs index 67cb1285..f5119283 100644 --- a/kinode/src/net/types.rs +++ b/kinode/src/net/types.rs @@ -115,13 +115,12 @@ impl Peers { self.peers.remove(name) } - /// close the (peer count / fraction) oldest connections - pub async fn cull(&self, fraction: u64) { - let num_to_remove = (self.peers.len() as f64 / fraction as f64).ceil() as usize; - let mut to_remove = Vec::with_capacity(num_to_remove); + /// close the n oldest connections + pub async fn cull(&self, n: usize) { + let mut to_remove = Vec::with_capacity(n); let mut sorted_peers: Vec<_> = self.peers.iter().collect(); sorted_peers.sort_by_key(|p| p.last_message); - to_remove.extend(sorted_peers.iter().take(num_to_remove)); + to_remove.extend(sorted_peers.iter().take(n)); for peer in to_remove { self.peers.remove(&peer.identity.name); } diff --git a/kinode/src/vfs.rs b/kinode/src/vfs.rs index 87f65d30..2c8f43a2 100644 --- a/kinode/src/vfs.rs +++ b/kinode/src/vfs.rs @@ -165,7 +165,7 @@ impl Files { access_order: Arc::new(Mutex::new(UniqueQueue::new())), our, send_to_loop, - fds_limit: 100, // TODO blocking request to fd_manager to get max num of fds at boot + fds_limit: 10, // small hardcoded limit that gets replaced by fd_manager soon after boot } } @@ -1031,9 +1031,7 @@ async fn handle_fd_request(km: KernelMessage, files: &mut Files) -> anyhow::Resu crate::fd_manager::send_fd_manager_hit_fds_limit(&files.our, &files.send_to_loop) .await; files - .close_least_recently_used_files( - (files.open_files.len() as u64 - fds_limit) / 2, - ) + .close_least_recently_used_files(files.open_files.len() as u64 - fds_limit) .await?; } }