From 30ac1fa26d7a7eca907f63a60cd52108e8cb5f69 Mon Sep 17 00:00:00 2001 From: Daniel Mai Date: Fri, 4 Dec 2020 21:53:22 -0800 Subject: [PATCH 1/3] feat(zero): Bring in jemalloc debugging to Zero. Accessible via /jemalloc at Zero's HTTP port. --- dgraph/cmd/alpha/run.go | 13 +------------ dgraph/cmd/zero/run.go | 1 + x/metrics.go | 11 +++++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/dgraph/cmd/alpha/run.go b/dgraph/cmd/alpha/run.go index 9f1b0345c42..71842225910 100644 --- a/dgraph/cmd/alpha/run.go +++ b/dgraph/cmd/alpha/run.go @@ -48,7 +48,6 @@ import ( "github.com/dgraph-io/dgraph/worker" "github.com/dgraph-io/dgraph/x" "github.com/dgraph-io/ristretto/z" - "github.com/dustin/go-humanize" "github.com/golang/glog" "github.com/pkg/errors" "github.com/spf13/cast" @@ -333,16 +332,6 @@ func healthCheck(w http.ResponseWriter, r *http.Request) { _, _ = w.Write(resp.Json) } -func jemallocHandler(w http.ResponseWriter, r *http.Request) { - x.AddCorsHeaders(w) - - na := z.NumAllocBytes() - fmt.Fprintf(w, "Num Allocated Bytes: %s [%d]\n", - humanize.IBytes(uint64(na)), na) - fmt.Fprintf(w, "Allocators:\n%s\n", z.Allocators()) - fmt.Fprintf(w, "%s\n", z.Leaks()) -} - func stateHandler(w http.ResponseWriter, r *http.Request) { var err error x.AddCorsHeaders(w) @@ -436,7 +425,7 @@ func setupServer(closer *z.Closer) { http.HandleFunc("/alter", alterHandler) http.HandleFunc("/health", healthCheck) http.HandleFunc("/state", stateHandler) - http.HandleFunc("/jemalloc", jemallocHandler) + http.HandleFunc("/jemalloc", x.JemallocHandler) // TODO: Figure out what this is for? http.HandleFunc("/debug/store", storeStatsHandler) diff --git a/dgraph/cmd/zero/run.go b/dgraph/cmd/zero/run.go index 61a117cb864..b8f1d5f2f51 100644 --- a/dgraph/cmd/zero/run.go +++ b/dgraph/cmd/zero/run.go @@ -247,6 +247,7 @@ func run() { http.HandleFunc("/moveTablet", st.moveTablet) http.HandleFunc("/assign", st.assign) http.HandleFunc("/enterpriseLicense", st.applyEnterpriseLicense) + http.HandleFunc("/jemalloc", x.JemallocHandler) zpages.Handle(http.DefaultServeMux, "/z") // This must be here. It does not work if placed before Grpc init. diff --git a/x/metrics.go b/x/metrics.go index 497c615baea..50ffc8ed237 100644 --- a/x/metrics.go +++ b/x/metrics.go @@ -37,6 +37,7 @@ import ( datadog "github.com/DataDog/opencensus-go-exporter-datadog" "github.com/dgraph-io/badger/v2" "github.com/dgraph-io/ristretto/z" + "github.com/dustin/go-humanize" "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" "github.com/spf13/viper" @@ -565,3 +566,13 @@ func getMemUsage() int { return rss * os.Getpagesize() } + +func JemallocHandler(w http.ResponseWriter, r *http.Request) { + x.AddCorsHeaders(w) + + na := z.NumAllocBytes() + fmt.Fprintf(w, "Num Allocated Bytes: %s [%d]\n", + humanize.IBytes(uint64(na)), na) + fmt.Fprintf(w, "Allocators:\n%s\n", z.Allocators()) + fmt.Fprintf(w, "%s\n", z.Leaks()) +} From 4f8834ea401f67d801df6a0c04329189b813fcce Mon Sep 17 00:00:00 2001 From: Daniel Mai Date: Fri, 4 Dec 2020 21:56:00 -0800 Subject: [PATCH 2/3] Fix typo. --- x/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/metrics.go b/x/metrics.go index 50ffc8ed237..b40021c3cc4 100644 --- a/x/metrics.go +++ b/x/metrics.go @@ -568,7 +568,7 @@ func getMemUsage() int { } func JemallocHandler(w http.ResponseWriter, r *http.Request) { - x.AddCorsHeaders(w) + AddCorsHeaders(w) na := z.NumAllocBytes() fmt.Fprintf(w, "Num Allocated Bytes: %s [%d]\n", From 3819a5e7c4f8ddc4cde62c4f5efd2e18de595774 Mon Sep 17 00:00:00 2001 From: Daniel Mai Date: Fri, 4 Dec 2020 22:00:25 -0800 Subject: [PATCH 3/3] fix(OOM): Bring in latest Badger. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 37d1ce5f0a0..00ad8c75c79 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/OneOfOne/xxhash v1.2.5 // indirect github.com/blevesearch/bleve v1.0.13 github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd - github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20201205014101-3a4d8e7399b7 + github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20201205055457-63726a849024 github.com/dgraph-io/dgo/v200 v200.0.0-20200805103119-a3544c464dd6 github.com/dgraph-io/gqlgen v0.13.2 github.com/dgraph-io/gqlparser/v2 v2.1.1 diff --git a/go.sum b/go.sum index 86530b12757..2a94debe733 100644 --- a/go.sum +++ b/go.sum @@ -116,8 +116,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger v1.6.0 h1:DshxFxZWXUcO0xX476VJC07Xsr6ZCBVRHKZ93Oh7Evo= github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= -github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20201205014101-3a4d8e7399b7 h1:vqS1c9IRwTMS0Kb/OaLziwkQvk4h63j7mLVsku27fnk= -github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20201205014101-3a4d8e7399b7/go.mod h1:5RUGROQEPbBw8Ba5Q4Tff8/dgwoJM6EeJCsCOLgSeek= +github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20201205055457-63726a849024 h1:hj/5tQ6gD8ucfbobNcBrv8v5XmpIGGQy3ZQSloh2rfA= +github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20201205055457-63726a849024/go.mod h1:5RUGROQEPbBw8Ba5Q4Tff8/dgwoJM6EeJCsCOLgSeek= github.com/dgraph-io/dgo/v200 v200.0.0-20200805103119-a3544c464dd6 h1:toHzMCdCUgYsjM0cW9+wafnKFXfp1HizIJUyzihN+vk= github.com/dgraph-io/dgo/v200 v200.0.0-20200805103119-a3544c464dd6/go.mod h1:rHa+h3kI4M8ASOirxyIyNeXBfHFgeskVUum2OrDMN3U= github.com/dgraph-io/gqlgen v0.13.2 h1:TNhndk+eHKj5qE7BenKKSYdSIdOGhLqxR1rCiMso9KM=