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

[Merged by Bors] - Improve performance of proposal builder by not DB inserting active set if not necessary #6422

Closed
wants to merge 7 commits into from

Conversation

fasmat
Copy link
Member

@fasmat fasmat commented Oct 29, 2024

Motivation

Closes #6418

The first proposal created by a node for any identity triggers persisting the activeset that is used by all identities of the node. This can be a slow process (especially when many ATXs are received by the node) and is usually not necessary, because the activeset is most likely already in the DB.

This PR moves persisting the active set to the beginning of an epoch and avoids a DB write if not necessary (which will usually be the case).

Description

All uses of WithTx have been renamed to WithTxImmediate (because they are). A new WithTx was added that starts a normal instead of an immediate transaction.

This transaction is used to first do a select on the available active sets in the DB and only write the used active set if it doesn't exist yet. Since most nodes use the same active set that is pre-shared this will almost never trigger an actual insert preventing the requirement to acquire a DB write lock and speed up the process.

Additionally I fixed an issue where if beginning a transaction failed (because for instance the TX was canceled already via context), the connection used was not returned to the DB pool. This fixes the flaky TestSyncer test in the malsync package and ensures this doesn't happen during normal node operation.

Test Plan

existing tests pass

TODO

  • Explain motivation or link existing issue(s)
  • Test changes and document test plan
  • Update documentation as needed
  • Update changelog as needed

@fasmat fasmat self-assigned this Oct 29, 2024
@fasmat
Copy link
Member Author

fasmat commented Oct 29, 2024

bors try

spacemesh-bors bot added a commit that referenced this pull request Oct 29, 2024
@fasmat
Copy link
Member Author

fasmat commented Oct 29, 2024

bors try

@spacemesh-bors
Copy link

try

Already running a review

@spacemesh-bors
Copy link

try

Build failed:

@fasmat
Copy link
Member Author

fasmat commented Oct 29, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Oct 29, 2024
…t if not necessary (#6422)

## Motivation

Closes #6418

The first proposal created by a node for any identity triggers persisting the activeset that is used by all identities of the node. This can be a slow process (especially when many ATXs are received by the node) and is usually not necessary, because the activeset is most likely already in the DB.

This PR moves persisting the active set to the beginning of an epoch and avoids a DB write if not necessary (which will usually be the case).
Copy link

codecov bot commented Oct 29, 2024

Codecov Report

Attention: Patch coverage is 92.18750% with 5 lines in your changes missing coverage. Please review.

Project coverage is 79.7%. Comparing base (d32ffaa) to head (2f8aa8e).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
miner/proposal_builder.go 85.7% 2 Missing and 1 partial ⚠️
sql/database.go 50.0% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #6422   +/-   ##
=======================================
  Coverage     79.7%   79.7%           
=======================================
  Files          328     328           
  Lines        42977   42984    +7     
=======================================
+ Hits         34256   34292   +36     
+ Misses        6782    6753   -29     
  Partials      1939    1939           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@spacemesh-bors
Copy link

Pull request successfully merged into develop.

Build succeeded:

@spacemesh-bors spacemesh-bors bot changed the title Improve performance of proposal builder by not DB inserting active set if not necessary [Merged by Bors] - Improve performance of proposal builder by not DB inserting active set if not necessary Oct 29, 2024
@spacemesh-bors spacemesh-bors bot closed this Oct 29, 2024
@spacemesh-bors spacemesh-bors bot deleted the 6418-do-not-insert-if-not-necessary branch October 29, 2024 18:24
spacemesh-bors bot pushed a commit that referenced this pull request Oct 30, 2024
## Motivation

Follow up to #6422: Update changlog and remove unused metric.
spacemesh-bors bot pushed a commit that referenced this pull request Oct 30, 2024
## Motivation

Follow up to #6422: Update changlog and remove unused metric.
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.

Improve performance of proposal builder
3 participants