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

fix(core): Added some metrics #9298

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 3 additions & 5 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1282,11 +1282,9 @@
l := &query.Latency{}
l.Start = time.Now()

// TODO: Following trace messages have been commented out as stringified trace messages allocate
// too much memory. These trace messages need to be generated if tracing is enabled.
// if bool(glog.V(3)) || worker.LogDQLRequestEnabled() {
// glog.Infof("Got a query, DQL form: %+v at %+v", req.req, l.Start.Format(time.RFC3339))
// }
if bool(glog.V(3)) || worker.LogDQLRequestEnabled() {
glog.Infof("Got a query, DQL form: %+v at %+v", req.req, l.Start.Format(time.RFC3339))
Fixed Show fixed Hide fixed
}

isMutation := len(req.req.Mutations) > 0
methodRequest := methodQuery
Expand Down
28 changes: 17 additions & 11 deletions posting/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ func RemoveCacheFor(key []byte) {
type Cache struct {
data *ristretto.Cache[[]byte, *CachePL]

numCacheRead int64
numCacheReadFails int64
numCacheSave int64
numCacheRead atomic.Int64
numCacheReadFails atomic.Int64
numCacheSave atomic.Int64
}

func (c *Cache) wait() {
Expand All @@ -365,23 +365,22 @@ func (c *Cache) get(key []byte) (*CachePL, bool) {
}
val, ok := c.data.Get(key)
if !ok {
atomic.AddInt64(&c.numCacheReadFails, 1)
c.numCacheReadFails.Add(1)
return val, ok
}
if val.list == nil {
atomic.AddInt64(&c.numCacheReadFails, 1)
c.numCacheReadFails.Add(1)
return nil, false
}
atomic.AddInt64(&c.numCacheRead, 1)
c.numCacheRead += 1
c.numCacheRead.Add(1)
return val, true
}

func (c *Cache) set(key []byte, i *CachePL) {
if c == nil {
return
}
c.numCacheSave += 1
c.numCacheSave.Add(1)
c.data.Set(key, i, 1)
}

Expand All @@ -407,8 +406,7 @@ type MemoryLayer struct {
cache *Cache

// metrics
statsHolder *StatsHolder
numDisksRead int64
statsHolder *StatsHolder
}

func (ml *MemoryLayer) clear() {
Expand Down Expand Up @@ -448,6 +446,15 @@ func initMemoryLayer(cacheSize int64, deleteOnUpdates bool) *MemoryLayer {
for range ticker.C {
// Record the posting list cache hit ratio
ostats.Record(context.Background(), x.PLCacheHitRatio.M(m.Ratio()))

x.NumPostingListCacheSave.M(ml.cache.numCacheRead.Load())
ml.cache.numCacheSave.Store(0)

x.NumPostingListCacheRead.M(ml.cache.numCacheRead.Load())
ml.cache.numCacheRead.Store(0)

x.NumPostingListCacheReadFail.M(ml.cache.numCacheReadFails.Load())
ml.cache.numCacheReadFails.Store(0)
}
}()

Expand Down Expand Up @@ -657,7 +664,6 @@ func (ml *MemoryLayer) readFromCache(key []byte, readTs uint64) *List {
}

func (ml *MemoryLayer) readFromDisk(key []byte, pstore *badger.DB, readTs uint64) (*List, error) {
atomic.AddInt64(&ml.numDisksRead, 1)
txn := pstore.NewTransactionAt(readTs, false)
defer txn.Discard()

Expand Down
2 changes: 0 additions & 2 deletions worker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,8 @@ func (qs *queryState) handleUidPostings(
}

if srcFn.fnType == compareAttrFn {
pl.RLock()
posting.GetStatsHolder().InsertRecord(
q.Attr, []byte(srcFn.tokens[i]), uint64(pl.ApproxLen()))
pl.RUnlock()
}

switch {
Expand Down
27 changes: 27 additions & 0 deletions x/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ var (
// RaftLeaderChanges records the total number of leader changes seen.
RaftLeaderChanges = ostats.Int64("raft_leader_changes_total",
"Total number of leader changes seen", ostats.UnitDimensionless)
NumPostingListCacheRead = ostats.Int64("num_posting_list_cache_reads",
"Number of times cache was read", ostats.UnitDimensionless)
NumPostingListCacheReadFail = ostats.Int64("num_posting_list_cache_reads_fail",
"Number of times cache was read", ostats.UnitDimensionless)
NumPostingListCacheSave = ostats.Int64("num_posting_list_cache_saves",
"Number of times item was saved in cache", ostats.UnitDimensionless)

// Conf holds the metrics config.
// TODO: Request statistics, latencies, 500, timeouts
Expand Down Expand Up @@ -202,6 +208,27 @@ var (
Aggregation: view.Count(),
TagKeys: allTagKeys,
},
{
Name: NumPostingListCacheRead.Name(),
Measure: NumPostingListCacheRead,
Description: NumPostingListCacheRead.Description(),
Aggregation: view.Count(),
TagKeys: allTagKeys,
},
{
Name: NumPostingListCacheReadFail.Name(),
Measure: NumPostingListCacheReadFail,
Description: NumPostingListCacheReadFail.Description(),
Aggregation: view.Count(),
TagKeys: allTagKeys,
},
{
Name: NumPostingListCacheSave.Name(),
Measure: NumPostingListCacheSave,
Description: NumPostingListCacheSave.Description(),
Aggregation: view.Count(),
TagKeys: allTagKeys,
},
{
Name: NumEdges.Name(),
Measure: NumEdges,
Expand Down
Loading