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 some db accesses #743

Merged
merged 7 commits into from
Mar 11, 2020
Merged

Optimize some db accesses #743

merged 7 commits into from
Mar 11, 2020

Conversation

roman-khimov
Copy link
Member

Problem

Slow block import.

Solution

Fix some suboptimal DB usage.

Getting references requires DB access and that is expensive.
It's a key for it, makes no sense storing it as data.
@roman-khimov roman-khimov added this to the v0.74.0 milestone Mar 11, 2020
@codecov
Copy link

codecov bot commented Mar 11, 2020

Codecov Report

Merging #743 into master will decrease coverage by 0.17%.
The diff coverage is 59.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #743      +/-   ##
==========================================
- Coverage   66.77%   66.59%   -0.18%     
==========================================
  Files         136      135       -1     
  Lines       12213    12149      -64     
==========================================
- Hits         8155     8091      -64     
- Misses       3664     3667       +3     
+ Partials      394      391       -3     
Impacted Files Coverage Δ
pkg/core/blockchain.go 45.72% <52.54%> (-0.73%) ⬇️
pkg/core/dao.go 68.68% <66.66%> (-1.56%) ⬇️
pkg/core/state/unspent_coin.go 68.18% <68.18%> (ø)
pkg/core/cacheddao.go 86.95% <69.23%> (-7.17%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e8ff55...8c902a7. Read the comment docs.

… things

This change reduces pressure on DB by doing the following things:
 * not storing additional KV pair for SpentCoin
 * storing Output right in the UnspentCoin, thus eliminating the need to get a
   full transaction from DB

At the same time it makes UnspentCoin more fat and hot, but it should probably
worth it.

Also drop `GetUnspentCoinStateOrNew` as it shouldn't ever existed, UTXOs
can't come out of nowhere.

1.5M block import time (VerifyBlocks disabled) on AMD Ryzen 5 1600/16GB/HDD,
before:
real    302m9.895s
user    96m17.200s
sys     13m37.084s

after:
real    159m16.551s
user    69m58.279s
sys     7m34.334s

So it's almost two-fold which is a great improvement.
1.5M block import time (VerifyBlocks disabled) on AMD Ryzen 5 1600/16GB/HDD,
before:
real    159m16.551s
user    69m58.279s
sys     7m34.334s

after:
real    139m41.836s
user    67m12.477s
sys     6m19.420s

12% which is even a bit more than could be expected from inputs analysis (that
has around 10% cache hits for a block-wide cache), worth doing.
@roman-khimov roman-khimov merged commit 5f1868a into master Mar 11, 2020
@roman-khimov roman-khimov deleted the optimize-some-db-accesses branch March 11, 2020 14:33
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.

2 participants