mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 02:30:39 +08:00
Introduce sent blocks histogram
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
@ -79,9 +79,9 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
|
||||
// exclusively. We should probably find another way to share logging data
|
||||
ctx, cancelFunc := context.WithCancel(parent)
|
||||
ctx = metrics.CtxSubScope(ctx, "bitswap")
|
||||
dupHist := metrics.NewCtx(ctx, "dup_blocks_bytes", "Summary of duplicate"+
|
||||
dupHist := metrics.NewCtx(ctx, "recv_dup_blocks_bytes", "Summary of duplicate"+
|
||||
" data blocks recived").Histogram(metricsBuckets)
|
||||
allHist := metrics.NewCtx(ctx, "all_blocks_bytes", "Summary of all"+
|
||||
allHist := metrics.NewCtx(ctx, "recv_all_blocks_bytes", "Summary of all"+
|
||||
" data blocks recived").Histogram(metricsBuckets)
|
||||
|
||||
notif := notifications.New()
|
||||
|
@ -30,24 +30,28 @@ type WantManager struct {
|
||||
ctx context.Context
|
||||
cancel func()
|
||||
|
||||
metricWantlist metrics.Gauge
|
||||
wantlistGauge metrics.Gauge
|
||||
sentHistogram metrics.Histogram
|
||||
}
|
||||
|
||||
func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantManager {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
wantlistGauge := metrics.NewCtx(ctx, "wanlist_total",
|
||||
"Number of items in wantlist.").Gauge()
|
||||
sentHistogram := metrics.NewCtx(ctx, "sent_all_blocks_bytes", "Histogram of blocks sent by"+
|
||||
" this bitswap").Histogram(metricsBuckets)
|
||||
return &WantManager{
|
||||
incoming: make(chan []*bsmsg.Entry, 10),
|
||||
connect: make(chan peer.ID, 10),
|
||||
disconnect: make(chan peer.ID, 10),
|
||||
peerReqs: make(chan chan []peer.ID),
|
||||
peers: make(map[peer.ID]*msgQueue),
|
||||
wl: wantlist.NewThreadSafe(),
|
||||
network: network,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
metricWantlist: wantlistGauge,
|
||||
incoming: make(chan []*bsmsg.Entry, 10),
|
||||
connect: make(chan peer.ID, 10),
|
||||
disconnect: make(chan peer.ID, 10),
|
||||
peerReqs: make(chan chan []peer.ID),
|
||||
peers: make(map[peer.ID]*msgQueue),
|
||||
wl: wantlist.NewThreadSafe(),
|
||||
network: network,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
wantlistGauge: wantlistGauge,
|
||||
sentHistogram: sentHistogram,
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,6 +120,8 @@ func (pm *WantManager) SendBlock(ctx context.Context, env *engine.Envelope) {
|
||||
// throughout the network stack
|
||||
defer env.Sent()
|
||||
|
||||
pm.sentHistogram.Observe(float64(len(env.Block.RawData())))
|
||||
|
||||
msg := bsmsg.New(false)
|
||||
msg.AddBlock(env.Block)
|
||||
log.Infof("Sending block %s to %s", env.Block, env.Peer)
|
||||
@ -289,12 +295,12 @@ func (pm *WantManager) Run() {
|
||||
for _, e := range entries {
|
||||
if e.Cancel {
|
||||
if pm.wl.Remove(e.Cid) {
|
||||
pm.metricWantlist.Dec()
|
||||
pm.wantlistGauge.Dec()
|
||||
filtered = append(filtered, e)
|
||||
}
|
||||
} else {
|
||||
if pm.wl.AddEntry(e.Entry) {
|
||||
pm.metricWantlist.Inc()
|
||||
pm.wantlistGauge.Inc()
|
||||
filtered = append(filtered, e)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user