Merge branch 'master' of github.com:simple-rules/harmony-benchmark

pull/18/head
alok 6 years ago
commit 86fd0017a6
  1. 49
      aws-code/loghost/main.go
  2. 8
      benchmark.go
  3. 8
      client/txgen/main.go
  4. 9
      common/message.go
  5. 1
      consensus/consensus.go
  6. 2
      kill_node.sh
  7. 11
      p2p/peer.go

@ -0,0 +1,49 @@
package main
import (
"bufio"
"fmt"
"net"
"os"
)
const (
CONN_HOST = "localhost"
CONN_PORT = "3000"
CONN_TYPE = "tcp"
CONN_URL = CONN_HOST + ":" + CONN_PORT
)
func main() {
// Listen for incoming connections.
l, err := net.Listen(CONN_TYPE, CONN_URL)
if err != nil {
fmt.Println("Error listening:", err.Error())
os.Exit(1)
}
// Close the listener when the application closes.
defer l.Close()
fmt.Println("Listening on " + CONN_URL)
for {
// Listen for an incoming connection.
conn, err := l.Accept()
if err != nil {
fmt.Println("Error accepting: ", err.Error())
os.Exit(1)
}
// Handle connections in a new goroutine.
go handleRequest(conn)
}
}
// Handles incoming requests.
func handleRequest(conn net.Conn) {
for {
data, err := bufio.NewReader(conn).ReadString('\n')
if err != nil {
fmt.Println("Error reading:", err.Error())
break
}
fmt.Println(data)
}
}

@ -86,10 +86,10 @@ func main() {
// Setup a logger to stdout and log file.
logFileName := fmt.Sprintf("./%v/%v.log", *logFolder, *port)
h := log.MultiHandler(
log.Must.FileHandler(logFileName, log.LogfmtFormat()),
log.StdoutHandler)
// In cases where you just want a stdout logger, use the following one instead.
// h := log.CallerFileHandler(log.StdoutHandler)
log.StdoutHandler,
log.Must.FileHandler(logFileName, log.LogfmtFormat()), // Log to file
// log.Must.NetHandler("tcp", ":3000", log.JSONFormat()) // Log to remote
)
log.Root().SetHandler(h)
consensus := consensus.NewConsensus(*ip, *port, shardId, peers, leader)

@ -257,10 +257,10 @@ func main() {
// Setup a logger to stdout and log file.
logFileName := fmt.Sprintf("./%v/tx-generator.log", *logFolder)
h := log.MultiHandler(
log.Must.FileHandler(logFileName, log.LogfmtFormat()),
log.StdoutHandler)
// In cases where you just want a stdout logger, use the following one instead.
// h := log.CallerFileHandler(log.StdoutHandler)
log.StdoutHandler,
log.Must.FileHandler(logFileName, log.LogfmtFormat()), // Log to file
// log.Must.NetHandler("tcp", ":3000", log.JSONFormat()) // Log to remote
)
log.Root().SetHandler(h)
// Nodes containing utxopools to mirror the shards' data in the network

@ -4,6 +4,7 @@ import (
"errors"
)
// TODO: Fix the comments below.
/*
Node will process the content of the p2p message
@ -23,7 +24,15 @@ n - 2 bytes - actual message payload
*/
// NODE_TYPE_BYTES is # of bytes message category
const NODE_TYPE_BYTES = 1
// ACTION_TYPE_BYTES is # of bytes for message type which can be
// - for COMMITTEE category
// 0x00: consensus
// 0x01: sharding ...
// - for NODE category
// 0x00: transaction ...
const ACTION_TYPE_BYTES = 1
// The CATEGORY of messages

@ -146,6 +146,7 @@ func NewConsensus(ip, port, ShardID string, peers []p2p.Peer, leader p2p.Peer) C
if consensus.IsLeader {
consensus.ReadySignal = make(chan int)
// TODO: why do we need to do go rountine here.
// send a signal to indicate it's ready to run consensus
go func() {
consensus.ReadySignal <- 1

@ -1,4 +1,4 @@
for pid in `/bin/ps -fu $USER| grep "slave.go\|slave -port\|leader\|benchmark\|txgen" | grep -v "grep" | awk '{print $2}'`;
for pid in `/bin/ps -fu $USER| grep "benchmark\|txgen" | grep -v "grep" | awk '{print $2}'`;
do
echo 'Killed process: '$pid
kill -9 $pid

@ -6,6 +6,7 @@ import (
"log"
"net"
"strings"
"sync"
)
// Peer is the object for a p2p peer (node)
@ -28,10 +29,16 @@ func BroadcastMessage(peers []Peer, msg []byte) {
// Construct broadcast p2p message
content := ConstructP2pMessage(byte(17), msg)
// TODO(rj): Can optimize by calling goroutine.
var wg sync.WaitGroup
wg.Add(len(peers))
for _, peer := range peers {
send(peer.Ip, peer.Port, content)
// send(peer.Ip, peer.Port, content)
go func() {
defer wg.Done()
send(peer.Ip, peer.Port, content)
}()
}
wg.Wait()
}
// ConstructP2pMessage constructs the p2p message as [messageType, contentSize, content]

Loading…
Cancel
Save