Browse Source

mempool: fix benchmark CheckTx for hitting the GetEvictableTxs call (#7796)

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.
pull/7813/head
JayT106 3 years ago
committed by GitHub
parent
commit
58d8bad99a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions
  1. +9
    -2
      internal/mempool/mempool_bench_test.go

+ 9
- 2
internal/mempool/mempool_bench_test.go View File

@ -14,8 +14,13 @@ func BenchmarkTxMempool_CheckTx(b *testing.B) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() 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 := setup(ctx, b, 10000)
txmp.config.Size = 5000
rng := rand.New(rand.NewSource(time.Now().UnixNano())) rng := rand.New(rand.NewSource(time.Now().UnixNano()))
const peerID = 1
b.ResetTimer() b.ResetTimer()
@ -26,9 +31,11 @@ func BenchmarkTxMempool_CheckTx(b *testing.B) {
require.NoError(b, err) require.NoError(b, err)
priority := int64(rng.Intn(9999-1000) + 1000) priority := int64(rng.Intn(9999-1000) + 1000)
tx := []byte(fmt.Sprintf("%X=%d", prefix, priority))
tx := []byte(fmt.Sprintf("sender-%d-%d=%X=%d", n, peerID, prefix, priority))
txInfo := TxInfo{SenderID: uint16(peerID)}
b.StartTimer() b.StartTimer()
require.NoError(b, txmp.CheckTx(ctx, tx, nil, TxInfo{}))
require.NoError(b, txmp.CheckTx(ctx, tx, nil, txInfo))
} }
} }

Loading…
Cancel
Save