@cryptotaxi247 / kubo / commits / 26cb182ba

Introduce block and dup histograms to bitswap

License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jakub Sztandera committed Jan 20, 2017 at 14:09 UTC 26cb182ba84a78803677cfb35c4940aaf6939d7b
1 file changed +20 -1
exchange/bitswap/bitswap.go
+20 -1
@@ -19,6 +19,7 @@ import (
19 flags "github.com/ipfs/go-ipfs/flags"
20 "github.com/ipfs/go-ipfs/thirdparty/delay"
21
22 + metrics "gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
23 process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
24 procctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
25 logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
@@ -47,6 +48,9 @@ var (
48 HasBlockBufferSize = 256
49 provideKeysBufferSize = 2048
50 provideWorkerMax = 512
51 +
52 + // the 1<<18+15 is to observe old file chunks that are 1<<18 + 14 in size
53 + metricsBuckets = []float64{1 << 6, 1 << 10, 1 << 14, 1 << 18, 1<<18 + 15, 1 << 22}
54 )
55
56 func init() {
@@ -74,6 +78,11 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
78 // shouldn't accept a context anymore. Clients should probably use Close()
79 // exclusively. We should probably find another way to share logging data
80 ctx, cancelFunc := context.WithCancel(parent)
81 + ctx = metrics.CtxSubScope(ctx, "bitswap")
82 + dupHist := metrics.NewCtx(ctx, "dup_blocks_bytes", "Summary of duplicate"+
83 + " data blocks recived").Histogram(metricsBuckets)
84 + allHist := metrics.NewCtx(ctx, "all_blocks_bytes", "Summary of all"+
85 + " data blocks recived").Histogram(metricsBuckets)
86
87 notif := notifications.New()
88 px := process.WithTeardown(func() error {
@@ -91,6 +100,9 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
100 newBlocks: make(chan *cid.Cid, HasBlockBufferSize),
101 provideKeys: make(chan *cid.Cid, provideKeysBufferSize),
102 wm: NewWantManager(ctx, network),
103 +
104 + dupMetric: dupHist,
105 + allMetric: allHist,
106 }
107 go bs.wm.Run()
108 network.SetDelegate(bs)
@@ -145,6 +157,10 @@ type Bitswap struct {
157 blocksRecvd int
158 dupBlocksRecvd int
159 dupDataRecvd uint64
160 +
161 + // Metrics interface metrics
162 + dupMetric metrics.Histogram
163 + allMetric metrics.Histogram
164 }
165
166 type blockRequest struct {
@@ -373,6 +389,8 @@ var ErrAlreadyHaveBlock = errors.New("already have block")
389 func (bs *Bitswap) updateReceiveCounters(b blocks.Block) error {
390 bs.counterLk.Lock()
391 defer bs.counterLk.Unlock()
392 + blkLen := len(b.RawData())
393 + bs.allMetric.Observe(float64(blkLen))
394 bs.blocksRecvd++
395 has, err := bs.blockstore.Has(b.Cid())
396 if err != nil {
@@ -380,8 +398,9 @@ func (bs *Bitswap) updateReceiveCounters(b blocks.Block) error {
398 return err
399 }
400 if err == nil && has {
401 + bs.dupMetric.Observe(float64(blkLen))
402 bs.dupBlocksRecvd++
384 - bs.dupDataRecvd += uint64(len(b.RawData()))
403 + bs.dupDataRecvd += uint64(blkLen)
404 }
405
406 if has {