aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-08-13 16:06:29 +0800
committermissionliao <38416648+missionliao@users.noreply.github.com>2018-08-13 16:06:29 +0800
commite22580beadb70991d95f13677f22701fe273791a (patch)
treec22a62d4c82c4b2bc66bdea7ab1a0e4cb790865f /simulation
parenta8ebf501e54406c7449f71dba0c9af696bbc4e21 (diff)
downloaddexon-consensus-e22580beadb70991d95f13677f22701fe273791a.tar
dexon-consensus-e22580beadb70991d95f13677f22701fe273791a.tar.gz
dexon-consensus-e22580beadb70991d95f13677f22701fe273791a.tar.bz2
dexon-consensus-e22580beadb70991d95f13677f22701fe273791a.tar.lz
dexon-consensus-e22580beadb70991d95f13677f22701fe273791a.tar.xz
dexon-consensus-e22580beadb70991d95f13677f22701fe273791a.tar.zst
dexon-consensus-e22580beadb70991d95f13677f22701fe273791a.zip
simulation: fix concurrent map write (#52)
Fix concurrent map write and also change k8s settings.
Diffstat (limited to 'simulation')
-rw-r--r--simulation/app.go9
-rw-r--r--simulation/constant.go2
-rw-r--r--simulation/kubernetes/config.toml.in2
-rw-r--r--simulation/kubernetes/peer-server.yaml8
4 files changed, 15 insertions, 6 deletions
diff --git a/simulation/app.go b/simulation/app.go
index 89b41a1..0330f07 100644
--- a/simulation/app.go
+++ b/simulation/app.go
@@ -20,6 +20,7 @@ package simulation
import (
"encoding/json"
"fmt"
+ "sync"
"time"
"github.com/dexon-foundation/dexon-consensus-core/common"
@@ -38,6 +39,7 @@ type simApp struct {
// uncofirmBlocks stores the blocks whose timestamps are not ready.
unconfirmedBlocks map[types.ValidatorID]common.Hashes
blockByHash map[common.Hash]*types.Block
+ blockByHashMutex sync.RWMutex
}
// newSimApp returns point to a new instance of simApp.
@@ -53,6 +55,9 @@ func newSimApp(id types.ValidatorID, Network PeerServerNetwork) *simApp {
}
func (a *simApp) addBlock(block *types.Block) {
+ a.blockByHashMutex.Lock()
+ defer a.blockByHashMutex.Unlock()
+
a.blockByHash[block.Hash] = block
}
@@ -74,6 +79,7 @@ func (a *simApp) getAckedBlocks(ackHash common.Hash) (output common.Hashes) {
break
}
}
+
// All of the Height of unconfirmed blocks are lower than the acked block.
if len(output) == 0 {
output, a.unconfirmedBlocks[ackBlock.ProposerID] = hashes, common.Hashes{}
@@ -89,6 +95,9 @@ func (a *simApp) StronglyAcked(blockHash common.Hash) {
// TotalOrderingDeliver is called when blocks are delivered by the total
// ordering algorithm.
func (a *simApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool) {
+ a.blockByHashMutex.Lock()
+ defer a.blockByHashMutex.Unlock()
+
now := time.Now()
blocks := make([]*types.Block, len(blockHashes))
for idx := range blockHashes {
diff --git a/simulation/constant.go b/simulation/constant.go
index 79ef84a..b805118 100644
--- a/simulation/constant.go
+++ b/simulation/constant.go
@@ -19,5 +19,5 @@ package simulation
const (
peerPort = 8080
- msgBufferSize = 256
+ msgBufferSize = 2560
)
diff --git a/simulation/kubernetes/config.toml.in b/simulation/kubernetes/config.toml.in
index 68008a2..4e4ec0b 100644
--- a/simulation/kubernetes/config.toml.in
+++ b/simulation/kubernetes/config.toml.in
@@ -4,7 +4,7 @@ title = "DEXON Consensus Simulation Config"
num = {{numValidators}}
propose_interval_mean = 5e+02
propose_interval_sigma = 3e+01
-max_block = 100
+max_block = 1000
[validator.consensus]
phi_ratio = 6.66670024394989e-01
diff --git a/simulation/kubernetes/peer-server.yaml b/simulation/kubernetes/peer-server.yaml
index 3a07590..eb8a70e 100644
--- a/simulation/kubernetes/peer-server.yaml
+++ b/simulation/kubernetes/peer-server.yaml
@@ -41,11 +41,11 @@ spec:
- containerPort: 8080
resources:
requests:
- cpu: 2
- memory: 2Gi
+ cpu: 4
+ memory: 4Gi
limits:
- cpu: 2
- memory: 2Gi
+ cpu: 4
+ memory: 4Gi
env:
- name: ROLE
value: "peer-server"