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

Optimize memory use for blockindex #682

Merged
merged 2 commits into from
May 23, 2020

Conversation

aguycalled
Copy link
Member

@aguycalled aguycalled commented May 22, 2020

This pull request optimizes the memory storage of the block indexes.

Block indexes store for every block the block header and some information needed for the chain validation. They are permanently kept in memory to speed up the validation process. Part of this extra data are the votes of the community fund/dao. Even if the votes of a block were empty, they were still using some memory space. This means even the first blocks of the chain (when no community fund was active) were taking memory space as if they had votes. This effect has been exaggerated with the introduction of the dao upgrade.

After the patch, a different set of data structures are used. Only blocks which include votes of a particular type attach data to those structures, hence reducing considerably the memory use. Other unused fields like prevoutStake and nStakeTime are also removed from memory.

What to test:

  • memory use is effectively reduced when using this branch
  • stressor tests run succesfully
  • chain sync tests

@mxaddict
Copy link
Contributor

mxaddict commented May 22, 2020

Took a while to read the Diff, but changes seem to make sense, will do a build and some tests on mainnet.

  • sync from genesis
  • sync from genesis (restart in the middle)
  • run the stress test a few times
  • Check that this PR uses less memory

@mxaddict
Copy link
Contributor

Btw @aguycalled I saw some lines modified that only changed the whitespace, might make sense to add a linter of some sort to enforce some rules on whitespace, indentation and formatting.

@navbuilder
Copy link

A new build of 67a7a79 has completed succesfully!
Binaries available at https://build.nav.community/binaries/optimize-blockindex-memory

@navbuilder
Copy link

A new build of f4177a6 has completed succesfully!
Binaries available at https://build.nav.community/binaries/optimize-blockindex-memory

@mxaddict
Copy link
Contributor

Old master build was running 1.75GB RAM on my navcoind node, this branch is using about 1.5GB
So it's a nice ~200MB decrease.

@mxaddict
Copy link
Contributor

Ran the stress script 2 times for ~400 blocks each time, worked fine with this branch.

Copy link
Contributor

@chasingkirkjufell chasingkirkjufell left a comment

Choose a reason for hiding this comment

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

Ubuntu 18.04 local build qt wallet reduced from 2.6 GB memory to 2.4 GB
Windows 10 Gitian build qt wallet reduced from 2.5 GB to 1.96 GB
Tested Syncing mainnet with all index with no problem

@aguycalled aguycalled merged commit 99e27d6 into navcoin:master May 23, 2020
@aguycalled aguycalled deleted the optimize-blockindex-memory branch May 23, 2020 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants