aboutsummaryrefslogtreecommitdiffstats
path: root/core/test
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-08-28 13:13:21 +0800
committerGitHub <noreply@github.com>2018-08-28 13:13:21 +0800
commit7e9d2db5576d697b578669c935b2e7bbf9422ec7 (patch)
treee4fb9f4b95b23934a142a88ee05fbd49dff50b3c /core/test
parent9c8f9a447bfd768a7b29db904bd604410ec66a09 (diff)
downloadtangerine-consensus-7e9d2db5576d697b578669c935b2e7bbf9422ec7.tar
tangerine-consensus-7e9d2db5576d697b578669c935b2e7bbf9422ec7.tar.gz
tangerine-consensus-7e9d2db5576d697b578669c935b2e7bbf9422ec7.tar.bz2
tangerine-consensus-7e9d2db5576d697b578669c935b2e7bbf9422ec7.tar.lz
tangerine-consensus-7e9d2db5576d697b578669c935b2e7bbf9422ec7.tar.xz
tangerine-consensus-7e9d2db5576d697b578669c935b2e7bbf9422ec7.tar.zst
tangerine-consensus-7e9d2db5576d697b578669c935b2e7bbf9422ec7.zip
core: tune performance (#73)
- Avoid using recursive function in critical path. - Do not write through when using levelDB. Things put to levelDB would be safe from panic even we didn't force to write through every time. - Dump count of confirmed blocks proposed by self. - Avoid allocating variables in loop. - Return length of acking node set, we only need that when total ordering. - Fix potential bug: make sure win records updated when acking height vectors of candidates are changed. - Keep dirty validators in slice. - Add cache for objects to ease the pressure to garbage collector. - Cache global acking status when total ordering. - Add method to recycle blocks. - Marshal JSON should be called once for each broadcast. - Make updateWinRecord called in parallel. - Log average / deviation of latencies when simulation finished.
Diffstat (limited to 'core/test')
-rw-r--r--core/test/utils.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/core/test/utils.go b/core/test/utils.go
index 35fbdd5..789c28e 100644
--- a/core/test/utils.go
+++ b/core/test/utils.go
@@ -18,6 +18,9 @@
package test
import (
+ "math"
+ "time"
+
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
)
@@ -38,3 +41,26 @@ func GenerateRandomValidatorIDs(validatorCount int) (vIDs types.ValidatorIDs) {
}
return
}
+
+// CalcLatencyStatistics calculates average and deviation from a slice
+// of latencies.
+func CalcLatencyStatistics(latencies []time.Duration) (avg, dev time.Duration) {
+ var (
+ sum float64
+ sumOfSquareDiff float64
+ )
+
+ // Calculate average.
+ for _, v := range latencies {
+ sum += float64(v)
+ }
+ avgAsFloat := sum / float64(len(latencies))
+ avg = time.Duration(avgAsFloat)
+ // Calculate deviation
+ for _, v := range latencies {
+ diff := math.Abs(float64(v) - avgAsFloat)
+ sumOfSquareDiff += diff * diff
+ }
+ dev = time.Duration(math.Sqrt(sumOfSquareDiff / float64(len(latencies)-1)))
+ return
+}