From 40e485356e941a7f290172c9c7799fbe8a85d2f8 Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Fri, 22 Jun 2018 19:52:34 -0700 Subject: [PATCH] split log per node --- aws-code/transaction_generator.go | 14 ++++++++++---- benchmark_main.go | 21 +++++++++++---------- deploy.sh | 10 ++++++++-- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/aws-code/transaction_generator.go b/aws-code/transaction_generator.go index e9d8d398a..f80bb2d92 100644 --- a/aws-code/transaction_generator.go +++ b/aws-code/transaction_generator.go @@ -110,16 +110,22 @@ func readConfigFile(configFile string) [][]string { } func main() { - // Setup a stdout logger - h := log.CallerFileHandler(log.StdoutHandler) - log.Root().SetHandler(h) - configFile := flag.String("config_file", "local_config.txt", "file containing all ip addresses and config") numTxsPerBatch := flag.Int("num_txs_per_batch", 10000, "number of transactions to send per message") + timestamp := flag.String("timestamp", "latest", "timestamp of this execution") flag.Parse() config := readConfigFile(*configFile) leaders := getLeaders(&config) + // Setup a logger to stdout and log file. + logFileName := fmt.Sprintf("./%v-tx-generator.log", *timestamp) + h := log.MultiHandler( + log.Must.FileHandler(logFileName, log.LogfmtFormat()), + log.StdoutHandler) + // In cases where you just want a stdout logger, use the following one instead. + // h := log.CallerFileHandler(log.StdoutHandler) + log.Root().SetHandler(h) + // Testing node to mirror the node data in consensus dataNode := node.NewNode(&consensus.Consensus{}) dataNode.AddMoreFakeTransactions(10000) diff --git a/benchmark_main.go b/benchmark_main.go index a18978dc8..237b0f1c0 100644 --- a/benchmark_main.go +++ b/benchmark_main.go @@ -10,7 +10,6 @@ import ( "harmony-benchmark/p2p" "os" "strings" - "time" ) func getShardId(myIp, myPort string, config *[][]string) string { @@ -61,18 +60,10 @@ func readConfigFile(configFile string) [][]string { } func main() { - // Setup a logger to stdout and log file. - logFileName := fmt.Sprintf("./%v.log", time.Now().Format("20060102150405")) - h := log.MultiHandler( - log.Must.FileHandler(logFileName, log.LogfmtFormat()), - log.StdoutHandler) - // In cases where you just want a stdout logger, use the following one instead. - // h := log.CallerFileHandler(log.StdoutHandler) - log.Root().SetHandler(h) - ip := flag.String("ip", "127.0.0.1", "IP of the node") port := flag.String("port", "9000", "port of the node.") configFile := flag.String("config_file", "config.txt", "file containing all ip addresses") + timestamp := flag.String("timestamp", "latest", "timestamp of this execution") flag.Parse() config := readConfigFile(*configFile) @@ -80,9 +71,19 @@ func main() { peers := getPeers(*ip, *port, shardId, &config) leader := getLeader(shardId, &config) + // Setup a logger to stdout and log file. + logFileName := fmt.Sprintf("./%v-%v.log", *timestamp, *port) + h := log.MultiHandler( + log.Must.FileHandler(logFileName, log.LogfmtFormat()), + log.StdoutHandler) + // In cases where you just want a stdout logger, use the following one instead. + // h := log.CallerFileHandler(log.StdoutHandler) + log.Root().SetHandler(h) + consensus := consensus.NewConsensus(*ip, *port, shardId, peers, leader) node := node.NewNode(&consensus) + // Assign closure functions to the consensus object consensus.BlockVerifier = node.VerifyNewBlock consensus.OnConsensusDone = node.AddNewBlockToBlockchain diff --git a/deploy.sh b/deploy.sh index 71148722f..53939cfce 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,9 +1,15 @@ +timestamp() { + date +"%Y%m%d-%H%M%S" +} + +t=`timestamp` + ./kill_node.sh config=$1 while IFS='' read -r line || [[ -n "$line" ]]; do IFS=' ' read ip port mode <<< $line #echo $ip $port $mode $config - go run ./benchmark_main.go -ip $ip -port $port -config_file $config& + go run ./benchmark_main.go -ip $ip -port $port -config_file $config -timestamp $t& done < $config -go run ./aws-code/transaction_generator.go -config_file $config \ No newline at end of file +go run ./aws-code/transaction_generator.go -config_file $config -timestamp $t \ No newline at end of file