diff --git a/core/commands/stat.go b/core/commands/stat.go index ad9a576ee9c..94286703c61 100644 --- a/core/commands/stat.go +++ b/core/commands/stat.go @@ -93,6 +93,11 @@ Example: return } + if nd.Reporter == nil { + res.SetError(fmt.Errorf("bandwidth reporter disabled in config"), cmds.ErrNormal) + return + } + pstr, pfound, err := req.Option("peer").String() if err != nil { res.SetError(err, cmds.ErrNormal) diff --git a/core/core.go b/core/core.go index adadc1920f3..acc59bbb191 100644 --- a/core/core.go +++ b/core/core.go @@ -143,9 +143,6 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin return err } - // Set reporter - n.Reporter = metrics.NewBandwidthCounter() - // get undialable addrs from config cfg, err := n.Repo.Config() if err != nil { @@ -160,6 +157,11 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin addrfilter = append(addrfilter, f) } + if !cfg.Swarm.DisableBandwidthMetrics { + // Set reporter + n.Reporter = metrics.NewBandwidthCounter() + } + peerhost, err := hostOption(ctx, n.Identity, n.Peerstore, n.Reporter, addrfilter) if err != nil { return err diff --git a/docs/config.md b/docs/config.md index 87f100c7f9a..bd9395bcfb2 100644 --- a/docs/config.md +++ b/docs/config.md @@ -213,5 +213,10 @@ Options for configuring the swarm. An array of address filters (multiaddr netmasks) to filter dials to. See https://github.com/ipfs/go-ipfs/issues/1226#issuecomment-120494604 for more information. +- `DisableBandwidthMetrics` +A boolean value that when set to true, will cause ipfs to not keep track of +bandwidth metrics. Disabling bandwidth metrics can lead to a slight performance +improvement, as well as a reduction in memory usage. + ## `Tour` Unused. diff --git a/repo/config/swarm.go b/repo/config/swarm.go index d398b3d80af..7d074d996d2 100644 --- a/repo/config/swarm.go +++ b/repo/config/swarm.go @@ -1,5 +1,6 @@ package config type SwarmConfig struct { - AddrFilters []string + AddrFilters []string + DisableBandwidthMetrics bool }