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

feat: ETH RPC: Use Block Cache for EthGetBlockByHash #12359

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

aarshkshah1992
Copy link
Contributor

Closes #10520.

Part of #12293.

Verified

This commit was signed with the committer’s verified signature.
MadVikingGod Aaron Clawson

Verified

This commit was signed with the committer’s verified signature.
MadVikingGod Aaron Clawson
@aarshkshah1992
Copy link
Contributor Author

aarshkshah1992 commented Aug 8, 2024

Tested this on a mainnet node

With Caching enabled (fetch all txdata as well)

First request

time curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByHash","params":["0xd5742c7ead47c4224dd1e7a877532fc52fdc3094bad36b85b66661b2c2cf2401", true],"id":1}' http://localhost:1234/rpc/v1

real	0m0.060s

Second request

time curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByHash","params":["0xd5742c7ead47c4224dd1e7a877532fc52fdc3094bad36b85b66661b2c2cf2401", true],"id":1}' http://localhost:1234/rpc/v1

real	0m0.034s

Copy link
Contributor

@akaladarshi akaladarshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Just a couple of comments.

@Stebalien
Copy link
Member

Do you have any before metrics?

@aarshkshah1992
Copy link
Contributor Author

@Stebalien Lemme get them for you.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable approach.

@aarshkshah1992
Copy link
Contributor Author

aarshkshah1992 commented Aug 8, 2024

@Stebalien

Without any caching

1st fetch

time curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByHash","params":["0xd5742c7ead47c4224dd1e7a877532fc52fdc3094bad36b85b66661b2c2cf2401", true],"id":1}' http://localhost:1234/rpc/v1

real	0m0.073s

2nd fetch


time curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByHash","params":["0xd5742c7ead47c4224dd1e7a877532fc52fdc3094bad36b85b66661b2c2cf2401", true],"id":1}' http://localhost:1234/rpc/v1
real	0m0.065s

Caching definitely helps here. Keep in mind that this is a snapshot synced node with splitstore pruning enabled. Difference should be even more pronounced on an archival node with no splitstore.

Verified

This commit was signed with the committer’s verified signature.
MadVikingGod Aaron Clawson
@Stebalien
Copy link
Member

2x savings actually aren't that large here... I wonder if that's just because the network is quiet right now.

On the other hand, the cache is pretty small so it probably isn't harmful.

Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine but I am a little concerned about the large memory footprint of lotus just getting bigger, turn on the eth API and you have yet another blob in memory. Although thankfully it only grows if you use it.
I'm not sure exactly how much these take up but the JSON output of one of your example blocks is over 500Kb, so maybe they end up being something like 200Kb in memory, so perhaps 100Mb here when we cache 500 of them.

@aarshkshah1992 aarshkshah1992 merged commit d289074 into master Aug 9, 2024
84 checks passed
@aarshkshah1992 aarshkshah1992 deleted the feat/eth-api-blk-tx-cache branch August 9, 2024 05:56
@rjan90 rjan90 mentioned this pull request Aug 31, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ☑️ Done (Archive)
Development

Successfully merging this pull request may close these issues.

Add Eth API Block Cache
4 participants