I use Brownie to create and execute transactions on a custom Anvil fork. Note that I am not using Brownie's development network cmd to run this fork; instead, I have forked the network separately and added the network using brownie networks add but generally, this case is also valid for other forking methods that I have tried such as ganache.
As I create more transactions, I've observed that the speed of transaction creation gradually decreases. After running my script for a while, hardware resource usage (CPU, RAM, Disk) significantly increases, and the CPU hits 100% usage (one entire core). This leads me to suspect that Brownie might have a bottleneck.
Add the network to brownie (brownie networks add Polygon anvil_polygon_mainnet_fork host='http://127.0.0.1:42069' chainid=137)
Run the Brownie script to create transactions (brownie run scripts/bulktx.py --network anvil_polygon_mainnet_fork)
Observe the decrease in transaction creation speed and increase in hardware resource usage over time.
Expected Behavior:
The transaction creation speed should remain consistent regardless of the number of transactions created without significant hardware resource increase.
Actual Behavior:
The transaction creation speed decreases over time, and hardware usage significantly increases, eventually hitting 100% CPU usage.
BulkTx script:
from brownie import accounts, web3
from web3.middleware import construct_simple_cache_middleware
from time import time
def main():
web3.middleware_onion.add(construct_simple_cache_middleware(cache_class=dict))
acc = accounts.at('<some public address that has balance in the forked network>', force=True)
print(acc: {acc}')
start_time, idx = time(), 0
while idx := idx+1:
tx = acc.transfer(acc.address, 1000000000000000)
print(f'{idx}: {(time() - start_time)/idx}')
How it started:
How it's going:
Note: the speed in the screen shots shows the AVG time it takes to make a transaction and does not mean actual TPS speed
I am genuinely curious about why transaction creation slows down over time and would greatly appreciate any insights or solutions.
Environment information
brownie
Version: 1.19.3ganache-cli
Version: not usingWhat was wrong?
I use Brownie to create and execute transactions on a custom Anvil fork. Note that I am not using Brownie's development network cmd to run this fork; instead, I have forked the network separately and added the network using
brownie networks add
but generally, this case is also valid for other forking methods that I have tried such as ganache.As I create more transactions, I've observed that the speed of transaction creation gradually decreases. After running my script for a while, hardware resource usage (CPU, RAM, Disk) significantly increases, and the CPU hits 100% usage (one entire core). This leads me to suspect that Brownie might have a bottleneck.
To Reproduce:
anvil --base-fee 0 --fork-url <YOUR_FORK_URL> --port 42069 --auto-impersonate --compute-units-per-second 8000 --no-rate-limit
)brownie networks add Polygon anvil_polygon_mainnet_fork host='http://127.0.0.1:42069' chainid=137
)brownie run scripts/bulktx.py --network anvil_polygon_mainnet_fork
)Expected Behavior:
The transaction creation speed should remain consistent regardless of the number of transactions created without significant hardware resource increase.
Actual Behavior:
The transaction creation speed decreases over time, and hardware usage significantly increases, eventually hitting 100% CPU usage.
BulkTx script:
How it started: How it's going:
Note: the speed in the screen shots shows the AVG time it takes to make a transaction and does not mean actual TPS speed
I am genuinely curious about why transaction creation slows down over time and would greatly appreciate any insights or solutions.
I appreciate your help!