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

eth_estimateGas performance #15859

Closed
ryanschneider opened this issue Jan 11, 2018 · 6 comments
Closed

eth_estimateGas performance #15859

ryanschneider opened this issue Jan 11, 2018 · 6 comments

Comments

@ryanschneider
Copy link
Contributor

System information

Geth version: 1.8.0-unstable-56152b31 (also 1.7.3-stable-4bb3c89d)
OS & Version: Windows/Linux/OSX
Commit hash : 56152b31ac251d1cc68fcddbdad159ba5234c415

Expected behaviour

eth_estimateGas is more or less as performant as eth_call.

Actual behaviour

eth_estimateGas takes seconds or minutes to run.

Steps to reproduce the behaviour

I don't have a sure fire repro but have seen it happen if you make the call just a couple seconds after starting geth, or sometimes it takes hours before it gets into this state.

However, during testing I noticed two things:

So, as a test I switched to rpc.LatestBlockNumber in ryanschneider@7df8498, and was unable to reproduce the issue after throwing a lot of test traffic at it.

I'd love to help track down the issue, but don't have clarity into why the binary search is used. Also my current theory is that there is contention on the pending block, does that sounds like a reasonable place to look?

Backtrace

I'll get a debug.stacks output from either 1.7.3 or master here the next time I see the issue.

@karalabe
Copy link
Member

The binary search is needed due to funky gas dynamics and allowances in various EVM opcodes. For example, doing a CALL forwards 63/64 of the available gas to the called contract. Which means, even though the internal call might use N amount of gas, the opcode to be called actually requires (N/63*64). There's a similar issue with CALL stipends where a tiny amount of gas (1900) required by the opcode gets granted for free to the CALL, but won't get refunded if not used. This also makes the actual used amount and the required amount different.

Your other measurement that the pending state is slow vs. the latest block is fast is an intriguing find! I'll need to take a closer look at that.

@ryanschneider
Copy link
Contributor Author

Thanks @karalabe , for what it's worth I changed some of our nodes to run w/ this commit (ryanschneider@8c95ba4) that just patches 1.7.3 to use latest and our 95% percentile response time from eth_estimateGas went from 5 seconds to 300ms.

@ryanschneider
Copy link
Contributor Author

We need to collect more info, but we're seeing a similar level of slowness in eth_getTransactionByHash for txs that aren't mined yet, which hits the commented out part of the codepath here:

https://github.com/ryanschneider/go-ethereum/blob/dc78cb610d530765844df0833775358d737c47de/internal/ethapi/api.go#L979

So that seems to further my thinking that we're seeing some major contention on the pending transactions. Anything specific I can do to help debug?

@dovy
Copy link

dovy commented Jan 20, 2018

So maybe I'm crazy, but why not just have a running process that updates the gas price with each transaction and then when someone asks for the gas price, the stored value is just returned? I know you're all trying to do this via the blockchain, but it seems like it's not ready for that. Wouldn't this be an appropriate and effective method to mitigate this deficiency?

@ryanschneider
Copy link
Contributor Author

Your other measurement that the pending state is slow vs. the latest block is fast is an intriguing find! I'll need to take a closer look at that.

@karalabe I think I've fixed this in #16497, if you could take a look it'd be greatly appreciated!

@stale
Copy link

stale bot commented Apr 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot closed this as completed May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants