Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Optimize insert path in the DB by avoiding ON CONFLICT #1090

Merged
merged 1 commit into from
Feb 1, 2022

Conversation

cevian
Copy link
Contributor

@cevian cevian commented Jan 27, 2022

Turns out there is a horrible CPU perf penalty on the DB for ON CONFLICT DO NOTHING.
yet in our data, conflicts are rare. So we first try inserting without ON CONFLICT
and fall back if there is a unique constraint violation.

Unlike retriying with COPY this does not require sending the data again
and thus saves latency and bandwidth.

Description

Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.

Merge requirements

Please take into account the following non-code changes that you may need to make with your PR:

  • CHANGELOG entry for user-facing changes
  • Updated the relevant documentation

@cevian cevian requested a review from jgpruitt as a code owner January 27, 2022 22:36
@cevian cevian force-pushed the on_conflict_opt branch 2 times, most recently from c972b50 to 69bd1bf Compare January 27, 2022 22:38
@cevian cevian requested a review from a team as a code owner January 27, 2022 22:38
@cevian cevian requested review from bitwalker and removed request for a team January 27, 2022 22:38
Copy link
Contributor

@bitwalker bitwalker left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@antekresic antekresic left a comment

Choose a reason for hiding this comment

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

Looks good.

Maybe we should add a Go bench for ingesting metrics (like we have for traces) so we can see the improvement and record here for historical reasons.

We can do that in a separate PR.

@VineethReddy02 VineethReddy02 added this to the 0.8.1 milestone Feb 1, 2022
Turns out there is a horrible CPU perf penalty on the DB for ON CONFLICT DO NOTHING.
yet in our data, conflicts are rare. So we first try inserting without ON CONFLICT
and fall back if there is a unique constraint violation.

Unlike retriying with COPY this does not require sending the data again
and thus saves latency and bandwidth.
@cevian
Copy link
Contributor Author

cevian commented Feb 1, 2022

@antekresic we have some work in https://github.com/cevian/postbench but yeah adding to go benchmarks will also be good

@cevian cevian merged commit d70c89d into timescale:master Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants