Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
stream: add set cache metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
acud committed Nov 28, 2019
1 parent 52fb861 commit 0678d71
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions network/stream/sync_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ import (
const (
syncStreamName = "SYNC"
cacheCapacity = 10000
setCacheCapacity = 50000 // 50000 * 32 = ~1.6mb
setCacheCapacity = 200000 // 200000 * 32 = ~6.4mb mem footprint, 200K chunks ~=800 megs of data
maxBinZeroSyncPeers = 3
)

var (
setCacheMissCount = metrics.GetOrRegisterCounter("network.stream.sync_provider.set.cachemiss", nil)
setCacheHitCount = metrics.GetOrRegisterCounter("network.stream.sync_provider.set.cachehit", nil)
)

type syncProvider struct {
netStore *storage.NetStore // netstore
kad *network.Kademlia // kademlia
Expand All @@ -66,7 +71,7 @@ func NewSyncProvider(ns *storage.NetStore, kad *network.Kademlia, autostart bool
if err != nil {
panic(err)
}
sc, err := lru.New(cacheCapacity)
sc, err := lru.New(setCacheCapacity)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -204,6 +209,9 @@ func (s *syncProvider) Set(ctx context.Context, addrs ...chunk.Address) error {
for _, addr := range addrs {
if _, ok := s.setCache.Get(addr); !ok {
chunksToSet = append(chunksToSet, addr)
setCacheMissCount.Inc(1)
} else {
setCacheHitCount.Inc(1)
}
}
s.setCacheMtx.RUnlock()
Expand Down

0 comments on commit 0678d71

Please sign in to comment.