Skip to content

Commit aa121ca

Browse files
committed
[bench] Replace AWK tx/s script with b.ReportMetric
Add test.ReportTxPerSecond(b) helper and call it from all benchmarks. Cap batch benchmarks to exactly b.N transactions for accurate reporting. Remove bench-tx-per-sec.awk and Makefile AWK pipes. Signed-off-by: Senthilnathan <cendhu@gmail.com>
1 parent 108e56b commit aa121ca

11 files changed

Lines changed: 53 additions & 36 deletions

File tree

Makefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,33 +208,33 @@ kill-test-docker: FORCE
208208
# Benchmarks
209209
#########################
210210

211-
# Run a load generation benchmarks with added TX/sec column.
211+
# Run load generation benchmarks.
212212
bench-loadgen: FORCE
213-
$(go_cmd) test ./loadgen/... -bench "Benchmark.*" -run="^$$" | awk -f scripts/bench-tx-per-sec.awk
213+
$(go_cmd) test ./loadgen/... -bench "Benchmark.*" -run="^$$"
214214

215-
# Run dependency detector benchmarks with added op/sec column.
215+
# Run dependency detector benchmarks.
216216
bench-dep: FORCE
217-
$(go_cmd) test ./service/coordinator/dependencygraph/... -timeout 60m -bench "BenchmarkDependencyGraph.*" -run="^$$" | awk -f scripts/bench-tx-per-sec.awk
217+
$(go_cmd) test ./service/coordinator/dependencygraph/... -timeout 60m -bench "BenchmarkDependencyGraph.*" -run="^$$"
218218

219-
# Run dependency detector benchmarks with added op/sec column.
219+
# Run preparer benchmarks.
220220
bench-preparer: FORCE
221-
$(go_cmd) test ./service/vc/... -bench "BenchmarkPrepare.*" -run "^$$" | awk -f scripts/bench-tx-per-sec.awk
221+
$(go_cmd) test ./service/vc/... -bench "BenchmarkPrepare.*" -run "^$$"
222222

223-
# Run signature benchmarks with added op/sec column.
223+
# Run signature benchmarks.
224224
bench-sign: FORCE
225-
$(go_cmd) test ./utils/signature/... -bench ".*" -run "^$$" | awk -f scripts/bench-tx-per-sec.awk
225+
$(go_cmd) test ./utils/signature/... -bench ".*" -run "^$$"
226226

227-
# Run sidecar benchmarks with added op/sec column.
227+
# Run sidecar benchmarks.
228228
bench-sidecar: FORCE
229-
$(go_cmd) test ./service/sidecar/... -bench "Benchmark.*" -run "^$$" | awk -f scripts/bench-tx-per-sec.awk
229+
$(go_cmd) test ./service/sidecar/... -bench "Benchmark.*" -run "^$$"
230230

231231
# Run serialization benchmarks.
232232
bench-serialization: FORCE
233233
$(go_cmd) test ./utils/serialization/... -bench "Benchmark.*" -run "^$$"
234234

235-
# Run deliver benchmarks with added op/sec column.
235+
# Run deliver benchmarks.
236236
bench-deliver: FORCE
237-
$(go_cmd) test ./utils/deliverorderer/... -bench "Benchmark.*" -run "^$$" | awk -f scripts/bench-tx-per-sec.awk
237+
$(go_cmd) test ./utils/deliverorderer/... -bench "Benchmark.*" -run "^$$"
238238

239239
#########################
240240
# Code Generation

loadgen/metrics/tracker_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/stretchr/testify/require"
1818

1919
"github.com/hyperledger/fabric-x-committer/utils"
20+
"github.com/hyperledger/fabric-x-committer/utils/test"
2021
)
2122

2223
//nolint:gocognit // cognitive complexity 24 > 15
@@ -89,6 +90,7 @@ func BenchmarkLatencyTrackerPortion(b *testing.B) {
8990
for _, txID := range txIDs {
9091
sampler(txID)
9192
}
93+
test.ReportTxPerSecond(b)
9294
})
9395
}
9496
}

loadgen/workload/stream_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func BenchmarkGenTx(b *testing.B) {
106106
txs := g.Consume(ctx, param)
107107
sum += len(txs)
108108
}
109+
test.ReportTxPerSecond(b)
109110
})
110111
}
111112

@@ -125,6 +126,7 @@ func BenchmarkGenQuery(b *testing.B) {
125126
q := g.Consume(ctx, ConsumeParameters{RequestedItems: request})
126127
sum += len(q)
127128
}
129+
test.ReportTxPerSecond(b)
128130
})
129131
}
130132

scripts/bench-tx-per-sec.awk

Lines changed: 0 additions & 14 deletions
This file was deleted.

service/coordinator/dependencygraph/manager_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func BenchmarkDependencyGraph(b *testing.B) {
9090
PrometheusMetricsProvider: monitoring.NewProvider(),
9191
})
9292

93-
txPoll := workload.GenerateTransactions(b, p, max(b.N*3, batchSize*3))
93+
txPoll := workload.GenerateTransactions(b, p, max(b.N, batchSize))
9494

9595
ctx := b.Context()
9696
outCtx := channel.NewReader(ctx, out)
@@ -120,10 +120,12 @@ func BenchmarkDependencyGraph(b *testing.B) {
120120
// Generates the load to the manager's queue.
121121
go func() {
122122
var i uint64
123-
for ctx.Err() == nil && len(txPoll) > 0 {
124-
take := min(batchSize, len(txPoll))
123+
remaining := b.N
124+
for ctx.Err() == nil && remaining > 0 {
125+
take := min(batchSize, len(txPoll), remaining)
125126
batch := workload.MapToCoordinatorBatch(i, txPoll[:take])
126127
txPoll = txPoll[take:]
128+
remaining -= take
127129
inCtx.Write(&TransactionBatch{
128130
ID: i,
129131
Txs: batch.Txs,
@@ -145,6 +147,7 @@ func BenchmarkDependencyGraph(b *testing.B) {
145147
total += len(batch)
146148
}
147149
b.StopTimer()
150+
test.ReportTxPerSecond(b)
148151
})
149152
}
150153
})

service/sidecar/mapping_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/hyperledger/fabric-x-committer/api/servicepb"
1919
"github.com/hyperledger/fabric-x-committer/loadgen/workload"
2020
"github.com/hyperledger/fabric-x-committer/utils"
21+
"github.com/hyperledger/fabric-x-committer/utils/test"
2122
)
2223

2324
func BenchmarkMapOneBlock(b *testing.B) {
@@ -29,6 +30,7 @@ func BenchmarkMapOneBlock(b *testing.B) {
2930
b.ResetTimer()
3031
mappedBlock, err := mapBlock(block, &txIDToHeight)
3132
b.StopTimer()
33+
test.ReportTxPerSecond(b)
3234
require.NoError(b, err, "This can never occur unless there is a bug in the relay.")
3335
require.NotNil(b, mappedBlock)
3436
}
@@ -65,7 +67,7 @@ func BenchmarkMapBlockSize(b *testing.B) {
6567
}
6668
blockIdx++
6769
}
68-
b.ReportMetric(float64(b.N)/b.Elapsed().Seconds(), "tx/s")
70+
test.ReportTxPerSecond(b)
6971
})
7072
}
7173
}

service/sidecar/notify_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func BenchmarkNotifier(b *testing.B) {
9090
notifiedCount += len(res.TxStatusEvents)
9191
}
9292
b.StopTimer()
93+
test.ReportTxPerSecond(b)
9394
}
9495

9596
type notifierTestEnv struct {

service/vc/preparer_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ func requireEqualMapOfLists[K comparable, V any](t *testing.T, expected, actual
681681
}
682682
}
683683

684-
//nolint:gocognit // single method for simplicity.
685684
func BenchmarkPrepare(b *testing.B) {
686685
flogging.ActivateSpec("fatal")
687686

@@ -698,18 +697,20 @@ func BenchmarkPrepare(b *testing.B) {
698697
return p.run(ctx, w)
699698
}, nil)
700699

701-
txPoll := workload.GenerateTransactions(b, nil, max(b.N*3, batchSize*3))
700+
txPoll := workload.GenerateTransactions(b, nil, max(b.N, batchSize))
702701

703702
inCtx := channel.NewWriter(b.Context(), txBatch)
704703
outCtx := channel.NewReader(b.Context(), preparedTxs)
705704
b.ResetTimer()
706705
// Generates the load to the preparer's queue.
707706
go func() {
708707
var i uint64
709-
for b.Context().Err() == nil && len(txPoll) > 0 {
710-
take := min(batchSize, len(txPoll))
708+
remaining := b.N
709+
for b.Context().Err() == nil && remaining > 0 {
710+
take := min(batchSize, len(txPoll), remaining)
711711
inCtx.Write(workload.MapToVcBatch(i, txPoll[:take]))
712712
txPoll = txPoll[take:]
713+
remaining -= take
713714
i++
714715
}
715716
}()
@@ -723,6 +724,7 @@ func BenchmarkPrepare(b *testing.B) {
723724
total += len(batch.txIDToHeight)
724725
}
725726
b.StopTimer()
727+
test.ReportTxPerSecond(b)
726728
})
727729
}
728730
}

utils/deliverorderer/verify_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/hyperledger/fabric-x-committer/loadgen/workload"
2424
"github.com/hyperledger/fabric-x-committer/utils/deliver"
25+
"github.com/hyperledger/fabric-x-committer/utils/test"
2526
"github.com/hyperledger/fabric-x-committer/utils/testcrypto"
2627
)
2728

@@ -48,6 +49,7 @@ func BenchmarkVerifyBlock(b *testing.B) {
4849
require.NoError(b, verErr)
4950
}
5051
b.StopTimer()
52+
test.ReportTxPerSecond(b)
5153
})
5254
}
5355
}

utils/serialization/envelope_wrapper_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
"github.com/hyperledger/fabric-protos-go-apiv2/common"
1313
"github.com/stretchr/testify/require"
14+
15+
"github.com/hyperledger/fabric-x-committer/utils/test"
1416
"google.golang.org/protobuf/types/known/timestamppb"
1517

1618
"github.com/hyperledger/fabric-x-common/protoutil"
@@ -198,7 +200,7 @@ func BenchmarkUnwrapEnvelope(b *testing.B) {
198200
b.Fatal(err)
199201
}
200202
}
201-
b.ReportMetric(float64(b.N)/b.Elapsed().Seconds(), "tx/s")
203+
test.ReportTxPerSecond(b)
202204
}
203205

204206
func BenchmarkUnwrapEnvelopeLite(b *testing.B) {
@@ -210,7 +212,7 @@ func BenchmarkUnwrapEnvelopeLite(b *testing.B) {
210212
b.Fatal(err)
211213
}
212214
}
213-
b.ReportMetric(float64(b.N)/b.Elapsed().Seconds(), "tx/s")
215+
test.ReportTxPerSecond(b)
214216
}
215217

216218
// loadgenEnvelopes generates realistic serialized envelopes using the load

0 commit comments

Comments
 (0)