Skip to content

Commit a9e6626

Browse files
authored
eth/fetcher: add metrics for tracking slow peers (#32964)
This PR introduces two new metrics to monitor slow peers - One tracks the number of slow peers. - The other measures the time it takes for those peers to become "unfrozen" These metrics help with monitoring and evaluating the need for future optimization of the transaction fetcher and peer management, for example i n peer scoring and prioritization. Additionally, this PR moves the fetcher metrics into a separate file, `eth/fetcher/metrics.go`.
1 parent 0ec6327 commit a9e6626

File tree

2 files changed

+68
-30
lines changed

2 files changed

+68
-30
lines changed

eth/fetcher/metrics.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2025 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/
16+
17+
// Contains the metrics collected by the txfetcher.
18+
19+
package fetcher
20+
21+
import "github.com/ethereum/go-ethereum/metrics"
22+
23+
var (
24+
txAnnounceInMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/announces/in", nil)
25+
txAnnounceKnownMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/announces/known", nil)
26+
txAnnounceUnderpricedMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/announces/underpriced", nil)
27+
txAnnounceDOSMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/announces/dos", nil)
28+
29+
txBroadcastInMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/broadcasts/in", nil)
30+
txBroadcastKnownMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/broadcasts/known", nil)
31+
txBroadcastUnderpricedMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/broadcasts/underpriced", nil)
32+
txBroadcastOtherRejectMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/broadcasts/otherreject", nil)
33+
34+
txRequestOutMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/request/out", nil)
35+
txRequestFailMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/request/fail", nil)
36+
txRequestDoneMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/request/done", nil)
37+
txRequestTimeoutMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/request/timeout", nil)
38+
39+
txReplyInMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/replies/in", nil)
40+
txReplyKnownMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/replies/known", nil)
41+
txReplyUnderpricedMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/replies/underpriced", nil)
42+
txReplyOtherRejectMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/replies/otherreject", nil)
43+
44+
txFetcherWaitingPeers = metrics.NewRegisteredGauge("eth/fetcher/transaction/waiting/peers", nil)
45+
txFetcherWaitingHashes = metrics.NewRegisteredGauge("eth/fetcher/transaction/waiting/hashes", nil)
46+
txFetcherQueueingPeers = metrics.NewRegisteredGauge("eth/fetcher/transaction/queueing/peers", nil)
47+
txFetcherQueueingHashes = metrics.NewRegisteredGauge("eth/fetcher/transaction/queueing/hashes", nil)
48+
txFetcherFetchingPeers = metrics.NewRegisteredGauge("eth/fetcher/transaction/fetching/peers", nil)
49+
txFetcherFetchingHashes = metrics.NewRegisteredGauge("eth/fetcher/transaction/fetching/hashes", nil)
50+
51+
txFetcherSlowPeers = metrics.NewRegisteredGauge("eth/fetcher/transaction/slow/peers", nil)
52+
// Note: this metric does not mean that the fetching of a transaction
53+
// was blocked by a specific peer during this period, since we request
54+
// another peer to fetch the same transaction hash.
55+
// The purpose of this metric is to measure how long it takes for a slow peer
56+
// to become "unfrozen", either by eventually replying to the request
57+
// or by being dropped, measuring from the moment the request was sent.
58+
txFetcherSlowWait = metrics.NewRegisteredHistogram("eth/fetcher/transaction/slow/wait", nil, metrics.NewExpDecaySample(1028, 0.015))
59+
)

eth/fetcher/tx_fetcher.go

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/ethereum/go-ethereum/core/txpool"
3131
"github.com/ethereum/go-ethereum/core/types"
3232
"github.com/ethereum/go-ethereum/log"
33-
"github.com/ethereum/go-ethereum/metrics"
3433
)
3534

3635
const (
@@ -80,35 +79,6 @@ var (
8079
txFetchTimeout = 5 * time.Second
8180
)
8281

83-
var (
84-
txAnnounceInMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/announces/in", nil)
85-
txAnnounceKnownMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/announces/known", nil)
86-
txAnnounceUnderpricedMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/announces/underpriced", nil)
87-
txAnnounceDOSMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/announces/dos", nil)
88-
89-
txBroadcastInMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/broadcasts/in", nil)
90-
txBroadcastKnownMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/broadcasts/known", nil)
91-
txBroadcastUnderpricedMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/broadcasts/underpriced", nil)
92-
txBroadcastOtherRejectMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/broadcasts/otherreject", nil)
93-
94-
txRequestOutMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/request/out", nil)
95-
txRequestFailMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/request/fail", nil)
96-
txRequestDoneMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/request/done", nil)
97-
txRequestTimeoutMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/request/timeout", nil)
98-
99-
txReplyInMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/replies/in", nil)
100-
txReplyKnownMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/replies/known", nil)
101-
txReplyUnderpricedMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/replies/underpriced", nil)
102-
txReplyOtherRejectMeter = metrics.NewRegisteredMeter("eth/fetcher/transaction/replies/otherreject", nil)
103-
104-
txFetcherWaitingPeers = metrics.NewRegisteredGauge("eth/fetcher/transaction/waiting/peers", nil)
105-
txFetcherWaitingHashes = metrics.NewRegisteredGauge("eth/fetcher/transaction/waiting/hashes", nil)
106-
txFetcherQueueingPeers = metrics.NewRegisteredGauge("eth/fetcher/transaction/queueing/peers", nil)
107-
txFetcherQueueingHashes = metrics.NewRegisteredGauge("eth/fetcher/transaction/queueing/hashes", nil)
108-
txFetcherFetchingPeers = metrics.NewRegisteredGauge("eth/fetcher/transaction/fetching/peers", nil)
109-
txFetcherFetchingHashes = metrics.NewRegisteredGauge("eth/fetcher/transaction/fetching/hashes", nil)
110-
)
111-
11282
var errTerminated = errors.New("terminated")
11383

11484
// txAnnounce is the notification of the availability of a batch
@@ -635,6 +605,7 @@ func (f *TxFetcher) loop() {
635605
}
636606
// Keep track of the request as dangling, but never expire
637607
f.requests[peer].hashes = nil
608+
txFetcherSlowPeers.Inc(1)
638609
}
639610
}
640611
// Schedule a new transaction retrieval
@@ -728,6 +699,10 @@ func (f *TxFetcher) loop() {
728699
log.Warn("Unexpected transaction delivery", "peer", delivery.origin)
729700
break
730701
}
702+
if req.hashes == nil {
703+
txFetcherSlowPeers.Dec(1)
704+
txFetcherSlowWait.Update(time.Duration(f.clock.Now() - req.time).Nanoseconds())
705+
}
731706
delete(f.requests, delivery.origin)
732707

733708
// Anything not delivered should be re-scheduled (with or without
@@ -807,6 +782,10 @@ func (f *TxFetcher) loop() {
807782
}
808783
delete(f.fetching, hash)
809784
}
785+
if request.hashes == nil {
786+
txFetcherSlowPeers.Dec(1)
787+
txFetcherSlowWait.Update(time.Duration(f.clock.Now() - request.time).Nanoseconds())
788+
}
810789
delete(f.requests, drop.peer)
811790
}
812791
// Clean up general announcement tracking

0 commit comments

Comments
 (0)