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 eb2625c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion network/stream/sync_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const (
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 eb2625c

Please sign in to comment.