-
Notifications
You must be signed in to change notification settings - Fork 476
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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++ | ||
} | ||
|
@@ -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) { | ||
numAccts := 100 | ||
//newAcctProb := 0.0 | ||
//newAcctProb := 1.0 | ||
bc := setupEnv(b, numAccts) | ||
zstdLevel, err := strconv.Atoi(os.Getenv("ZSTD_LEVEL")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
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) | ||
} | ||
} |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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