Skip to content

HF writes incur heavy context switching #737

Description

@greged93

I'm monitoring 3 log files on a Linux host machine, using the RecommendedWatcher. Writes on the log files happen at HF (around 10k-20k per second). This leads to a very high amount of context switches and interrupts, degrading the performance of my host machine.
I realize there probably isn't a solution for me here (and that I should have expected this before trying to use inotify), but might be nice to document this somewhere as a gotcha.

Below is a screenshot of the context switches, interrupts and CPU schedule timeslices. The high value occur when running the below, low ranges when the watcher is shutdown.

Image Image
        let (fs_event_tx, watcher_rx) = tokio::sync::mpsc::unbounded_channel();
        let mut watcher = recommended_watcher(move |res| {
            let fs_event_tx = fs_event_tx.clone();
            if let Err(err) = fs_event_tx.send(res) {
                error!(target: "feed::file_watcher", ?err, "Failed to send event from recommended watcher");
            }
        })?;

        for source in EventSource::iter() {
            let dir = source.event_source_dir(&dir, batch).canonicalize()?;
            info!(target: "feed::file_watcher", ?dir, "watching file");
            watcher.watch(&dir, RecursiveMode::Recursive)?;
        }

 loop {
            tokio::select! {
                event = watcher_rx.recv() => match event {
                    Some(Ok(event)) => (),
                    Some(Err(err)) => {
                        log_and_panic(&format!("Notify error: {err}"));
                    }
                    None => {
                        log_and_panic("Watcher channel closed");
                    }
                },
                () = tokio::time::sleep(Duration::from_secs(15)) => {
                    log_and_panic("Stream has fallen behind (node failed?)");
                }

            }
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions