refactor(sysinfo): collect network stats in a background task shared via watch channel - #2029
Merged
Conversation
…via watch channel Replace the per-call mutex-guarded measurement in `Network::get_stats` with a single `StatsCollector` task spawned at construction that samples the interface every second and publishes results through a `tokio::sync::watch` channel. Callers now clone the receiver and await the next unseen sample, so concurrent callers no longer serialize behind a lock and each wait a full interval; a fresh clone gets the latest stats immediately. `get_stats` now takes `&mut self` and returns `Option<NetworkStats>`, yielding `None` once the collector has stopped. The scheduler announcer maps that case to an error and the upload server's sync_host loop exits cleanly. `Network::new` must be called within a tokio runtime since it spawns the collector. Adds a test covering concurrent and sequential reads. Signed-off-by: Gaius <gaius.qi@gmail.com>
gaius-qi
requested review from
BruceAko,
Fricounet,
Zephyrcf,
hhhhsdxxxx,
imeoer and
mingcheng
September 2, 2026 07:17
gaius-qi
enabled auto-merge (squash)
September 2, 2026 07:20
Update the workspace package version and all internal dragonfly-client crate dependency versions from 1.5.3 to 1.5.4 for the next release. Signed-off-by: Gaius <gaius.qi@gmail.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2029 +/- ##
==========================================
+ Coverage 54.40% 54.61% +0.21%
==========================================
Files 101 101
Lines 27427 27454 +27
==========================================
+ Hits 14921 14994 +73
+ Misses 12506 12460 -46
🚀 New features to boost your workflow:
|
hhhhsdxxxx
approved these changes
Sep 2, 2026
EvanCley
approved these changes
Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replace the per-call mutex-guarded measurement in
Network::get_statswith a singleStatsCollectortask spawned at construction that samples the interface every second and publishes results through atokio::sync::watchchannel. Callers now clone the receiver and await the next unseen sample, so concurrent callers no longer serialize behind a lock and each wait a full interval; a fresh clone gets the latest stats immediately.get_statsnow takes&mut selfand returnsOption<NetworkStats>, yieldingNoneonce the collector has stopped. The scheduler announcer maps that case to an error and the upload server's sync_host loop exits cleanly.Network::newmust be called within a tokio runtime since it spawns the collector. Adds a test covering concurrent and sequential reads.Related Issue
Fixed #2020
Motivation and Context
Screenshots (if appropriate)