Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The following emojis are used to highlight certain changes:
### Changed

- upgrade to `go-libp2p` [v0.41.1](https://github.com/libp2p/go-libp2p/releases/tag/v0.41.1)
- `bitswap/network`: Add a new `requests_in_flight` metric gauge that measures how many bitswap streams are being written or read at a given time.

### Removed

Expand Down
9 changes: 9 additions & 0 deletions bitswap/network/bsnet/ipfs_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ func (bsnet *impl) msgToStream(ctx context.Context, s network.Stream, msg bsmsg.
log.Warnf("error setting deadline: %s", err)
}

bsnet.metrics.RequestsInFlight.Inc()
defer bsnet.metrics.RequestsInFlight.Dec()

// Older Bitswap versions use a slightly different wire format so we need
// to convert the message to the appropriate format depending on the remote
// peer's Bitswap version.
Expand Down Expand Up @@ -423,6 +426,12 @@ func (bsnet *impl) DisconnectFrom(ctx context.Context, p peer.ID) error {
func (bsnet *impl) handleNewStream(s network.Stream) {
defer s.Close()

// In HTTPnet this metric measures sending the request and reading the
// response.
// In bitswap these are de-coupled, but we can measure them separately.
bsnet.metrics.RequestsInFlight.Inc()
defer bsnet.metrics.RequestsInFlight.Dec()

if len(bsnet.receivers) == 0 {
_ = s.Reset()
return
Expand Down
6 changes: 6 additions & 0 deletions bitswap/network/bsnet/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var durationHistogramBuckets = []float64{0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 30,

var blockSizesHistogramBuckets = []float64{1, 128 << 10, 256 << 10, 512 << 10, 1024 << 10, 2048 << 10, 4092 << 10}

func requestsInFlight(ctx context.Context) imetrics.Gauge {
return imetrics.NewCtx(ctx, "requests_in_flight", "Current number of in-flight requests").Gauge()
}

func responseSizes(ctx context.Context) imetrics.Histogram {
return imetrics.NewCtx(ctx, "response_bytes", "Histogram of bitswap response sizes").Histogram(blockSizesHistogramBuckets)
}
Expand All @@ -27,6 +31,7 @@ func wantlistsSeconds(ctx context.Context) imetrics.Histogram {
}

type metrics struct {
RequestsInFlight imetrics.Gauge
WantlistsTotal imetrics.Counter
WantlistsItemsTotal imetrics.Counter
WantlistsSeconds imetrics.Histogram
Expand All @@ -37,6 +42,7 @@ func newMetrics() *metrics {
ctx := imetrics.CtxScope(context.Background(), "exchange_bitswap")

return &metrics{
RequestsInFlight: requestsInFlight(ctx),
WantlistsTotal: wantlistsTotal(ctx),
WantlistsItemsTotal: wantlistsItemsTotal(ctx),
WantlistsSeconds: wantlistsSeconds(ctx),
Expand Down
Loading