mirror of
https://github.com/uqbar-dao/nectar.git
synced 2025-01-03 06:11:01 +03:00
fds limit fixes
This commit is contained in:
parent
8f28f5486c
commit
7128350746
@ -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::<anyhow::Result<()>>::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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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?;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user