aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-07-31 11:54:48 +0800
committerGitHub <noreply@github.com>2018-07-31 11:54:48 +0800
commit36d069fbecaf270974c920e6e27f0def22936fb9 (patch)
treeadd599d24654346d974f29e89c709a0890d57ef8
parentd99bc645ee0138c6ea628f77c6475eec1a61253e (diff)
downloaddexon-consensus-36d069fbecaf270974c920e6e27f0def22936fb9.tar
dexon-consensus-36d069fbecaf270974c920e6e27f0def22936fb9.tar.gz
dexon-consensus-36d069fbecaf270974c920e6e27f0def22936fb9.tar.bz2
dexon-consensus-36d069fbecaf270974c920e6e27f0def22936fb9.tar.lz
dexon-consensus-36d069fbecaf270974c920e6e27f0def22936fb9.tar.xz
dexon-consensus-36d069fbecaf270974c920e6e27f0def22936fb9.tar.zst
dexon-consensus-36d069fbecaf270974c920e6e27f0def22936fb9.zip
Print confirmed blocks per second when Peer Server stopped. (#22)
-rw-r--r--simulation/peer-server.go2
-rw-r--r--simulation/verification.go45
2 files changed, 47 insertions, 0 deletions
diff --git a/simulation/peer-server.go b/simulation/peer-server.go
index 9cace94..1b8432f 100644
--- a/simulation/peer-server.go
+++ b/simulation/peer-server.go
@@ -217,6 +217,8 @@ func (p *PeerServer) Run(configPath string) {
go func() {
<-stopServer
+ LogStatus(p.peerTotalOrder)
+
log.Printf("Shutting down peerServer.\n")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
diff --git a/simulation/verification.go b/simulation/verification.go
index 0e111be..bc1afc4 100644
--- a/simulation/verification.go
+++ b/simulation/verification.go
@@ -21,17 +21,28 @@ import (
"container/heap"
"log"
"math"
+ "time"
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
)
+type timeStamp struct {
+ time time.Time
+ length int
+}
+
+type totalOrderStatus struct {
+ blockReceive []timeStamp
+}
+
// TotalOrderResult is the object maintaining peer's result of
// Total Ordering Algorithm.
type TotalOrderResult struct {
hashList common.Hashes
curID int
pendingBlockList PendingBlockList
+ status totalOrderStatus
}
// PeerTotalOrder stores the TotalOrderResult of each validator.
@@ -47,6 +58,11 @@ func NewTotalOrderResult() *TotalOrderResult {
// PushBlocks push a BlockList into the TotalOrderResult and return true if
// there is new blocks ready for verifiy
func (totalOrder *TotalOrderResult) PushBlocks(blocks BlockList) (ready bool) {
+ totalOrder.status.blockReceive = append(totalOrder.status.blockReceive,
+ timeStamp{
+ time: time.Now(),
+ length: len(blocks.BlockHash),
+ })
if blocks.ID != totalOrder.curID {
heap.Push(&totalOrder.pendingBlockList, &blocks)
return false
@@ -65,6 +81,28 @@ func (totalOrder *TotalOrderResult) PushBlocks(blocks BlockList) (ready bool) {
return true
}
+// CalculateBlocksPerSecond calculates the result using status.blockReceive
+func (totalOrder *TotalOrderResult) CalculateBlocksPerSecond() float64 {
+ ts := totalOrder.status.blockReceive
+ if len(ts) < 2 {
+ return 0
+ }
+
+ diffTime := ts[len(ts)-1].time.Sub(ts[0].time).Seconds()
+ if diffTime == 0 {
+ return 0
+ }
+ totalBlocks := 0
+ for _, blocks := range ts {
+ // Blocks received at time zero are confirmed beforehand.
+ if blocks.time == ts[0].time {
+ continue
+ }
+ totalBlocks += blocks.length
+ }
+ return float64(totalBlocks) / diffTime
+}
+
// VerifyTotalOrder verifies if the result of Total Ordering Algorithm
// returned by all validators are the same. However, the length of result
// of each validators may not be the same, so only the common part is verified.
@@ -109,3 +147,10 @@ func VerifyTotalOrder(id types.ValidatorID,
}
return totalOrder, !hasError, length
}
+
+// LogStatus prints all the status to log.
+func LogStatus(peerTotalOrder PeerTotalOrder) {
+ for vID, totalOrder := range peerTotalOrder {
+ log.Printf("[Validator %s] BPS: %.6f\n", vID, totalOrder.CalculateBlocksPerSecond())
+ }
+}