mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-03 10:32:05 +00:00
Based on the discussion in #7723, make the CheckTx benchmark exercise GetEvictableTxs which is one of the critical paths in CheckTx. After profiling the test, the sorting will occupy 90% of the CPU time in CheckTx. In the test it doesn't count the influence of the preCheck, postCheck, and CheckTxAsync when the mempool is full.
42 lines
927 B
Go
42 lines
927 B
Go
package mempool
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"math/rand"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func BenchmarkTxMempool_CheckTx(b *testing.B) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// setup the cache and the mempool number for hitting GetEvictableTxs during the
|
|
// benchmark. 5000 is the current default mempool size in the TM config.
|
|
txmp := setup(ctx, b, 10000)
|
|
txmp.config.Size = 5000
|
|
|
|
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
const peerID = 1
|
|
|
|
b.ResetTimer()
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
b.StopTimer()
|
|
prefix := make([]byte, 20)
|
|
_, err := rng.Read(prefix)
|
|
require.NoError(b, err)
|
|
|
|
priority := int64(rng.Intn(9999-1000) + 1000)
|
|
tx := []byte(fmt.Sprintf("sender-%d-%d=%X=%d", n, peerID, prefix, priority))
|
|
txInfo := TxInfo{SenderID: uint16(peerID)}
|
|
|
|
b.StartTimer()
|
|
|
|
require.NoError(b, txmp.CheckTx(ctx, tx, nil, txInfo))
|
|
}
|
|
}
|