bnb-chain / op-geth

GNU Lesser General Public License v3.0
58 stars 47 forks source link

optimization: enqueue transactions in parallel from p2p #173

Closed andyzhang2023 closed 1 month ago

andyzhang2023 commented 2 months ago

Description

Enqueuing a transaction into the txpool, it costs about 80us per transaction to call txpool.Add(tx), within which the txpool.addLocked(tx) costs only 15us. So by calling txpool.Add(tx) in parallel, we can improve the performance of txpool.Add(tx) from 12KTPS to 60KTPS:

  1. before improvement: 1s/80us = 1000000/80 = 12500
  2. after improvement: 1s/15us = 1000000/15 = 66666

It helps a lot when the traffic is heavy and a lot of transactions are accumulated in the broadcasting caches, like "p2p buffers", TCP read buffer and TCP write buffers.