running benchmark with utils and scripts

pull/126/head
ak 6 years ago
parent 31e4e43d41
commit 3fe8432be3
  1. 55
      benchmark.go
  2. 3
      deploy.sh
  3. 23
      utils/utils.go

@ -12,8 +12,8 @@ import (
"github.com/harmony-one/harmony/attack" "github.com/harmony-one/harmony/attack"
"github.com/harmony-one/harmony/consensus" "github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/db" "github.com/harmony-one/harmony/db"
"github.com/harmony-one/harmony/discovery"
"github.com/harmony-one/harmony/log" "github.com/harmony-one/harmony/log"
pkg_newnode "github.com/harmony-one/harmony/newnode"
"github.com/harmony-one/harmony/node" "github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/profiler" "github.com/harmony-one/harmony/profiler"
@ -73,9 +73,11 @@ func loggingInit(logFolder, role, ip, port string, onlyLogTps bool) {
log.Root().SetHandler(h) log.Root().SetHandler(h)
} }
func main() { func main() {
accountModel := flag.Bool("account_model", true, "Whether to use account model") accountModel := flag.Bool("account_model", true, "Whether to use account model")
// TODO: use http://getmyipaddress.org/ or http://www.get-myip.com/ to retrieve my IP address //TODO: use http://getmyipaddress.org/ or http://www.get-myip.com/ to retrieve my IP address
ip := flag.String("ip", "127.0.0.1", "IP of the node") ip := flag.String("ip", "127.0.0.1", "IP of the node")
port := flag.String("port", "9000", "port of the node.") port := flag.String("port", "9000", "port of the node.")
configFile := flag.String("config_file", "config.txt", "file containing all ip addresses") configFile := flag.String("config_file", "config.txt", "file containing all ip addresses")
@ -88,12 +90,12 @@ func main() {
syncNode := flag.Bool("sync_node", false, "Whether this node is a new node joining blockchain and it needs to get synced before joining consensus.") syncNode := flag.Bool("sync_node", false, "Whether this node is a new node joining blockchain and it needs to get synced before joining consensus.")
onlyLogTps := flag.Bool("only_log_tps", false, "Only log TPS if true") onlyLogTps := flag.Bool("only_log_tps", false, "Only log TPS if true")
// This IP belongs to jenkins.harmony.one //This IP belongs to jenkins.harmony.one
idcIP := flag.String("idc", "54.183.5.66", "IP of the identity chain") idcIP := flag.String("idc", "127.0.0.1", "IP of the identity chain")
idcPort := flag.String("idc_port", "8080", "port of the identity chain") idcPort := flag.String("idc_port", "8081", "port of the identity chain")
peerDisvoery := flag.Bool("peer_discovery", false, "Enable Peer Discovery") peerDiscovery := flag.Bool("peer_discovery", true, "Enable Peer Discovery")
// Leader needs to have a minimal number of peers to start consensus // // Leader needs to have a minimal number of peers to start consensus
minPeers := flag.Int("min_peers", 100, "Minimal number of Peers in shard") minPeers := flag.Int("min_peers", 100, "Minimal number of Peers in shard")
flag.Parse() flag.Parse()
@ -113,37 +115,31 @@ func main() {
var leader p2p.Peer var leader p2p.Peer
var selfPeer p2p.Peer var selfPeer p2p.Peer
var clientPeer *p2p.Peer var clientPeer *p2p.Peer
// Use Peer Discovery to get shard/leader/peer/... //Use Peer Discovery to get shard/leader/peer/...
priKey, pubKey := utils.GenKey(*ip, *port) if *peerDiscovery {
if *peerDisvoery { candidateNode := pkg_newnode.New(*ip, *port)
// Contact Identity Chain BCPeer := p2p.Peer{IP: *idcIP, Port: *idcPort}
// This is a blocking call service := candidateNode.NewService(*ip, *port)
// Assume @ak has get it working candidateNode.ConnectBeaconChain(BCPeer)
// TODO: this has to work with @ak's fix shardID = candidateNode.GetShardID()
discoveryConfig := discovery.New(priKey, pubKey) leader = candidateNode.GetLeader()
selfPeer = candidateNode.GetSelfPeer()
err := discoveryConfig.StartClientMode(*idcIP, *idcPort) clientPeer = candidateNode.GetClientPeer()
if err != nil { service.Stop()
fmt.Println("Unable to start peer discovery! ", err) selfPeer.PubKey = candidateNode.PubK
os.Exit(1)
}
shardID = discoveryConfig.GetShardID()
leader = discoveryConfig.GetLeader()
peers = discoveryConfig.GetPeers()
selfPeer = discoveryConfig.GetSelfPeer()
} else { } else {
distributionConfig := utils.NewDistributionConfig() distributionConfig := utils.NewDistributionConfig()
distributionConfig.ReadConfigFile(*configFile) distributionConfig.ReadConfigFile(*configFile)
shardID = distributionConfig.GetShardID(*ip, *port) shardID = distributionConfig.GetShardID(*ip, *port)
peers = distributionConfig.GetPeers(*ip, *port, shardID)
leader = distributionConfig.GetLeader(shardID) leader = distributionConfig.GetLeader(shardID)
selfPeer = distributionConfig.GetSelfPeer(*ip, *port, shardID) selfPeer = distributionConfig.GetSelfPeer(*ip, *port, shardID)
_, pubKey := utils.GenKey(*ip, *port)
selfPeer.PubKey = pubKey
// Create client peer. // Create client peer.
clientPeer = distributionConfig.GetClientPeer() clientPeer = distributionConfig.GetClientPeer()
} }
selfPeer.PubKey = pubKey fmt.Println(peers, leader, selfPeer, clientPeer, *logFolder, *minPeers)
var role string var role string
if leader.IP == *ip && leader.Port == *port { if leader.IP == *ip && leader.Port == *port {
@ -156,7 +152,6 @@ func main() {
// Attack determination. // Attack determination.
attack.GetInstance().SetAttackEnabled(attackDetermination(*attackedMode)) attack.GetInstance().SetAttackEnabled(attackDetermination(*attackedMode))
} }
// Init logging. // Init logging.
loggingInit(*logFolder, role, *ip, *port, *onlyLogTps) loggingInit(*logFolder, role, *ip, *port, *onlyLogTps)
@ -223,7 +218,7 @@ func main() {
}() }()
} }
} else { } else {
if *peerDisvoery { if *peerDiscovery {
go currentNode.JoinShard(leader) go currentNode.JoinShard(leader)
} }
} }

@ -73,7 +73,8 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardID <<< $line IFS=' ' read ip port mode shardID <<< $line
#echo $ip $port $mode #echo $ip $port $mode
if [ "$mode" != "client" ]; then if [ "$mode" != "client" ]; then
./bin/benchmark -ip $ip -port $port -config_file $config -log_folder $log_folder $DB $PEER -min_peers $MIN & ./bin/benchmark -ip $ip -port $port -log_folder $log_folder $DB $PEER -min_peers $MIN &
sleep 10
fi fi
done < $config done < $config

@ -67,3 +67,26 @@ func GenKey(ip, port string) (kyber.Scalar, kyber.Point) {
return priKey, pubKey return priKey, pubKey
} }
// AllocateShard uses the number of current nodes and number of shards
// to return the shardnum a new node belongs to, it also tells whether the node is a leader
func AllocateShard(numnode, numshards int) (int, bool) {
if numshards == 1 {
if numnode == 1 {
return 1, true
} else {
return 1, false
}
}
if numnode <= numshards {
return numnode, true
} else {
shardnum := numnode % numshards
if shardnum == 0 {
return numshards, false
} else {
return shardnum, false
}
}
}

Loading…
Cancel
Save