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

services/horizon/txsub: Batch status check queries for pending transactions in txsub #3563

Merged
merged 13 commits into from
Jun 28, 2021

Conversation

bartekn
Copy link
Contributor

@bartekn bartekn commented Apr 22, 2021

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

This commit modifies txsub.Tick to check the status of transactions in the queue by sending a batch query instead of sending separate queries to get status of each transaction in the queue.

Close #3552.

Why

This was done due performance reasons. If the number of transactions in the queue is large this slows down entire Tick function. Data in #3552 suggest that previous method can take even 4s per Tick execution for around 1000 transactions in the queue.

Known limitations

N/A

@bartekn bartekn linked an issue Apr 22, 2021 that may be closed by this pull request
@bartekn bartekn marked this pull request as ready for review June 8, 2021 13:41
@bartekn bartekn requested a review from a team June 8, 2021 13:41
@@ -28,6 +28,25 @@ func (q *Q) TransactionByHash(ctx context.Context, dest interface{}, hash string
return q.Get(ctx, dest, union)
}

// TransactionsByHashesSinceLedger fetches transactions from the `history_transactions`
// table which match the given hash since the given ledger sequence (for perf reasons).
func (q *Q) TransactionsByHashesSinceLedger(ctx context.Context, dest interface{}, hashes []string, sinceLedgerSeq uint32) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it necessary to add the ht.ledger_sequence >= sinceLedgerSeq condition? I thought the transaction hash is globally unique?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately the query without the ledger_sequence limit is extremely slow. I realized it after to.mer tested it and added a fix in e8701ab. Technically the 100 ledgers is too much because TransactionsByHashesSinceLedger is used only when checking the status of transactions in Tick so this could be 12 (one minute of ledgers).

for _, hash := range pending {
tx, found := txMap[hash]
if !found {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

How come we can happily continue here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't it be that the transaction is in the DB but isn't found by TransactionsByHashesSinceLedger() due to the sinceLedgerSeq passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If txMap doesn't contain the hash it means that tx with hash has not been included in the ledger yet. So we continue to the next pending transaction.

@bartekn
Copy link
Contributor Author

bartekn commented Jun 24, 2021

@2opremio @tamirms thanks for the comments. I decided to put off this PR because of the issues found while testing 2.5.0 (Captive-Core persistent storage). I answered your questions and we can include this in the next release.

@bartekn bartekn merged commit 2f66142 into master Jun 28, 2021
@bartekn bartekn deleted the batch-txresults branch June 28, 2021 13:35
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.

Batch status check queries for pending transactions in txsub
4 participants