Skip to content

Commit

Permalink
Merge pull request #3381 from ipfs/feat/disable-bw-stats
Browse files Browse the repository at this point in the history
add config option to disable bandwidth metrics
  • Loading branch information
whyrusleeping authored Nov 16, 2016
2 parents 1a365a8 + 43d6683 commit afa1f15
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions core/commands/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion repo/config/swarm.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package config

type SwarmConfig struct {
AddrFilters []string
AddrFilters []string
DisableBandwidthMetrics bool
}

0 comments on commit afa1f15

Please sign in to comment.