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

perf(stream): optimize native pg sink #19688

Merged
merged 21 commits into from
Dec 24, 2024

Conversation

kwannoel
Copy link
Contributor

@kwannoel kwannoel commented Dec 5, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Just measure the throughput for both via grafana.

The performance improvement of unoptimized to optimized native pg sink went from 30r/s to 10K r/s.

The performance is around the same as JDBC. LHS is for native pg sink. RHS is for jdbc sink. Toggle the screenshot below.


screenshot Screenshot 2024-12-06 at 2 47 15 PM

Implementation details:

  1. We batch inserts and deletes in this PR, with up to 32768 parameters, since that's the max parameter supported by PG.
  2. We use transactions to delimit each batch.
  3. We remove updateInsert handling path, since compaction will normalizze updateInsert to Insert.
  4. We use LogSinker instead of SinkWriter to avoid redundant flushes to the log store.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

Copy link
Contributor Author

kwannoel commented Dec 5, 2024

@kwannoel kwannoel changed the title Add prepared sql to error logs + add slt bench perf(stream): optimize native pg sink Dec 5, 2024
@kwannoel kwannoel marked this pull request as ready for review December 5, 2024 07:29
@kwannoel kwannoel marked this pull request as draft December 5, 2024 07:29
@kwannoel kwannoel requested review from chenzl25 and StrikeW December 6, 2024 06:48
@kwannoel kwannoel force-pushed the 12-04-add_prepared_sql_to_error_logs_add_slt_bench branch from 47a0411 to 1d408c5 Compare December 7, 2024 10:43
@kwannoel kwannoel changed the base branch from main to 12-06-feat_common_support_switching_from_pg_jdbc_to_pg_native_sinks December 7, 2024 10:50
@kwannoel kwannoel marked this pull request as ready for review December 7, 2024 10:51
@kwannoel kwannoel force-pushed the 12-06-feat_common_support_switching_from_pg_jdbc_to_pg_native_sinks branch from e01f6d2 to 0062ecd Compare December 11, 2024 00:12
@kwannoel kwannoel requested a review from a team as a code owner December 11, 2024 00:12
@kwannoel kwannoel requested review from BugenZhao and removed request for a team December 11, 2024 00:12
@kwannoel kwannoel force-pushed the 12-04-add_prepared_sql_to_error_logs_add_slt_bench branch 2 times, most recently from a195d55 to 068fee0 Compare December 11, 2024 03:19
@kwannoel kwannoel changed the base branch from 12-06-feat_common_support_switching_from_pg_jdbc_to_pg_native_sinks to graphite-base/19688 December 12, 2024 01:30
@kwannoel kwannoel force-pushed the 12-04-add_prepared_sql_to_error_logs_add_slt_bench branch from 068fee0 to bfa8d33 Compare December 12, 2024 13:02
@kwannoel kwannoel force-pushed the graphite-base/19688 branch from e78d259 to 2e302e9 Compare December 12, 2024 13:02
@kwannoel
Copy link
Contributor Author

Bump

Copy link
Contributor

@chenzl25 chenzl25 left a comment

Choose a reason for hiding this comment

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

Rest LGTM, thanks!

Comment on lines 556 to 570
let row_parameters: String = pk_indices
.iter()
.map(|j| {
format!(
"{} = ${}",
schema.fields()[*j].name,
i * number_of_pk + j + 1
)
})
.collect_vec()
.join(" AND ");
format!("({row_parameters})")
})
.collect_vec()
.join(" AND ");
.join("OR");
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can use PK In (...) instead of PK = xxx or PK = yyy which is more compacted and easy to be recognized by the external system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improve later. Merge to let user try it. #19913

@kwannoel kwannoel force-pushed the graphite-base/19688 branch from 2e302e9 to 81f651f Compare December 24, 2024 07:00
@kwannoel kwannoel force-pushed the 12-04-add_prepared_sql_to_error_logs_add_slt_bench branch from bfa8d33 to 4c34456 Compare December 24, 2024 07:00
@kwannoel kwannoel changed the base branch from graphite-base/19688 to main December 24, 2024 07:00
@kwannoel kwannoel force-pushed the 12-04-add_prepared_sql_to_error_logs_add_slt_bench branch from 59a512d to c58d906 Compare December 24, 2024 12:24
@graphite-app graphite-app bot requested a review from a team December 24, 2024 13:19
@kwannoel kwannoel added this pull request to the merge queue Dec 24, 2024
Merged via the queue into main with commit 3bdf84d Dec 24, 2024
29 of 30 checks passed
@kwannoel kwannoel deleted the 12-04-add_prepared_sql_to_error_logs_add_slt_bench branch December 24, 2024 15:26
github-actions bot pushed a commit that referenced this pull request Dec 24, 2024
github-merge-queue bot pushed a commit that referenced this pull request Dec 28, 2024
Co-authored-by: Noel Kwan <47273164+kwannoel@users.noreply.github.com>
kwannoel added a commit that referenced this pull request Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants