rough version of tps report.

pull/61/head
Richard Liu 6 years ago
parent 78a46a7ddf
commit 5eeca78124
  1. 1
      benchmark.go
  2. 44
      consensus/consensus_leader.go

@ -82,7 +82,6 @@ func main() {
h := log.MultiHandler( h := log.MultiHandler(
log.StdoutHandler, log.StdoutHandler,
log.Must.FileHandler(logFileName, log.JSONFormat()), // Log to file log.Must.FileHandler(logFileName, log.JSONFormat()), // Log to file
// log.Must.NetHandler("tcp", ":3000", log.JSONFormat()) // Log to remote
) )
log.Root().SetHandler(h) log.Root().SetHandler(h)

@ -5,6 +5,9 @@ import (
"encoding/binary" "encoding/binary"
"encoding/gob" "encoding/gob"
"errors" "errors"
"net/http"
"net/url"
"strconv"
"time" "time"
"github.com/dedis/kyber" "github.com/dedis/kyber"
@ -368,18 +371,7 @@ func (consensus *Consensus) processResponseMessage(payload []byte, targetState C
copy(blockHeaderObj.Bitmap[:], bitmap) copy(blockHeaderObj.Bitmap[:], bitmap)
consensus.OnConsensusDone(&blockHeaderObj) consensus.OnConsensusDone(&blockHeaderObj)
// TODO: @ricl these logic are irrelevant to consensus, move them to another file, say profiler. consensus.reportTPS(blockHeaderObj.NumTransactions)
endTime := time.Now()
timeElapsed := endTime.Sub(startTime)
numOfTxs := blockHeaderObj.NumTransactions
consensus.Log.Info("TPS Report",
"numOfTXs", numOfTxs,
"startTime", startTime,
"endTime", endTime,
"timeElapsed", timeElapsed,
"TPS", float64(numOfTxs)/timeElapsed.Seconds(),
"consensus", consensus)
// Send signal to Node so the new block can be added and new round of consensus can be triggered // Send signal to Node so the new block can be added and new round of consensus can be triggered
consensus.ReadySignal <- 1 consensus.ReadySignal <- 1
} }
@ -410,3 +402,31 @@ func (consensus *Consensus) verifyResponse(commitments *map[uint16]kyber.Point,
//} //}
return nil return nil
} }
func (consensus *Consensus) reportTPS(numOfTxs int32) {
endTime := time.Now()
timeElapsed := endTime.Sub(startTime)
tps := float64(numOfTxs) / timeElapsed.Seconds()
consensus.Log.Info("TPS Report",
"numOfTXs", numOfTxs,
"startTime", startTime,
"endTime", endTime,
"timeElapsed", timeElapsed,
"TPS", tps,
"consensus", consensus)
reportMetrics(tps)
}
func reportMetrics(tps float64) {
URL := "http://localhost:3000/report"
form := url.Values{
"tps": {strconv.FormatFloat(tps, 'f', 2, 64)},
}
body := bytes.NewBufferString(form.Encode())
rsp, err := http.Post(URL, "application/x-www-form-urlencoded", body)
if err != nil {
return
}
defer rsp.Body.Close()
}

Loading…
Cancel
Save