Browse Source

mempool: benchmark improvements (#6418)

pull/6421/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
f366ae3c87
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions
  1. +5
    -2
      mempool/bench_test.go
  2. +13
    -6
      mempool/clist_mempool.go

+ 5
- 2
mempool/bench_test.go View File

@ -13,13 +13,14 @@ func BenchmarkReap(b *testing.B) {
cc := proxy.NewLocalClientCreator(app)
mempool, cleanup := newMempoolWithApp(cc)
defer cleanup()
mempool.config.Size = 100000
size := 10000
for i := 0; i < size; i++ {
tx := make([]byte, 8)
binary.BigEndian.PutUint64(tx, uint64(i))
if err := mempool.CheckTx(tx, nil, TxInfo{}); err != nil {
b.Error(err)
b.Fatal(err)
}
}
b.ResetTimer()
@ -34,11 +35,13 @@ func BenchmarkCheckTx(b *testing.B) {
mempool, cleanup := newMempoolWithApp(cc)
defer cleanup()
mempool.config.Size = 1000000
for i := 0; i < b.N; i++ {
tx := make([]byte, 8)
binary.BigEndian.PutUint64(tx, uint64(i))
if err := mempool.CheckTx(tx, nil, TxInfo{}); err != nil {
b.Error(err)
b.Fatal(err)
}
}
}


+ 13
- 6
mempool/clist_mempool.go View File

@ -489,7 +489,10 @@ func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs {
mem.updateMtx.RLock()
defer mem.updateMtx.RUnlock()
var totalGas int64
var (
totalGas int64
runningSize int64
)
// TODO: we will get a performance boost if we have a good estimate of avg
// size per tx, and set the initial capacity based off of that.
@ -498,22 +501,26 @@ func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs {
for e := mem.txs.Front(); e != nil; e = e.Next() {
memTx := e.Value.(*mempoolTx)
dataSize := types.ComputeProtoSizeForTxs(append(txs, memTx.tx))
txs = append(txs, memTx.tx)
dataSize := types.ComputeProtoSizeForTxs([]types.Tx{memTx.tx})
// Check total size requirement
if maxBytes > -1 && dataSize > maxBytes {
return txs
if maxBytes > -1 && runningSize+dataSize > maxBytes {
return txs[:len(txs)-1]
}
runningSize += dataSize
// Check total gas requirement.
// If maxGas is negative, skip this check.
// Since newTotalGas < masGas, which
// must be non-negative, it follows that this won't overflow.
newTotalGas := totalGas + memTx.gasWanted
if maxGas > -1 && newTotalGas > maxGas {
return txs
return txs[:len(txs)-1]
}
totalGas = newTotalGas
txs = append(txs, memTx.tx)
}
return txs
}


Loading…
Cancel
Save