Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add BenchmarkBlockEncoding #4590

Closed
wants to merge 3 commits into from
Closed
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
54 changes: 53 additions & 1 deletion ledger/fullblock_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import (
"encoding/binary"
"fmt"
mrand "math/rand"
"os"
"path/filepath"
"strconv"
"testing"
"time"

"github.com/DataDog/zstd"
"github.com/stretchr/testify/require"

"github.com/algorand/go-algorand/agreement"
Expand Down Expand Up @@ -243,7 +246,7 @@ func payTo(bc *benchConfig, from, to basics.Address, amt uint64) {
tx := createPaymentTransaction(uint64(bc.txnCount), bc.round, from, to, amt)
var stxn transactions.SignedTxn
stxn.Txn = tx
stxn.Sig = crypto.Signature{1}
crypto.RandBytes(stxn.Sig[:])
addTransaction(bc, stxn)
bc.numPay++
}
Expand Down Expand Up @@ -636,3 +639,52 @@ func callAppTransaction(
appTx.Type = protocol.ApplicationCallTx
return
}

// BenchmarkBlockEncoding builds a full block of pay transactions and benchmarks the time it takes to encode b.N of them.
func BenchmarkBlockEncoding(b *testing.B) {
Copy link
Contributor

Choose a reason for hiding this comment

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

misnamed? This is really a benchmark of zstd compression at some level? I was expecting a benchmark around the msgp operation as 'encoding'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right, it was benchmarking the encoding before, and then I moved the place where ResetTimer and StopTimer was surrounding when Pavel started implementing block compression

numAccts := 100
//newAcctProb := 0.0
//newAcctProb := 1.0
bc := setupEnv(b, numAccts)
zstdLevel, err := strconv.Atoi(os.Getenv("ZSTD_LEVEL"))
Copy link
Contributor

Choose a reason for hiding this comment

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

who sets this env variable?

require.NoError(b, err, "bad ZSTD_LEVEL: %s", os.Getenv("ZSTD_LEVEL"))
b.Logf("ZSTD_LEVEL: %d", zstdLevel)

numBlocks := uint64(b.N)
fmt.Printf("Preparing... /%d: ", numBlocks)
s3 := time.Now()

for bc.round < numBlocks {
currentRound := bc.round
for bc.round == currentRound {
// add pay transaction
//payEvent(bc, mrand.Float64() < newAcctProb)
Copy link
Contributor

Choose a reason for hiding this comment

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

cleanup?

payEvent(bc, false)
}
if (currentRound+1)*10%(2*numBlocks) == 0 {
fmt.Printf("%d%% %.1fs ", (currentRound+1)*100/numBlocks, time.Since(s3).Seconds())
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use b.Logf or fmt.Printf. Mixing them is confusing.

s3 = time.Now()
}

}
fmt.Printf("\nSummary %d blocks and %d txns: pay %d/blk (%d%%) assets %d/blk (%d%%) apps %d/blk (%d%%)\n",
numBlocks, bc.txnCount, bc.numPay/numBlocks, bc.numPay*100/bc.txnCount, bc.numAst/numBlocks, bc.numAst*100/bc.txnCount, bc.numApp/numBlocks, bc.numApp*100/bc.txnCount)

encs := make([][]byte, len(bc.blocks))
for i, blk := range bc.blocks {
encs[i] = protocol.Encode(&blk)
}
zstdbufs := make([][]byte, len(bc.blocks))
b.ResetTimer()
for i := range encs {
zstdbufs[i], err = zstd.CompressLevel(nil, encs[i], zstdLevel)
b.Logf("zstd compress size: %d orig: %d", len(zstdbufs[i]), len(encs[i]))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not very useful (i.e. printing a line for each). Will be nice to collect the stats are print at the end as a summary of mean/median of the compression ratio.
Also, this may also impact the accuracy of the time measurement.

require.NoError(b, err)
}
b.StopTimer()
for i := range encs {
buf, err := zstd.Decompress(nil, zstdbufs[i])
b.Logf("zstd decompress size: %d orig: %d", len(buf), len(zstdbufs[i]))
require.NoError(b, err)
}
}