mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-26 19:21:44 +00:00
Fixes to tm-bench transaction content
- Initialize random with current time as seed so transaction messages are different at every run - Added hash of hostname to make transactions coming from different hosts different in every case - Added current time to transaction to make sure that messages are different even if random numbers are the same in subsequent runs - Shortened the transaction size to 64 bytes from the original 250
This commit is contained in:
committed by
Anton Kaliaev
parent
cd5173f9a5
commit
45a7ae2e62
@ -14,6 +14,8 @@ import (
|
|||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
"github.com/tendermint/tools/tm-monitor/monitor"
|
"github.com/tendermint/tools/tm-monitor/monitor"
|
||||||
|
"math/rand"
|
||||||
|
"crypto/md5"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "0.1.0"
|
var version = "0.1.0"
|
||||||
@ -74,6 +76,8 @@ Examples:
|
|||||||
blockCh := make(chan tmtypes.Header, 100)
|
blockCh := make(chan tmtypes.Header, 100)
|
||||||
blockLatencyCh := make(chan float64, 100)
|
blockLatencyCh := make(chan float64, 100)
|
||||||
|
|
||||||
|
rand.Seed(time.Now().Unix())
|
||||||
|
|
||||||
nodes := startNodes(endpoints, blockCh, blockLatencyCh)
|
nodes := startNodes(endpoints, blockCh, blockLatencyCh)
|
||||||
|
|
||||||
transacters := startTransacters(endpoints, connections, txsRate)
|
transacters := startTransacters(endpoints, connections, txsRate)
|
||||||
@ -138,10 +142,18 @@ func startNodes(endpoints []string, blockCh chan<- tmtypes.Header, blockLatencyC
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startTransacters(endpoints []string, connections int, txsRate int) []*transacter {
|
func startTransacters(endpoints []string, connections int, txsRate int) []*transacter {
|
||||||
|
|
||||||
|
var hostHash [16]byte
|
||||||
|
if hostName , err := os.Hostname(); err != nil {
|
||||||
|
hostHash = md5.Sum([]byte("127.0.0.1"))
|
||||||
|
} else {
|
||||||
|
hostHash = md5.Sum([]byte(hostName))
|
||||||
|
}
|
||||||
|
|
||||||
transacters := make([]*transacter, len(endpoints))
|
transacters := make([]*transacter, len(endpoints))
|
||||||
|
|
||||||
for i, e := range endpoints {
|
for i, e := range endpoints {
|
||||||
t := newTransacter(e, connections, txsRate)
|
t := newTransacter(e, connections, txsRate, hostHash)
|
||||||
t.SetLogger(logger)
|
t.SetLogger(logger)
|
||||||
if err := t.Start(); err != nil {
|
if err := t.Start(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -30,6 +30,7 @@ type transacter struct {
|
|||||||
Target string
|
Target string
|
||||||
Rate int
|
Rate int
|
||||||
Connections int
|
Connections int
|
||||||
|
HostHash [16]byte
|
||||||
|
|
||||||
conns []*websocket.Conn
|
conns []*websocket.Conn
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
@ -38,11 +39,12 @@ type transacter struct {
|
|||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTransacter(target string, connections int, rate int) *transacter {
|
func newTransacter(target string, connections int, rate int, hosthash [16]byte) *transacter {
|
||||||
return &transacter{
|
return &transacter{
|
||||||
Target: target,
|
Target: target,
|
||||||
Rate: rate,
|
Rate: rate,
|
||||||
Connections: connections,
|
Connections: connections,
|
||||||
|
HostHash: hosthash,
|
||||||
conns: make([]*websocket.Conn, connections),
|
conns: make([]*websocket.Conn, connections),
|
||||||
logger: log.NewNopLogger(),
|
logger: log.NewNopLogger(),
|
||||||
}
|
}
|
||||||
@ -136,7 +138,7 @@ func (t *transacter) sendLoop(connIndex int) {
|
|||||||
|
|
||||||
for i := 0; i < t.Rate; i++ {
|
for i := 0; i < t.Rate; i++ {
|
||||||
// each transaction embeds connection index and tx number
|
// each transaction embeds connection index and tx number
|
||||||
tx := generateTx(connIndex, txNumber)
|
tx := generateTx(connIndex, txNumber, t.HostHash)
|
||||||
paramsJson, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)})
|
paramsJson, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("failed to encode params: %v\n", err)
|
fmt.Printf("failed to encode params: %v\n", err)
|
||||||
@ -189,11 +191,26 @@ func connect(host string) (*websocket.Conn, *http.Response, error) {
|
|||||||
return websocket.DefaultDialer.Dial(u.String(), nil)
|
return websocket.DefaultDialer.Dial(u.String(), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTx(a int, b int) []byte {
|
func generateTx(a int, b int, hosthash [16]byte) []byte {
|
||||||
tx := make([]byte, 250)
|
// 64 byte transaction
|
||||||
binary.PutUvarint(tx[:32], uint64(a))
|
tx := make([]byte, 64)
|
||||||
binary.PutUvarint(tx[32:64], uint64(b))
|
|
||||||
if _, err := rand.Read(tx[234:]); err != nil {
|
// 0-8 connection number
|
||||||
|
binary.PutUvarint(tx[:8], uint64(a))
|
||||||
|
|
||||||
|
// 8-16 transaction number
|
||||||
|
binary.PutUvarint(tx[8:16], uint64(b))
|
||||||
|
|
||||||
|
// 16-32 hostname hash
|
||||||
|
for i:=0; i < 16 ; i++ {
|
||||||
|
tx[16+i] = hosthash[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 32-40 current time
|
||||||
|
PutUvarint(tx[32:40], uint64(time.Now().Unix()))
|
||||||
|
|
||||||
|
// 40-64 random data
|
||||||
|
if _, err := rand.Read(tx[40:]); err != nil {
|
||||||
panic(errors.Wrap(err, "failed to generate transaction"))
|
panic(errors.Wrap(err, "failed to generate transaction"))
|
||||||
}
|
}
|
||||||
return tx
|
return tx
|
||||||
|
Reference in New Issue
Block a user