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

tapdb: allow batch inserting proofs when syncing universe, remove write lock for RegisterIssuance #449

Merged
merged 13 commits into from
Sep 7, 2023

Conversation

guggero
Copy link
Member

@guggero guggero commented Aug 11, 2023

Fixes #374.

Opening as draft, want to address the following TODOs before full review:

  • Code cleanup
  • Unit tests for batch inserts
  • Allow federation envoy to also support batch inserting, will speed up local insertion

@guggero guggero force-pushed the remove-mint-lock branch 2 times, most recently from 91848b3 to a7d03b6 Compare August 14, 2023 13:55
tapdb/interfaces.go Show resolved Hide resolved
tapdb/interfaces.go Show resolved Hide resolved
tapdb/interfaces.go Outdated Show resolved Hide resolved
tapdb/universe.go Show resolved Hide resolved
universe/base.go Outdated Show resolved Hide resolved
universe/base.go Outdated Show resolved Hide resolved
universe/interface.go Show resolved Hide resolved
universe/syncer.go Outdated Show resolved Hide resolved
tapgarden/caretaker.go Outdated Show resolved Hide resolved
tapgarden/caretaker.go Outdated Show resolved Hide resolved
@guggero
Copy link
Member Author

guggero commented Aug 18, 2023

I was able to complete a full asset mint with 10k assets with Postgres on my local machine today 💯

Here are some statistics of the run:

Total time elapsed:			5,516s (1h 32m)
Creating 10k seedlings:			21s
Confirming batch:			84s (1m 24s)
Inserting 10k proof (local universe):	2,031s

<start second node>
Creating leaf diff:			300ms
Fetching 10k leaves:			2s
Inserting 10k leaves (syncer):		3,337s (55m)

EDIT: After a few optimizations, I was able to get a full run in 4541s. Attaching the log if anyone is curious:
10k-itest.log

@guggero guggero force-pushed the remove-mint-lock branch 2 times, most recently from e308cdc to 711414b Compare August 18, 2023 13:04
@guggero guggero marked this pull request as ready for review August 18, 2023 13:37
@guggero
Copy link
Member Author

guggero commented Aug 18, 2023

Still want to add some additional unit tests to the database around batched insertion, but the PR should otherwise be ready for re-review.

tapdb/multiverse.go Show resolved Hide resolved
universe/syncer.go Outdated Show resolved Hide resolved
tapgarden/caretaker.go Outdated Show resolved Hide resolved
tapgarden/caretaker.go Outdated Show resolved Hide resolved
tapgarden/caretaker.go Show resolved Hide resolved
universe/syncer.go Outdated Show resolved Hide resolved
universe/interface.go Show resolved Hide resolved
Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

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

Didn't yet bench locally but this was a great read! Cool to see fn used to great effect.

Confirmed no regression with SQLite at batch size 1k. Left most of my comments on existing threads.

make/testing_flags.mk Show resolved Hide resolved
universe/base.go Show resolved Hide resolved
@Roasbeef
Copy link
Member

Needs a rebase!

Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

When syncing proofs from a remote universe, we download the proofs in
parallel. But to avoid also hammering the DB with parallel write
requests, we batch the writes.
We also want to insert proofs in batches into the local universe when we
mint multiple assets.
Instead of having three make goals for the optional itests, we use an
argument (make itest optional=true), which also makes it easier for us
to increase test and postgres harness timeouts during those optional
tests.
It seems like Ubuntu 22.04 (current latest) terminates build jobs
because of high CPU usage sometimes (see
actions/runner-images#6680).

We attempt to fix this by using the older runner.
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🐙


// We use an error group to simply the error handling of a goroutine.
batchSyncEG.Go(func() error {
newLeafProofs, err = s.batchStreamNewItems(
Copy link
Member

Choose a reason for hiding this comment

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

Very cool pattern! I think we might need just one more light layer of abstraction to make it a bit more readable, but I dig the structured concurrency here.

@Roasbeef Roasbeef merged commit c20fdd5 into main Sep 7, 2023
@guggero guggero deleted the remove-mint-lock branch September 7, 2023 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
4 participants