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 rest account balance query #2060

Merged
merged 1 commit into from
Jun 2, 2021
Merged

Conversation

xin-hedera
Copy link
Collaborator

Detailed description:
This PR optimizes the account balance (both hbar and token balances) db query:

  1. Rewrite the query to avoid unnecessary entity table sequential scan
  2. Add index on entity (id, type)

Which issue(s) this PR fixes:
Fixes #2020

Special notes for your reviewer:
Performance comparison on hot data in perfnet:

$ time curl -s localhost:12000/api/v1/accounts/1336  > /dev/null

real  0m0.616s
user  0m0.006s
sys 0m0.006s

$ time curl -s localhost:6551/api/v1/accounts/1336  > /dev/null

real  0m2.635s
user  0m0.013s
sys 0m0.000s

Note the account has 3051 token balances.

Checklist

  • Documentation added
  • Tests updated

Signed-off-by: Xin Li <xin.li@hedera.com>
@xin-hedera xin-hedera added bug Type: Something isn't working P1 rest Area: REST API database Area: Database labels Jun 1, 2021
@xin-hedera xin-hedera added this to the Mirror 0.35.0 milestone Jun 1, 2021
@xin-hedera xin-hedera requested a review from a team June 1, 2021 20:30
@xin-hedera xin-hedera self-assigned this Jun 1, 2021
@codecov
Copy link

codecov bot commented Jun 1, 2021

Codecov Report

Merging #2060 (224bbac) into master (126751e) will decrease coverage by 7.58%.
The diff coverage is 87.92%.

❗ Current head 224bbac differs from pull request most recent head 5fc06c9. Consider uploading reports for the commit 5fc06c9 to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2060      +/-   ##
============================================
- Coverage     87.05%   79.46%   -7.59%     
- Complexity     1744     1919     +175     
============================================
  Files           315      377      +62     
  Lines          7731     9301    +1570     
  Branches        740      879     +139     
============================================
+ Hits           6730     7391     +661     
- Misses          772     1648     +876     
- Partials        229      262      +33     
Impacted Files Coverage Δ
...ensus/ConsensusCreateTopicTransactionSupplier.java 0.00% <ø> (ø)
...sus/ConsensusSubmitMessageTransactionSupplier.java 0.00% <0.00%> (ø)
...ensus/ConsensusUpdateTopicTransactionSupplier.java 0.00% <ø> (ø)
...er/schedule/ScheduleCreateTransactionSupplier.java 0.00% <ø> (ø)
...supplier/token/TokenCreateTransactionSupplier.java 0.00% <ø> (ø)
...supplier/token/TokenUpdateTransactionSupplier.java 0.00% <ø> (ø)
...ra/mirror/monitor/config/MonitorConfiguration.java 0.00% <0.00%> (ø)
...edera/mirror/monitor/publish/PublishException.java 0.00% <0.00%> (ø)
.../hedera/mirror/monitor/publish/PublishMetrics.java 0.00% <0.00%> (ø)
...a/mirror/monitor/publish/TransactionPublisher.java 1.09% <0.00%> (-0.04%) ⬇️
... and 180 more

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 1704d28...5fc06c9. Read the comment docs.

@sonarcloud
Copy link

sonarcloud bot commented Jun 1, 2021

Copy link
Contributor

@ijungmann ijungmann left a comment

Choose a reason for hiding this comment

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

LGTM, I like some of the cleanup you've done as well.

Copy link
Member

@steven-sheehy steven-sheehy left a comment

Choose a reason for hiding this comment

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

LGTM

@xin-hedera xin-hedera merged commit a1d02e1 into master Jun 2, 2021
@xin-hedera xin-hedera deleted the slow-account-balance-query branch June 2, 2021 15:06
xin-hedera added a commit that referenced this pull request Jun 2, 2021
- rewrite the query to avoid unnecessary entity table sequential scan
- add index on entity (id, type)

Signed-off-by: Xin Li <xin.li@hedera.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Something isn't working database Area: Database P1 rest Area: REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slow get single account balance and token balances query
3 participants