mempool: benchmark improvements (#6418)

This commit is contained in:
Sam Kleinman
2021-05-04 10:45:32 -04:00
committed by GitHub
parent 7f30bc96f0
commit f366ae3c87
2 changed files with 18 additions and 8 deletions
+5 -2
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
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
}