diff --git a/dgraph/cmd/bulk/run.go b/dgraph/cmd/bulk/run.go index 7fed65ea770..3fa2b590c85 100644 --- a/dgraph/cmd/bulk/run.go +++ b/dgraph/cmd/bulk/run.go @@ -28,11 +28,9 @@ import ( "runtime" "strconv" "strings" - "time" "github.com/dgraph-io/dgraph/tok" "github.com/dgraph-io/dgraph/x" - "github.com/dustin/go-humanize" "github.com/spf13/cobra" ) @@ -204,27 +202,6 @@ func run() { defer os.RemoveAll(opt.TmpDir) } - // Bulk loader can take up a lot of RAM. So, run GC often. - go func() { - ticker := time.NewTicker(10 * time.Second) - defer ticker.Stop() - - var lastNum uint32 - var ms runtime.MemStats - for range ticker.C { - runtime.ReadMemStats(&ms) - fmt.Printf("GC: %d. InUse: %s. Idle: %s\n", ms.NumGC, humanize.Bytes(ms.HeapInuse), - humanize.Bytes(ms.HeapIdle-ms.HeapReleased)) - if ms.NumGC > lastNum { - // GC was already run by the Go runtime. No need to run it again. - lastNum = ms.NumGC - } else { - runtime.GC() - lastNum = ms.NumGC + 1 - } - } - }() - loader := newLoader(opt) if !opt.SkipMapPhase { loader.mapStage() diff --git a/dgraph/main.go b/dgraph/main.go index d832263fc20..e90f2e7a07e 100644 --- a/dgraph/main.go +++ b/dgraph/main.go @@ -22,6 +22,8 @@ import ( "time" "github.com/dgraph-io/dgraph/dgraph/cmd" + "github.com/dustin/go-humanize" + "github.com/golang/glog" ) func main() { @@ -30,5 +32,28 @@ func main() { // improving throughput. The extra CPU overhead is almost negligible in comparison. The // benchmark notes are located in badger-bench/randread. runtime.GOMAXPROCS(128) + + // Make sure the garbage collector is run periodically. + go func() { + ticker := time.NewTicker(10 * time.Second) + defer ticker.Stop() + + var lastNum uint32 + var ms runtime.MemStats + for range ticker.C { + runtime.ReadMemStats(&ms) + if ms.NumGC > lastNum { + // GC was already run by the Go runtime. No need to run it again. + lastNum = ms.NumGC + } else { + runtime.GC() + glog.V(2).Infof("GC: %d. InUse: %s. Idle: %s\n", ms.NumGC, + humanize.Bytes(ms.HeapInuse), + humanize.Bytes(ms.HeapIdle-ms.HeapReleased)) + lastNum = ms.NumGC + 1 + } + } + }() + cmd.Execute() }