Skip to content

Commit 3ea5438

Browse files
committed
wip
1 parent cf5966c commit 3ea5438

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

apps/testapp/kv/bench/main.go

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
)
1818

1919
type serverStats struct {
20+
InjectedTxs uint64 `json:"injected_txs"`
2021
ExecutedTxs uint64 `json:"executed_txs"`
2122
BlocksProduced uint64 `json:"blocks_produced"`
2223
}
@@ -73,24 +74,26 @@ func main() {
7374
ticker := time.NewTicker(time.Second)
7475
defer ticker.Stop()
7576

76-
var lastTxs uint64
77-
var peakTPS uint64
77+
var lastExecTxs uint64
78+
var peakTPS float64
7879

7980
loop:
8081
for {
8182
select {
8283
case <-ctx.Done():
8384
break loop
8485
case <-ticker.C:
85-
cur := totalTxs.Load()
86-
tps := cur - lastTxs
87-
lastTxs = cur
86+
stats := fetchStats(*addr)
87+
curExec := stats.ExecutedTxs - before.ExecutedTxs
88+
delta := curExec - lastExecTxs
89+
lastExecTxs = curExec
90+
tps := float64(delta)
8891
if tps > peakTPS {
8992
peakTPS = tps
9093
}
9194
elapsed := time.Since(start).Truncate(time.Second)
92-
fmt.Printf("\r[%6s] Total txs: %12d | Success: %12d | Fail: %8d | TPS: %12d ",
93-
elapsed, cur, success.Load(), failures.Load(), tps)
95+
fmt.Printf("\r[%6s] Executed txs: %12d | Success: %12d | Fail: %8d | TPS: %12.0f ",
96+
elapsed, curExec, success.Load(), failures.Load(), tps)
9497
}
9598
}
9699

@@ -102,12 +105,14 @@ loop:
102105

103106
after := fetchStats(*addr)
104107

105-
total := totalTxs.Load()
106-
avgTPS := float64(total) / elapsed.Seconds()
107-
108-
var txsPerBlock float64
109108
deltaBlocks := after.BlocksProduced - before.BlocksProduced
109+
deltaInjected := after.InjectedTxs - before.InjectedTxs
110110
deltaTxs := after.ExecutedTxs - before.ExecutedTxs
111+
112+
avgTPS := float64(deltaTxs) / elapsed.Seconds()
113+
avgInjectedTPS := float64(deltaInjected) / elapsed.Seconds()
114+
115+
var txsPerBlock float64
111116
if deltaBlocks > 0 {
112117
txsPerBlock = float64(deltaTxs) / float64(deltaBlocks)
113118
}
@@ -116,8 +121,8 @@ loop:
116121

117122
fmt.Println()
118123
fmt.Println()
119-
printResults(elapsed, uint64(*workers), uint64(*batchSize), total, success.Load(), failures.Load(),
120-
avgTPS, float64(peakTPS), deltaBlocks, deltaTxs, txsPerBlock, reached, *targetRPS)
124+
printResults(elapsed, uint64(*workers), uint64(*batchSize), totalTxs.Load(), success.Load(), failures.Load(),
125+
avgTPS, avgInjectedTPS, peakTPS, deltaBlocks, deltaInjected, deltaTxs, txsPerBlock, reached, *targetRPS)
121126
}
122127

123128
func singleWorker(ctx context.Context, addr string, success, failures, totalTxs *atomic.Uint64, done chan struct{}) {
@@ -293,8 +298,8 @@ func formatNum(n uint64) string {
293298
return result.String()
294299
}
295300

296-
func printResults(elapsed time.Duration, workers, batchSize, total, success, failures uint64,
297-
avgTPS, peakTPS float64, blocks, executedTxs uint64, txsPerBlock float64, reached bool, targetRPS uint64) {
301+
func printResults(elapsed time.Duration, workers, batchSize, sentTxs, batches, failures uint64,
302+
avgExecTPS, avgInjectedTPS, peakTPS float64, blocks, injectedTxs, executedTxs uint64, txsPerBlock float64, reached bool, targetRPS uint64) {
298303

299304
goalLabel := fmt.Sprintf("Goal (%s tx/s)", formatNum(targetRPS))
300305
sep := "+----------------------------------------+----------------------------------------+"
@@ -307,15 +312,17 @@ func printResults(elapsed time.Duration, workers, batchSize, total, success, fai
307312
fmt.Printf(rowFmt+"\n", "Workers", fmt.Sprintf("%d", workers))
308313
fmt.Printf(rowFmt+"\n", "Batch Size", fmt.Sprintf("%d txs/request", batchSize))
309314
fmt.Println(sep)
310-
fmt.Printf(rowFmt+"\n", "Total Transactions", formatNum(total))
311-
fmt.Printf(rowFmt+"\n", "Successful Requests", formatNum(success))
312-
fmt.Printf(rowFmt+"\n", "Failed Requests", formatNum(failures))
315+
fmt.Printf(rowFmt+"\n", "Client Txs Sent", formatNum(sentTxs))
316+
fmt.Printf(rowFmt+"\n", "Successful Batches", formatNum(batches))
317+
fmt.Printf(rowFmt+"\n", "Failed Batches", formatNum(failures))
313318
fmt.Println(sep)
314-
fmt.Printf(rowFmt+"\n", "Avg tx/s", formatFloat(avgTPS))
315-
fmt.Printf(rowFmt+"\n", "Peak tx/s (1s window)", formatFloat(peakTPS))
319+
fmt.Printf(rowFmt+"\n", "Avg Injected tx/s", formatFloat(avgInjectedTPS))
320+
fmt.Printf(rowFmt+"\n", "Avg Executed tx/s", formatFloat(avgExecTPS))
321+
fmt.Printf(rowFmt+"\n", "Peak Executed tx/s (1s)", formatFloat(peakTPS))
316322
fmt.Println(sep)
317-
fmt.Printf(rowFmt+"\n", "Server Blocks Produced", formatNum(blocks))
323+
fmt.Printf(rowFmt+"\n", "Server Txs Injected", formatNum(injectedTxs))
318324
fmt.Printf(rowFmt+"\n", "Server Txs Executed", formatNum(executedTxs))
325+
fmt.Printf(rowFmt+"\n", "Server Blocks Produced", formatNum(blocks))
319326
fmt.Printf(rowFmt+"\n", "Avg Txs per Block", fmt.Sprintf("%.2f", txsPerBlock))
320327
fmt.Println(sep)
321328

@@ -329,8 +336,12 @@ func printResults(elapsed time.Duration, workers, batchSize, total, success, fai
329336
} else {
330337
fmt.Printf(rowFmt+"\n", goalLabel, "NOT REACHED")
331338
fmt.Println(sep)
332-
fmt.Printf("\n Achieved %.2f%% of target (%.1fx away)\n",
333-
avgTPS/float64(targetRPS)*100, float64(targetRPS)/avgTPS)
339+
if avgExecTPS > 0 {
340+
fmt.Printf("\n Achieved %.2f%% of target (%.1fx away)\n",
341+
avgExecTPS/float64(targetRPS)*100, float64(targetRPS)/avgExecTPS)
342+
} else {
343+
fmt.Printf("\n No transactions executed during the test.\n")
344+
}
334345
}
335346
}
336347

0 commit comments

Comments
 (0)