From 5148c8c229314363efb67d25049be72522beb38d Mon Sep 17 00:00:00 2001 From: chris erway Date: Mon, 26 Sep 2022 13:29:37 -0400 Subject: [PATCH 1/2] add BenchmarkBlockEncoding --- ledger/fullblock_perf_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ledger/fullblock_perf_test.go b/ledger/fullblock_perf_test.go index d2d50cd8f7..60a33da3ec 100644 --- a/ledger/fullblock_perf_test.go +++ b/ledger/fullblock_perf_test.go @@ -636,3 +636,35 @@ 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 + bc := setupEnv(b, numAccts) + + 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) + } + if (currentRound+1)*10%(2*numBlocks) == 0 { + fmt.Printf("%d%% %.1fs ", (currentRound+1)*100/numBlocks, time.Since(s3).Seconds()) + 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) + + b.ResetTimer() + encs := make([][]byte, len(bc.blocks)) + for i, blk := range bc.blocks { + encs[i] = protocol.Encode(&blk) + } +} From 592037b2a4a663f53d7d6cc9a26dbe57ab202bab Mon Sep 17 00:00:00 2001 From: chris erway Date: Thu, 13 Oct 2022 11:28:30 -0400 Subject: [PATCH 2/2] add ZSTD_LEVEL testing --- go.mod | 1 + go.sum | 2 ++ ledger/fullblock_perf_test.go | 28 ++++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index f20b25dc6d..96ddeb7044 100644 --- a/go.mod +++ b/go.mod @@ -39,6 +39,7 @@ require ( ) require ( + github.com/DataDog/zstd v1.5.2 // indirect github.com/chrismcguire/gobberish v0.0.0-20150821175641-1d8adb509a0e // indirect github.com/cpuguy83/go-md2man v1.0.8 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 58fbbdb98c..548f9d7a0d 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= +github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/algorand/avm-abi v0.1.0 h1:znZFQXpSUVYz37vXbaH5OZG2VK4snTyXwnc/tV9CVr4= github.com/algorand/avm-abi v0.1.0/go.mod h1:+CgwM46dithy850bpTeHh9MC99zpn2Snirb3QTl2O/g= github.com/algorand/falcon v0.0.0-20220727072124-02a2a64c4414 h1:nwYN+GQ7Z5OOfZwqBO1ma7DSlP7S1YrKWICOyjkwqrc= diff --git a/ledger/fullblock_perf_test.go b/ledger/fullblock_perf_test.go index 60a33da3ec..04f90c4c74 100644 --- a/ledger/fullblock_perf_test.go +++ b/ledger/fullblock_perf_test.go @@ -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++ } @@ -640,8 +643,12 @@ func callAppTransaction( // 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 := 0.0 + //newAcctProb := 1.0 bc := setupEnv(b, numAccts) + zstdLevel, err := strconv.Atoi(os.Getenv("ZSTD_LEVEL")) + 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) @@ -651,7 +658,8 @@ func BenchmarkBlockEncoding(b *testing.B) { currentRound := bc.round for bc.round == currentRound { // add pay transaction - payEvent(bc, mrand.Float64() < newAcctProb) + //payEvent(bc, mrand.Float64() < newAcctProb) + payEvent(bc, false) } if (currentRound+1)*10%(2*numBlocks) == 0 { fmt.Printf("%d%% %.1fs ", (currentRound+1)*100/numBlocks, time.Since(s3).Seconds()) @@ -662,9 +670,21 @@ func BenchmarkBlockEncoding(b *testing.B) { 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) - b.ResetTimer() 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])) + 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) + } }