Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in Anvil for high transaction volume #7940

Closed
1 of 2 tasks
AnieeG opened this issue May 17, 2024 · 3 comments
Closed
1 of 2 tasks

Memory leak in Anvil for high transaction volume #7940

AnieeG opened this issue May 17, 2024 · 3 comments
Labels
T-bug Type: bug

Comments

@AnieeG
Copy link

AnieeG commented May 17, 2024

Component

Anvil

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (503792a 2024-05-10T11:26:11.682258969Z)

What command(s) is the bug in?

anvil --chain-id 1337 --block-time 2 --gas-limit 400000000000000 --code-size-limit 30000 --base-fee 100000 --host 0.0.0.0 --port 8545 --accounts 20 --balance 2000000000000000000 --state /state/dump.json --state-interval 60 --transaction-block-keeper 500

Operating System

Linux

Describe the bug

While running Anvil as part of a load scenario, the memory usage of Anvil nodes increases very quickly. The load scenario generates one transaction every 5 seconds, and the blocktime of Anvil is set to 1 second. Within 30 minutes, the memory usage surges to 6 GiB. Using the --prune-history option effectively manages the memory usage, but it results in a BlockOutOfRangeError (BlockOutOfRangeError: block height is 501 but requested was 500) when querying deployed contracts.

Is there a workaround for this issue? Can Anvil be used for high load testing scenarios?

@AnieeG AnieeG added the T-bug Type: bug label May 17, 2024
@grandizzy
Copy link
Collaborator

@AnieeG I don't see any mem leak using anvil 0.2.0 (260ad350c0 2024-05-27T10:56:35.953226014Z), the test I did was to run anvil

anvil --chain-id 1337 --block-time 1 --gas-limit 400000000000000 --code-size-limit 30000 --base-fee 100000 --host 0.0.0.0 --port 8545 --accounts 20 --balance 2000000000000000000 --state dump.json --state-interval 60 --transaction-block-keeper 500

and deploy Counter contract in a loop

while true; do forge create --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 src/Counter.sol:Counter; done

After 30 mins the resident memory reached 705M

image

then OS started to release it as expected, going down to 693M

image

Please retest with latest anvil and provide more details on how to reproduce if mem not released.

@AnieeG
Copy link
Author

AnieeG commented May 28, 2024

I have rerun this on latest tagged foundry version - forge 0.2.0 (0a5b22f 2024-05-21T10:30:02.156279959Z)
command used -

anvil --chain-id 90000034 --block-time 1 --gas-limit 400000000000000 --code-size-limit 30000 --base-fee 100000 --host 0.0.0.0 --port 8545 --accounts 20 --balance 2000000000000000000 --state /state/dump.json --state-interval 60 --transaction-block-keeper 500

Within 17m I see the usage is around 1.4GB
image

After 22m it shoots up to 2.0GB
image

But after 44m or so I see the usage has again gone down 808M
image

Thanks for fixing this!!

@grandizzy
Copy link
Collaborator

thanks, going to close per comment above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
None yet
Development

No branches or pull requests

2 participants