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

Switch to bulk upsert #52

Merged
merged 4 commits into from
Nov 28, 2023
Merged

Switch to bulk upsert #52

merged 4 commits into from
Nov 28, 2023

Conversation

ghickman
Copy link
Contributor

@ghickman ghickman commented Nov 27, 2023

Now that we're backfilling on every run it made sense to spend a bit of time optimising the database writes so local dev wasn't quite so slow. This switches us from executing one upsert (technically an INSERT … ON CONFLICT SET in postgres) per row stored to a single upsert with N values.

Locally this takes ingestion from ~3m50 to ~1m20.

psycopg can only send 65535 parameters in one go.  Each values dict is
currently 5 items, which means we end up with 10 parameters
(name+value).  Batching at 10k rows keeps the number of parameters under
the limit.
Copy link
Contributor

@benbc benbc left a comment

Choose a reason for hiding this comment

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

Doing a proper review later post-merge.

Base automatically changed from always-be-backfillin to main November 28, 2023 12:25
@ghickman ghickman merged commit a935950 into main Nov 28, 2023
7 checks passed
@ghickman ghickman deleted the bulk-upsert branch November 28, 2023 12:25
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