Skip to content

refactor(sysinfo): collect network stats in a background task shared via watch channel - #2029

Merged
gaius-qi merged 2 commits into
mainfrom
feature/network
Sep 2, 2026
Merged

refactor(sysinfo): collect network stats in a background task shared via watch channel#2029
gaius-qi merged 2 commits into
mainfrom
feature/network

Conversation

@gaius-qi

@gaius-qi gaius-qi commented Sep 2, 2026

Copy link
Copy Markdown
Member

Description

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.

Related Issue

Fixed #2020

Motivation and Context

Screenshots (if appropriate)

…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 gaius-qi added this to the v2.6.0 milestone Sep 2, 2026
@gaius-qi gaius-qi self-assigned this Sep 2, 2026
@gaius-qi
gaius-qi requested review from a team as code owners September 2, 2026 07:17
@gaius-qi gaius-qi added the enhancement New feature or request label Sep 2, 2026
@gaius-qi
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

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.61%. Comparing base (37bb7cb) to head (ff7e930).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
dragonfly-client-util/src/sysinfo/network.rs 82.08% 12 Missing ⚠️
dragonfly-client/src/grpc/dfdaemon_upload.rs 0.00% 2 Missing ⚠️
dragonfly-client/src/announcer/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
dragonfly-client/src/announcer/mod.rs 0.00% <0.00%> (ø)
dragonfly-client/src/grpc/dfdaemon_upload.rs 0.00% <0.00%> (ø)
dragonfly-client-util/src/sysinfo/network.rs 84.92% <82.08%> (+51.25%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaius-qi
gaius-qi merged commit 9733472 into main Sep 2, 2026
7 checks passed
@gaius-qi
gaius-qi deleted the feature/network branch September 2, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(client): coalesce network sampling so SyncHost cannot delay AnnounceHost

3 participants