Skip to content

Commit

Permalink
Expose block cache usage
Browse files Browse the repository at this point in the history
  • Loading branch information
aalda committed Apr 4, 2019
1 parent e843593 commit 7669721
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
32 changes: 29 additions & 3 deletions storage/rocks/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ type rocksDBMetrics struct {
*compressMetrics
}

func newRocksDBMetrics(stats *rocksdb.Statistics) *rocksDBMetrics {
func newRocksDBMetrics(stats *rocksdb.Statistics, cache *rocksdb.Cache) *rocksDBMetrics {
return &rocksDBMetrics{
blockCacheMetrics: newBlockCacheMetrics(stats),
blockCacheMetrics: newBlockCacheMetrics(stats, cache),
bloomFilterMetrics: newBloomFilterMetrics(stats),
memtableMetrics: newMemtableMetrics(stats),
getsMetrics: newGetsMetrics(stats),
Expand Down Expand Up @@ -85,10 +85,12 @@ type blockCacheMetrics struct {
DataBytesInsert prometheus.GaugeFunc
BytesRead prometheus.GaugeFunc
BytesWrite prometheus.GaugeFunc
Usage prometheus.GaugeFunc
PinnedUsage prometheus.GaugeFunc
}

// newBlockCacheMetrics initialises the prometheus metris for block cache.
func newBlockCacheMetrics(stats *rocksdb.Statistics) *blockCacheMetrics {
func newBlockCacheMetrics(stats *rocksdb.Statistics, cache *rocksdb.Cache) *blockCacheMetrics {
return &blockCacheMetrics{
Miss: prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Expand Down Expand Up @@ -270,6 +272,28 @@ func newBlockCacheMetrics(stats *rocksdb.Statistics) *blockCacheMetrics {
},
extractMetric(stats, rocksdb.TickerBlockCacheBytesWrite),
),
Usage: prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: blockCacheSubsystem,
Name: "cache_memory_usage",
Help: "Block cache memory usage.",
},
func() float64 {
return float64(cache.GetUsage())
},
),
PinnedUsage: prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: blockCacheSubsystem,
Name: "cache_pinned_memory_usage",
Help: "Block cache pinned memory usage.",
},
func() float64 {
return float64(cache.GetPinnedUsage())
},
),
}
}

Expand All @@ -296,6 +320,8 @@ func (m *blockCacheMetrics) collectors() []prometheus.Collector {
m.DataBytesInsert,
m.BytesRead,
m.BytesWrite,
m.Usage,
m.PinnedUsage,
}
}

Expand Down
5 changes: 3 additions & 2 deletions storage/rocks/rocksdb_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func NewRocksDBStoreOpts(opts *Options) (*RocksDBStore, error) {
}

if stats != nil {
store.metrics = newRocksDBMetrics(stats)
store.metrics = newRocksDBMetrics(stats, blockCache)
}

return store, nil
Expand Down Expand Up @@ -163,8 +163,9 @@ func getHyperCacheTableOpts(blockCache *rocksdb.Cache) *rocksdb.Options {
// those from L0 and move them to the high priority pool.
bbto.SetPinL0FilterAndIndexBlocksInCache(true)
bbto.SetCacheIndexAndFilterBlocksWithHighPriority(true)
bbto.SetPinTopLevelIndexAndFilterInCache(true)
// activate partition filters
bbto.SetPartitionFilters(true)
bbto.SetPinTopLevelIndexAndFilterInCache(true)
bbto.SetIndexType(rocksdb.KTwoLevelIndexSearchIndexType)
bbto.SetBlockCache(blockCache)
// increase block size to 16KB
Expand Down

0 comments on commit 7669721

Please sign in to comment.