Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Remove Stream impl for DirectoryMonitor #1078

Merged
merged 5 commits into from
Jul 16, 2021
Merged

Conversation

ranweiler
Copy link
Member

@ranweiler ranweiler commented Jul 16, 2021

The manual implementation of Stream for DirectoryMonitor misused the Waker provided by poll_next(). In practice, this resulted in telling the executor to poll the stream again immediately after any non-terminal try_recv(). The end result was equivalent to calling try_recv() in a tight loop. This pegged agent CPU usage as soon as we started monitoring directories for new files.

Now, we take a much simpler approach. The private into_async() shim function spawns a thread that blocks on new (synchronous) Receiver messages, and then immediately sends them to an unbounded async Receiver. All subsequent API surface can thus be effortlessly async.

DirectoryMonitor now exports a public next_file() async method, which is equivalent in practice to implementing Stream. We aren't using any Stream combinators, we don't lose anything in doing this. We can also use this to impl Stream again later, if needed.

  • Locally tested that agent directory monitoring use sites pick up new files
  • Confirmed that agent CPU usage drops from 100% to < 1%.
  • Manually tested tasks on deployed instance

src/agent/onefuzz/src/monitor.rs Outdated Show resolved Hide resolved
src/agent/onefuzz/src/monitor.rs Outdated Show resolved Hide resolved
@bmc-msft bmc-msft merged commit 517aa54 into microsoft:main Jul 16, 2021
@ranweiler ranweiler deleted the dir-mon branch July 16, 2021 17:12
@ghost ghost locked as resolved and limited conversation to collaborators Aug 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants