mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 22:31:21 +00:00
tools/tmbench: Improve accuracy with large tx sizes.
At larger tx sizes (e.g. > 10000) we were spending non-neglible amounts of time in tx creation, due to making the final bytes random. The slower the send loop, the less accurate it is at measuring the time tendermint took. (As we can't reach the promised contract of the given rate) There really isn't much need for that randomness, so this PR makes it such that only the txNumber gets bumped between txs from the same connection, thereby improving sendloop speed and accuracy.
This commit is contained in:
@ -160,6 +160,11 @@ func (t *transacter) sendLoop(connIndex int) {
|
||||
hostname = "127.0.0.1"
|
||||
}
|
||||
hostnameHash = md5.Sum([]byte(hostname))
|
||||
// each transaction embeds connection index, tx number and hash of the hostname
|
||||
// we update the tx number between successive txs
|
||||
tx := generateTx(connIndex, txNumber, t.Size, hostnameHash)
|
||||
txHex := make([]byte, len(tx)*2)
|
||||
hex.Encode(txHex, tx)
|
||||
|
||||
for {
|
||||
select {
|
||||
@ -172,17 +177,18 @@ func (t *transacter) sendLoop(connIndex int) {
|
||||
started = true
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
for i := 0; i < t.Rate; i++ {
|
||||
// each transaction embeds connection index, tx number and hash of the hostname
|
||||
tx := generateTx(connIndex, txNumber, t.Size, hostnameHash)
|
||||
paramsJSON, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)})
|
||||
// update tx number of the tx, and the corresponding hex
|
||||
updateTx(tx, txHex, txNumber)
|
||||
paramsJSON, err := json.Marshal(map[string]interface{}{"tx": txHex})
|
||||
if err != nil {
|
||||
fmt.Printf("failed to encode params: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
rawParamsJSON := json.RawMessage(paramsJSON)
|
||||
|
||||
c.SetWriteDeadline(time.Now().Add(sendTimeout))
|
||||
c.SetWriteDeadline(now.Add(sendTimeout))
|
||||
err = c.WriteJSON(rpctypes.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
ID: "tm-bench",
|
||||
@ -197,9 +203,10 @@ func (t *transacter) sendLoop(connIndex int) {
|
||||
return
|
||||
}
|
||||
|
||||
// Time added here is 7.13 ns/op, not significant enough to worry about
|
||||
if i%20 == 0 {
|
||||
if time.Now().After(endTime) {
|
||||
// cache the time.Now() reads to save time.
|
||||
if i%5 == 0 {
|
||||
now = time.Now()
|
||||
if now.After(endTime) {
|
||||
// Plus one accounts for sending this tx
|
||||
numTxSent = i + 1
|
||||
break
|
||||
@ -265,3 +272,13 @@ func generateTx(connIndex int, txNumber int, txSize int, hostnameHash [md5.Size]
|
||||
|
||||
return tx
|
||||
}
|
||||
|
||||
// warning, mutates input byte slice
|
||||
func updateTx(tx []byte, txHex []byte, txNumber int) {
|
||||
binary.PutUvarint(tx[8:16], uint64(txNumber))
|
||||
hexUpdate := make([]byte, 16)
|
||||
hex.Encode(hexUpdate, tx[8:16])
|
||||
for i := 16; i < 32; i++ {
|
||||
txHex[i] = hexUpdate[i-16]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user