Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track cache, WAL, filestore stats within tsm1 engine #5758

Merged
merged 12 commits into from
Feb 22, 2016
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions tsdb/engine/tsm1/cache.go
Original file line number Diff line number Diff line change
@@ -103,13 +103,19 @@ type Cache struct {

// NewCache returns an instance of a cache which will use a maximum of maxSize bytes of memory.
func NewCache(maxSize uint64, path string) *Cache {
return &Cache{
c := &Cache{
maxSize: maxSize,
store: make(map[string]*entry),
statMap: influxdb.NewStatistics("tsm1_cache:"+path, "tsm1_cache", map[string]string{"path": path}),
path: path,
lastSnapshot: time.Now(),
}
c.UpdateAge()
c.UpdateCompactTime(0)
c.updateCachedBytes(0)
c.updateMemSize(0)
c.updateSnapshots()
return c
}

// Write writes the set of values for the key to the cache. This function is goroutine-safe.
@@ -128,9 +134,7 @@ func (c *Cache) Write(key string, values []Value) error {
c.size = newSize

// Update the memory size stat
sizeStat := new(expvar.Int)
sizeStat.Set(int64(c.size))
c.statMap.Set(statCacheMemoryBytes, sizeStat)
c.updateMemSize(newSize)

return nil
}
@@ -160,9 +164,7 @@ func (c *Cache) WriteMulti(values map[string][]Value) error {
c.mu.Unlock()

// Update the memory size stat
sizeStat := new(expvar.Int)
sizeStat.Set(int64(newSize))
c.statMap.Set(statCacheMemoryBytes, sizeStat)
c.updateMemSize(newSize)

return nil
}
@@ -184,17 +186,9 @@ func (c *Cache) Snapshot() *Cache {
c.snapshots = append(c.snapshots, snapshot)
c.snapshotsSize += snapshot.size

// Update stats
memSizeStat := new(expvar.Int)
memSizeStat.Set(0)
c.statMap.Set(statCacheMemoryBytes, memSizeStat)

diskSizeStat := new(expvar.Int)
diskSizeStat.Set(int64(c.snapshotsSize))
c.statMap.Set(statCacheDiskBytes, diskSizeStat)

c.statMap.Add(statCachedBytes, int64(snapshot.size))
c.statMap.Add(statSnapshots, 1)
c.updateMemSize(0)
c.updateCachedBytes(snapshot.size)
c.updateSnapshots()

return snapshot
}
@@ -221,12 +215,7 @@ func (c *Cache) ClearSnapshot(snapshot *Cache) {
}
}

// Update disk stats
diskSizeStat := new(expvar.Int)
diskSizeStat.Set(int64(c.snapshotsSize))
c.statMap.Set(statCacheDiskBytes, diskSizeStat)

c.statMap.Add(statSnapshots, -1)
c.updateSnapshots()
}

// Size returns the number of point-calcuated bytes the cache currently uses.
@@ -457,3 +446,27 @@ func (c *Cache) UpdateAge() {
func (c *Cache) UpdateCompactTime(d time.Duration) {
c.statMap.Add(statWALCompactionTimeMs, int64(d/time.Millisecond))
}

// Update the cachedBytes counter
func (c *Cache) updateCachedBytes(b uint64) {
c.statMap.Add(statCachedBytes, int64(b))
}

// Update the memSize level
func (c *Cache) updateMemSize(b uint64) {
memSizeStat := new(expvar.Int)
memSizeStat.Set(int64(b))
c.statMap.Set(statCacheMemoryBytes, memSizeStat)
}

// Update the snapshotsCount and the diskSize levels
func (c *Cache) updateSnapshots() {
// Update disk stats
diskSizeStat := new(expvar.Int)
diskSizeStat.Set(int64(c.snapshotsSize))
c.statMap.Set(statCacheDiskBytes, diskSizeStat)

snapshotsStat := new(expvar.Int)
snapshotsStat.Set(int64(len(c.snapshots)))
c.statMap.Set(statSnapshots, snapshotsStat)
}