Simplify watch event passing by dropping events rather than blocking the hot code path

pull/118/head
Chip Senkbeil 2 years ago
parent 6991543ff7
commit e51392fcde
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -10,9 +10,6 @@ pub const CLIENT_WATCHER_CAPACITY: usize = 100;
/// Capacity associated with the server's file watcher to pass events outbound
pub const SERVER_WATCHER_CAPACITY: usize = 10000;
/// Duration in milliseconds to sleep when reaching maximum watcher events in queue
pub const SERVER_WATCHER_PAUSE_MILLIS: u64 = 100;
/// Represents the maximum size (in bytes) that data will be read from pipes
/// per individual `read` call
///

@ -1,5 +1,5 @@
use crate::{
constants::{SERVER_WATCHER_CAPACITY, SERVER_WATCHER_PAUSE_MILLIS},
constants::SERVER_WATCHER_CAPACITY,
data::{
self, Change, ChangeKind, ChangeKindSet, DirEntry, FileType, Metadata, PtySize, Request,
RequestData, Response, ResponseData, RunningProcess, SystemInfo,
@ -19,7 +19,7 @@ use std::{
path::{Path, PathBuf},
pin::Pin,
sync::Arc,
time::{Duration, SystemTime},
time::SystemTime,
};
use tokio::{
io::{self, AsyncWriteExt},
@ -406,28 +406,16 @@ where
// with a large volume of watch requests
let (tx, mut rx) = mpsc::channel(SERVER_WATCHER_CAPACITY);
let mut watcher = notify::recommended_watcher(move |res| {
let mut res = res;
// Attempt to send our result, breaking out of the loop
// if we succeed or it is impossible, otherwise trying
// again after a brief sleep
loop {
match tx.try_send(res) {
Ok(_) => break,
Err(TrySendError::Full(x)) => {
warn!(
"Reached watcher capacity of {}! Trying again after {}ms",
SERVER_WATCHER_CAPACITY, SERVER_WATCHER_PAUSE_MILLIS
);
res = x;
std::thread::sleep(Duration::from_millis(SERVER_WATCHER_PAUSE_MILLIS));
}
Err(TrySendError::Closed(_)) => {
warn!("Skipping watch event because watcher channel closed");
break;
}
}
let mut watcher = notify::recommended_watcher(move |res| match tx.try_send(res) {
Ok(_) => {}
Err(TrySendError::Full(_)) => {
warn!(
"Reached watcher capacity of {}! Dropping watcher event!",
SERVER_WATCHER_CAPACITY,
);
}
Err(TrySendError::Closed(_)) => {
warn!("Skipping watch event because watcher channel closed");
}
})?;

Loading…
Cancel
Save