-
Notifications
You must be signed in to change notification settings - Fork 48
Refactor Migration for better performance #586
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
Conversation
… Also add log output every now and then to make it more obvious that it's not stuck as it processes through stuff.
…ed from my cmoputer.
…on the migration.
…committing/running every time.
… so that they're only exposed for other unit tests.
Codecov Report
@@ Coverage Diff @@
## main #586 +/- ##
==========================================
+ Coverage 55.57% 55.63% +0.06%
==========================================
Files 149 149
Lines 19615 19665 +50
==========================================
+ Hits 10901 10941 +40
- Misses 7885 7891 +6
- Partials 829 833 +4
|
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.
LGTM. The progress logging will be very helpful and interesting.
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.
Nice use of benchmarking. LGTM.
* Overhaul the session deleting migration stuff to hopefully be faster. Also add log output every now and then to make it more obvious that it's not stuck as it processes through stuff. * Create a unit test file for timing the migration using real data loaded from my cmoputer. * Add some public functions to the migrations that expose indexing stuff for testing. * Update the big mibration test to be able to actually get timing info on the migration. * Add a more comprehensive unit test on the migration. * Tweak the numbers in the new test to cover the bad spot in the old way and more. * Get rid of the migrations_big_test test since that's way too big for committing/running every time. * Move the Index...Bad funcs into a _test.go file in the keeper package so that they're only exposed for other unit tests. * Add a comment about the purpose of the longer test and why there aren't more checks. * Add changelog entry.
Description
First, I added more log output during the migrations to make it easier to know that it's working (and not frozen).
I changed the process used to identify empty sessions.
Previously: Iterate over sessions and use the
sessionHasRecords
function (which iterates over all records in a scope until one in that session is found).Now: Iterate over records and keep track of all session ids seen. Then iterate over the sessions and keep track of the ones not previously seen.
Also, I got rid of the
map[string][][]byte
indexer and replaced it with just a map[string]struct{}. That will make it faster to look up known indexes. Thestruct{}
part isn't used; the map is only used for fast lookup. I usedstruct{}
there because of several articles indicating that maps get better performance with astruct{}
thanbool
orint
or eveninterface{}
. Thestring
keys aren't ascii friendly, but they work just fine for this purpose. You can't use a[]byte
as a map key, and conversion between[]byte
andstring
is fast.I tried to do some time comparisons between the two processes but found that the old process would run into a deadlock once a certain number of entries were involved. The deadlock was with creating a KV store for iterating over the records inside
sessionHasRecords
. Even a small test with 2 scope specs, 4 contract specs, 8 record specs, 32 scopes, 64 sessions, and 64 records would end up in a deadlock.I queried both mainnet and testnet for all metadata. Then (in a unit test not included in here) added all entries, and ran the migration. With the mainnet data, the migration ran in 20 seconds. With the testnet data, it ran in 2 minutes 33 seconds.
Some numbers:
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes