Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -208,33 +208,33 @@ kill-test-docker: FORCE
# Benchmarks
#########################

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

Suggested change
$(go_cmd) test ./service/coordinator/dependencygraph/... -timeout 60m -bench "BenchmarkDependencyGraph.*" -run="^$$"
$(go_cmd) test ./service/coordinator/dependencygraph/... -timeout 60m -bench "Benchmark.*" -run="^$$"


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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a: testsig should also call test.ReportTxPerSecond(b).
b: The makefile command should be fixed.

Suggested change
$(go_cmd) test ./utils/signature/... -bench ".*" -run "^$$"
$(go_cmd) test ./utils/testsig/... -bench ".*" -run "^$$"


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

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

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

#########################
# Code Generation
Expand Down
2 changes: 2 additions & 0 deletions loadgen/metrics/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/hyperledger/fabric-x-committer/utils"
"github.com/hyperledger/fabric-x-committer/utils/test"
)

//nolint:gocognit // cognitive complexity 24 > 15
Expand Down Expand Up @@ -89,6 +90,7 @@ func BenchmarkLatencyTrackerPortion(b *testing.B) {
for _, txID := range txIDs {
sampler(txID)
}
test.ReportTxPerSecond(b)
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions loadgen/workload/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func BenchmarkGenTx(b *testing.B) {
txs := g.Consume(ctx, param)
sum += len(txs)
}
test.ReportTxPerSecond(b)
})
}

Expand All @@ -125,6 +126,7 @@ func BenchmarkGenQuery(b *testing.B) {
q := g.Consume(ctx, ConsumeParameters{RequestedItems: request})
sum += len(q)
}
test.ReportTxPerSecond(b)
})
}

Expand Down
14 changes: 0 additions & 14 deletions scripts/bench-tx-per-sec.awk

This file was deleted.

9 changes: 6 additions & 3 deletions service/coordinator/dependencygraph/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func BenchmarkDependencyGraph(b *testing.B) {
PrometheusMetricsProvider: monitoring.NewProvider(),
})

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This benchmark is designed such that the dependency graph internal queue will not be empty during the benchmark.
This is why we submit up to 3 times the number of TXs.
We stop the benchmark once the manager released b.N TXs.


ctx := b.Context()
outCtx := channel.NewReader(ctx, out)
Expand Down Expand Up @@ -120,10 +120,12 @@ func BenchmarkDependencyGraph(b *testing.B) {
// Generates the load to the manager's queue.
go func() {
var i uint64
for ctx.Err() == nil && len(txPoll) > 0 {
take := min(batchSize, len(txPoll))
remaining := b.N
for ctx.Err() == nil && remaining > 0 {
take := min(batchSize, len(txPoll), remaining)
batch := workload.MapToCoordinatorBatch(i, txPoll[:take])
txPoll = txPoll[take:]
remaining -= take
inCtx.Write(&TransactionBatch{
ID: i,
Txs: batch.Txs,
Expand All @@ -145,6 +147,7 @@ func BenchmarkDependencyGraph(b *testing.B) {
total += len(batch)
}
b.StopTimer()
test.ReportTxPerSecond(b)
})
}
})
Expand Down
4 changes: 3 additions & 1 deletion service/sidecar/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/hyperledger/fabric-x-committer/api/servicepb"
"github.com/hyperledger/fabric-x-committer/loadgen/workload"
"github.com/hyperledger/fabric-x-committer/utils"
"github.com/hyperledger/fabric-x-committer/utils/test"
)

func BenchmarkMapOneBlock(b *testing.B) {
Expand All @@ -29,6 +30,7 @@ func BenchmarkMapOneBlock(b *testing.B) {
b.ResetTimer()
mappedBlock, err := mapBlock(block, &txIDToHeight)
b.StopTimer()
test.ReportTxPerSecond(b)
require.NoError(b, err, "This can never occur unless there is a bug in the relay.")
require.NotNil(b, mappedBlock)
}
Expand Down Expand Up @@ -65,7 +67,7 @@ func BenchmarkMapBlockSize(b *testing.B) {
}
blockIdx++
}
b.ReportMetric(float64(b.N)/b.Elapsed().Seconds(), "tx/s")
test.ReportTxPerSecond(b)
})
}
}
Expand Down
1 change: 1 addition & 0 deletions service/sidecar/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func BenchmarkNotifier(b *testing.B) {
notifiedCount += len(res.TxStatusEvents)
}
b.StopTimer()
test.ReportTxPerSecond(b)
}

type notifierTestEnv struct {
Expand Down
10 changes: 6 additions & 4 deletions service/vc/preparer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ func requireEqualMapOfLists[K comparable, V any](t *testing.T, expected, actual
}
}

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

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

txPoll := workload.GenerateTransactions(b, nil, max(b.N*3, batchSize*3))
txPoll := workload.GenerateTransactions(b, nil, max(b.N, batchSize))

inCtx := channel.NewWriter(b.Context(), txBatch)
outCtx := channel.NewReader(b.Context(), preparedTxs)
b.ResetTimer()
// Generates the load to the preparer's queue.
go func() {
var i uint64
for b.Context().Err() == nil && len(txPoll) > 0 {
take := min(batchSize, len(txPoll))
remaining := b.N
for b.Context().Err() == nil && remaining > 0 {
take := min(batchSize, len(txPoll), remaining)
inCtx.Write(workload.MapToVcBatch(i, txPoll[:take]))
txPoll = txPoll[take:]
remaining -= take
i++
}
}()
Expand All @@ -723,6 +724,7 @@ func BenchmarkPrepare(b *testing.B) {
total += len(batch.txIDToHeight)
}
b.StopTimer()
test.ReportTxPerSecond(b)
})
}
}
2 changes: 2 additions & 0 deletions utils/deliverorderer/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/hyperledger/fabric-x-committer/loadgen/workload"
"github.com/hyperledger/fabric-x-committer/utils/deliver"
"github.com/hyperledger/fabric-x-committer/utils/test"
"github.com/hyperledger/fabric-x-committer/utils/testcrypto"
)

Expand All @@ -48,6 +49,7 @@ func BenchmarkVerifyBlock(b *testing.B) {
require.NoError(b, verErr)
}
b.StopTimer()
test.ReportTxPerSecond(b)
})
}
}
Expand Down
5 changes: 3 additions & 2 deletions utils/serialization/envelope_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/hyperledger/fabric-x-committer/loadgen/workload"
"github.com/hyperledger/fabric-x-committer/utils/serialization"
"github.com/hyperledger/fabric-x-committer/utils/test"
)

// TestUnwrapEnvelopeLite tests UnwrapEnvelopeLite with well-formed input.
Expand Down Expand Up @@ -198,7 +199,7 @@ func BenchmarkUnwrapEnvelope(b *testing.B) {
b.Fatal(err)
}
}
b.ReportMetric(float64(b.N)/b.Elapsed().Seconds(), "tx/s")
test.ReportTxPerSecond(b)
}

func BenchmarkUnwrapEnvelopeLite(b *testing.B) {
Expand All @@ -210,7 +211,7 @@ func BenchmarkUnwrapEnvelopeLite(b *testing.B) {
b.Fatal(err)
}
}
b.ReportMetric(float64(b.N)/b.Elapsed().Seconds(), "tx/s")
test.ReportTxPerSecond(b)
}

// loadgenEnvelopes generates realistic serialized envelopes using the load
Expand Down
15 changes: 15 additions & 0 deletions utils/test/benchmark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package test

import "testing"

// ReportTxPerSecond reports a tx/s custom metric on the benchmark.
func ReportTxPerSecond(b *testing.B) {
b.Helper()
b.ReportMetric(float64(b.N)/b.Elapsed().Seconds(), "tx/s")
}
Loading