-
Notifications
You must be signed in to change notification settings - Fork 154
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
bench: benchmarking operation cost of BTCStaking module #437
Conversation
Attached the profiling result of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The benchmarking looks good to me. Generally I don't see the beginBlocker
as a bottleneck. In a case where we have 100 * 10 delegations, the time spent in beginBlocker
is only 0.25 seconds.
if err != nil { | ||
b.Fatal(err) | ||
} | ||
defer f.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the defer appear before the error handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, if there is an error then f
won't be opened and the program will exit at L76 directly. Same for the below comment
if err := pprof.StartCPUProfile(f); err != nil { | ||
b.Fatal(err) | ||
} | ||
defer pprof.StopCPUProfile() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
I remember @KonradStaniec mentioned that in Ethereum if executing a block takes more than this time then this might affect chain liveness? Also imagine if we have 100000 delegations this number becomes >2s |
It won't affect liveness. I think liveness will only be affected if block execution will take more than 12s, as one ethereum slot is 12s. I mentioned that execution of block in geth currently take 0.2s, and we are talking about chain which database have over 1tb of data, and 100s transactions per block. So having one begin block to take more than 0.25s seems worrying. |
Fixes https://babylon-chain.atlassian.net/browse/BM-1161
This PR introduces benchmark tests for the operation cost of BTC staking, more specifically its
BeginBlock
function. The benchmark test generates X finality providers, each with Y BTC delegations, then benchmarksBeginBlock
.To run the benchmark, do
go test -benchmem -run=^$ -bench=. github.com/babylonchain/babylon/x/btcstaking/keeper
.Results
The tests are run on a computer with following spec
Then we get the following results (1st variable is the number of finality providers, 2nd variable is the number of BTC delegations under each finality provider)
The conclusion is that BTC staking module has scalability issue -- with 1000 BTC delegations, the
BeginBlock
will take 0.25 second.The next step is to identify bottleneck and optimise it.