Skip to content

Commit

Permalink
export read bytes per second
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Mar 5, 2019
1 parent a6a3ea8 commit e51c51c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
30 changes: 19 additions & 11 deletions internal/piececache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ type Cache struct {
m sync.RWMutex
sem *semaphore.Semaphore

numCached metrics.EWMA
numTotal metrics.EWMA
numLoad metrics.EWMA
numCached metrics.EWMA
numTotal metrics.EWMA
numLoad metrics.EWMA
loadedBytes metrics.EWMA

closeC chan struct{}
}
Expand All @@ -28,14 +29,15 @@ type Loader func() ([]byte, error)

func New(maxSize int64, ttl time.Duration, parallelReads uint) *Cache {
c := &Cache{
maxSize: maxSize,
ttl: ttl,
items: make(map[string]*item),
sem: semaphore.New(int(parallelReads)),
numCached: metrics.NewEWMA1(),
numTotal: metrics.NewEWMA1(),
numLoad: metrics.NewEWMA1(),
closeC: make(chan struct{}),
maxSize: maxSize,
ttl: ttl,
items: make(map[string]*item),
sem: semaphore.New(int(parallelReads)),
numCached: metrics.NewEWMA1(),
numTotal: metrics.NewEWMA1(),
numLoad: metrics.NewEWMA1(),
loadedBytes: metrics.NewEWMA1(),
closeC: make(chan struct{}),
}
go c.tick()
return c
Expand All @@ -50,6 +52,7 @@ func (c *Cache) tick() {
c.numCached.Tick()
c.numTotal.Tick()
c.numLoad.Tick()
c.loadedBytes.Tick()
case <-c.closeC:
return
}
Expand Down Expand Up @@ -81,6 +84,10 @@ func (c *Cache) LoadsPerSecond() int {
return int(c.numLoad.Rate())
}

func (c *Cache) LoadedBytesPerSecond() int {
return int(c.loadedBytes.Rate())
}

func (c *Cache) LoadsWaiting() int {
return int(c.sem.Waiting())
}
Expand Down Expand Up @@ -137,6 +144,7 @@ func (c *Cache) getValue(i *item, loader Loader) ([]byte, error) {
c.sem.Signal()
i.loaded = true
c.numLoad.Update(1)
c.loadedBytes.Update(int64(len(i.value)))

return c.handleNewItem(i)
}
Expand Down
1 change: 1 addition & 0 deletions internal/rpctypes/rpctypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type SessionStats struct {
PieceCacheUtilization int
ReadsPerSecond int
ReadsPending int
ReadBytesPerSecond int
ActivePieceBytes int64
TorrentsPendingRAM int
Uptime int
Expand Down
1 change: 1 addition & 0 deletions torrent/rpchandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (h *rpcHandler) GetSessionStats(args *rpctypes.GetSessionStatsRequest, repl
PieceCacheUtilization: s.PieceCacheUtilization,
ReadsPerSecond: s.ReadsPerSecond,
ReadsPending: s.ReadsPending,
ReadBytesPerSecond: s.ReadBytesPerSecond,
ActivePieceBytes: s.ActivePieceBytes,
TorrentsPendingRAM: s.TorrentsPendingRAM,
Uptime: int(s.Uptime / time.Second),
Expand Down
1 change: 1 addition & 0 deletions torrent/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ func (s *Session) Stats() SessionStats {
PieceCacheUtilization: s.pieceCache.Utilization(),
ReadsPerSecond: s.pieceCache.LoadsPerSecond(),
ReadsPending: s.pieceCache.LoadsWaiting(),
ReadBytesPerSecond: s.pieceCache.LoadedBytesPerSecond(),
ActivePieceBytes: ramStats.Used,
TorrentsPendingRAM: ramStats.Count,
Uptime: time.Since(s.createdAt),
Expand Down
1 change: 1 addition & 0 deletions torrent/sessionstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type SessionStats struct {
PieceCacheUtilization int
ReadsPerSecond int
ReadsPending int
ReadBytesPerSecond int
ActivePieceBytes int64
TorrentsPendingRAM int
Uptime time.Duration
Expand Down

0 comments on commit e51c51c

Please sign in to comment.