From cbedf08a6ccd30cfb78388f64c87be507bd2c597 Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Fri, 6 Jul 2018 01:06:24 -0700 Subject: [PATCH] log mem usage. --- benchmark.go | 14 ++++++++++++++ consensus/consensus_leader.go | 7 ------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/benchmark.go b/benchmark.go index 0667ece5b..eb4e94bc2 100644 --- a/benchmark.go +++ b/benchmark.go @@ -9,8 +9,10 @@ import ( "harmony-benchmark/log" "harmony-benchmark/node" "harmony-benchmark/p2p" + "harmony-benchmark/utils" "math/rand" "os" + "runtime" "strings" "time" ) @@ -90,6 +92,16 @@ func attackDetermination(attackedMode int) bool { return false } +func logMemUsage(consensus *consensus.Consensus) { + for { + var m runtime.MemStats + runtime.ReadMemStats(&m) + log.Info("Mem Report", "Alloc", utils.BToMb(m.Alloc), "TotalAlloc", utils.BToMb(m.TotalAlloc), + "Sys", utils.BToMb(m.Sys), "NumGC", m.NumGC, "consensus", consensus) + time.Sleep(10 * time.Second) + } +} + func main() { ip := flag.String("ip", "127.0.0.1", "IP of the node") port := flag.String("port", "9000", "port of the node.") @@ -120,6 +132,8 @@ func main() { consensus := consensus.NewConsensus(*ip, *port, shardId, peers, leader) + go logMemUsage(&consensus) + node := node.NewNode(&consensus) // Set logger to attack model. attack.GetInstance().SetLogger(consensus.Log) diff --git a/consensus/consensus_leader.go b/consensus/consensus_leader.go index 85c5b06c2..17146d277 100644 --- a/consensus/consensus_leader.go +++ b/consensus/consensus_leader.go @@ -7,8 +7,6 @@ import ( "encoding/gob" "harmony-benchmark/blockchain" "harmony-benchmark/p2p" - "harmony-benchmark/utils" - "runtime" "strings" "time" ) @@ -336,11 +334,6 @@ func (consensus *Consensus) processResponseMessage(payload []byte) { "timeElapsed", timeElapsed, "TPS", float64(numOfTxs)/timeElapsed.Seconds()) - var m runtime.MemStats - runtime.ReadMemStats(&m) - consensus.Log.Info("Mem Report", "Alloc", utils.BToMb(m.Alloc), "TotalAlloc", utils.BToMb(m.TotalAlloc), - "Sys", utils.BToMb(m.Sys), "NumGC", m.NumGC) - // Send signal to Node so the new block can be added and new round of consensus can be triggered consensus.ReadySignal <- 1 }