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

feat(metric): Add dgraph_memory_alloc_bytes to track jemalloc memory. #7051

Merged
merged 4 commits into from
Dec 3, 2020
Merged
Changes from 3 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
17 changes: 17 additions & 0 deletions x/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ var (
// PendingProposals records the current number of pending RAFT proposals.
PendingProposals = stats.Int64("pending_proposals_total",
"Number of pending proposals", stats.UnitDimensionless)
// MemoryAlloc records the amount of memory allocated via jemalloc
MemoryAlloc = stats.Int64("memory_alloc_bytes",
"Amount of memory allocated", stats.UnitBytes)
// MemoryInUse records the current amount of used memory by Dgraph.
MemoryInUse = stats.Int64("memory_inuse_bytes",
"Amount of memory in use", stats.UnitBytes)
Expand Down Expand Up @@ -192,6 +195,13 @@ var (
Aggregation: view.LastValue(),
TagKeys: nil,
},
{
Name: MemoryAlloc.Name(),
Measure: MemoryAlloc,
Description: MemoryAlloc.Description(),
Aggregation: view.LastValue(),
TagKeys: allTagKeys,
},
{
Name: MemoryInUse.Name(),
Measure: MemoryInUse,
Expand Down Expand Up @@ -447,8 +457,13 @@ func MonitorMemoryMetrics(lc *z.Closer) {
defer lc.Done()
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()
fastTicker := time.NewTicker(time.Second)
defer fastTicker.Stop()

update := func() {
// ReadMemStats stops the world which is expensive especially when the
// heap is large. So don't call it too frequently. Calling it every
// minute is OK.
var ms runtime.MemStats
runtime.ReadMemStats(&ms)

Expand All @@ -475,6 +490,8 @@ func MonitorMemoryMetrics(lc *z.Closer) {
select {
case <-lc.HasBeenClosed():
return
case <-fastTicker.C:
ostats.Record(context.Background(), MemoryAlloc.M(z.NumAllocBytes()))
case <-ticker.C:
update()
}
Expand Down