Skip to content

Commit 80863c6

Browse files
Harshil Goeldarkcoderrises
authored andcommitted
fix(core): Add a few metrics and fix a bug (#9298)
1 parent 854dcc1 commit 80863c6

5 files changed

Lines changed: 51 additions & 21 deletions

File tree

edgraph/server.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,11 +1282,10 @@ func (s *Server) doQuery(ctx context.Context, req *Request) (resp *api.Response,
12821282
l := &query.Latency{}
12831283
l.Start = time.Now()
12841284

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

12911290
isMutation := len(req.req.Mutations) > 0
12921291
methodRequest := methodQuery

posting/mvcc.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,9 @@ func RemoveCacheFor(key []byte) {
347347
type Cache struct {
348348
data *ristretto.Cache[[]byte, *CachePL]
349349

350-
numCacheRead int64
351-
numCacheReadFails int64
352-
numCacheSave int64
350+
numCacheRead atomic.Int64
351+
numCacheReadFails atomic.Int64
352+
numCacheSave atomic.Int64
353353
}
354354

355355
func (c *Cache) wait() {
@@ -365,23 +365,22 @@ func (c *Cache) get(key []byte) (*CachePL, bool) {
365365
}
366366
val, ok := c.data.Get(key)
367367
if !ok {
368-
atomic.AddInt64(&c.numCacheReadFails, 1)
368+
c.numCacheReadFails.Add(1)
369369
return val, ok
370370
}
371371
if val.list == nil {
372-
atomic.AddInt64(&c.numCacheReadFails, 1)
372+
c.numCacheReadFails.Add(1)
373373
return nil, false
374374
}
375-
atomic.AddInt64(&c.numCacheRead, 1)
376-
c.numCacheRead += 1
375+
c.numCacheRead.Add(1)
377376
return val, true
378377
}
379378

380379
func (c *Cache) set(key []byte, i *CachePL) {
381380
if c == nil {
382381
return
383382
}
384-
c.numCacheSave += 1
383+
c.numCacheSave.Add(1)
385384
c.data.Set(key, i, 1)
386385
}
387386

@@ -407,8 +406,7 @@ type MemoryLayer struct {
407406
cache *Cache
408407

409408
// metrics
410-
statsHolder *StatsHolder
411-
numDisksRead int64
409+
statsHolder *StatsHolder
412410
}
413411

414412
func (ml *MemoryLayer) clear() {
@@ -448,6 +446,15 @@ func initMemoryLayer(cacheSize int64, deleteOnUpdates bool) *MemoryLayer {
448446
for range ticker.C {
449447
// Record the posting list cache hit ratio
450448
ostats.Record(context.Background(), x.PLCacheHitRatio.M(m.Ratio()))
449+
450+
x.NumPostingListCacheSave.M(ml.cache.numCacheRead.Load())
451+
ml.cache.numCacheSave.Store(0)
452+
453+
x.NumPostingListCacheRead.M(ml.cache.numCacheRead.Load())
454+
ml.cache.numCacheRead.Store(0)
455+
456+
x.NumPostingListCacheReadFail.M(ml.cache.numCacheReadFails.Load())
457+
ml.cache.numCacheReadFails.Store(0)
451458
}
452459
}()
453460

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

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

systest/backup/minio/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ services:
2323
read_only: true
2424
command:
2525
/gobin/dgraph ${COVERAGE_OUTPUT} alpha --telemetry "reports=false; sentry=false;"
26-
--my=alpha1:7080 --zero=zero1:5080 --logtostderr -v=2 --security
26+
--my=alpha1:7080 --zero=zero1:5080 --logtostderr --cache "size-mb=500;" -v=2 --security
2727
"whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;" --tls "ca-cert=/dgraph-tls/ca.crt;
2828
server-cert=/dgraph-tls/node.crt; server-key=/dgraph-tls/node.key; internal-port=true;
2929
client-cert=/dgraph-tls/client.alpha1.crt; client-key=/dgraph-tls/client.alpha1.key;"
@@ -48,7 +48,7 @@ services:
4848
read_only: true
4949
command:
5050
/gobin/dgraph ${COVERAGE_OUTPUT} alpha --telemetry "reports=false; sentry=false;"
51-
--my=alpha2:7080 --zero=zero1:5080 --logtostderr -v=2 --security
51+
--my=alpha2:7080 --zero=zero1:5080 --logtostderr --cache "size-mb=500;" -v=2 --security
5252
"whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;" --tls "ca-cert=/dgraph-tls/ca.crt;
5353
server-cert=/dgraph-tls/node.crt; server-key=/dgraph-tls/node.key; internal-port=true;
5454
client-cert=/dgraph-tls/client.alpha2.crt; client-key=/dgraph-tls/client.alpha2.key;"
@@ -73,7 +73,7 @@ services:
7373
read_only: true
7474
command:
7575
/gobin/dgraph ${COVERAGE_OUTPUT} alpha --telemetry "reports=false; sentry=false;"
76-
--my=alpha3:7080 --zero=zero1:5080 --logtostderr -v=2 --security
76+
--my=alpha3:7080 --zero=zero1:5080 --logtostderr --cache "size-mb=500;" -v=2 --security
7777
"whitelist=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16;" --tls "ca-cert=/dgraph-tls/ca.crt;
7878
server-cert=/dgraph-tls/node.crt; server-key=/dgraph-tls/node.key; internal-port=true;
7979
client-cert=/dgraph-tls/client.alpha3.crt; client-key=/dgraph-tls/client.alpha3.key;"

worker/task.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,8 @@ func (qs *queryState) handleUidPostings(
838838
}
839839

840840
if srcFn.fnType == compareAttrFn {
841-
pl.RLock()
842841
posting.GetStatsHolder().InsertRecord(
843842
q.Attr, []byte(srcFn.tokens[i]), uint64(pl.ApproxLen()))
844-
pl.RUnlock()
845843
}
846844

847845
switch {

x/metrics.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ var (
147147
// RaftLeaderChanges records the total number of leader changes seen.
148148
RaftLeaderChanges = ostats.Int64("raft_leader_changes_total",
149149
"Total number of leader changes seen", ostats.UnitDimensionless)
150+
NumPostingListCacheRead = ostats.Int64("num_posting_list_cache_reads",
151+
"Number of times cache was read", ostats.UnitDimensionless)
152+
NumPostingListCacheReadFail = ostats.Int64("num_posting_list_cache_reads_fail",
153+
"Number of times cache was read", ostats.UnitDimensionless)
154+
NumPostingListCacheSave = ostats.Int64("num_posting_list_cache_saves",
155+
"Number of times item was saved in cache", ostats.UnitDimensionless)
150156

151157
// Conf holds the metrics config.
152158
// TODO: Request statistics, latencies, 500, timeouts
@@ -202,6 +208,27 @@ var (
202208
Aggregation: view.Count(),
203209
TagKeys: allTagKeys,
204210
},
211+
{
212+
Name: NumPostingListCacheRead.Name(),
213+
Measure: NumPostingListCacheRead,
214+
Description: NumPostingListCacheRead.Description(),
215+
Aggregation: view.Count(),
216+
TagKeys: allTagKeys,
217+
},
218+
{
219+
Name: NumPostingListCacheReadFail.Name(),
220+
Measure: NumPostingListCacheReadFail,
221+
Description: NumPostingListCacheReadFail.Description(),
222+
Aggregation: view.Count(),
223+
TagKeys: allTagKeys,
224+
},
225+
{
226+
Name: NumPostingListCacheSave.Name(),
227+
Measure: NumPostingListCacheSave,
228+
Description: NumPostingListCacheSave.Description(),
229+
Aggregation: view.Count(),
230+
TagKeys: allTagKeys,
231+
},
205232
{
206233
Name: NumEdges.Name(),
207234
Measure: NumEdges,

0 commit comments

Comments
 (0)