feat: add per-piece download duration metric split by traffic type - #2017
Merged
gaius-qi merged 2 commits intoAug 28, 2026
Conversation
sophiephoon-canva
requested review from
BruceAko,
ClementMaH,
chlins,
mingcheng,
xujihui1985 and
yyzai384
August 27, 2026 02:40
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2017 +/- ##
==========================================
+ Coverage 54.18% 54.40% +0.21%
==========================================
Files 101 101
Lines 27237 27427 +190
==========================================
+ Hits 14759 14921 +162
- Misses 12478 12506 +28
🚀 New features to boost your workflow:
|
… write Previously, `collect_download_piece_duration_metrics` was called immediately after the network transfer completed, before the piece was written to storage. This caused duration metrics to exclude storage write time and to be recorded even on storage failures. Now the metric is collected only inside the success branch after `storage` confirms the piece is written. Signed-off-by: Gaius <gaius.qi@gmail.com>
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
Adds a new download_piece_duration_milliseconds histogram, labeled by type (LOCAL_PEER, REMOTE_PEER, BACK_TO_SOURCE), that records how long each piece download takes broken out by traffic source.
Currently, download_task_duration_milliseconds only reports latency at the whole-task level, and its task_type label reflects the TaskType enum (STANDARD/PERSISTENT/PERSISTENT_CACHE/CACHE) rather than where the data came from. There is no existing metric that lets you compare p2p latency against back-to-source latency against local-cache latency — this PR adds one.
Changes:
The stub functions that only tally traffic bytes for an already-completed local-cache hit (download_from_local, download_persistent_from_local, download_persistent_cache_from_local) are intentionally left untouched — they do no real I/O, so there's nothing meaningful to time there.
In every case, the timer starts immediately before the network/storage call being measured and stops immediately after, excluding rate-limiter waits and unrelated bookkeeping (piece-started/failed storage calls), so all three traffic types are measured over a comparable window.
Related Issue
#2016
Motivation and Context
We wanted a Grafana panel showing download latency split by p2p vs. back-to-source vs. local-cache for our Dragonfly client fleet. The existing task_type label on download_task_duration_milliseconds looked like it should provide this, but it's actually the TaskType enum (standard/persistent/cache) and is constant across normal workloads, so it can't answer that question. The traffic-source distinction (TrafficType) already exists on the byte-counter metric (download_traffic) but had no corresponding duration metric. This PR closes that gap without touching any existing metric's behavior.
Screenshots (if appropriate)