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

Use upsert statement when inserting to postgres state store #105

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

sdil
Copy link
Collaborator

@sdil sdil commented Dec 17, 2024

Summary

Warning

I'm not 100% sure if this implementation is accurate and produce the same result as previous one

When I was trying the Postgres state store, my test application was stuck after creating less than 10 actors. After figuring out the bottleneck, it seems like the DELETE statement is causing the PostgreSQL to be slow.

My initial thought is, DELETE statement is there to ensure that there's only 1 row for each actor exists in the database. Please correct me if I'm wrong.

I swapped the DELETE SQL statement to use INSERT .... ON CONFLICT SQL. Unfortunately, Squirrel does not support "ON CONFLUCT" statement correctly (refer Masterminds/squirrel#83 (comment)) so I have to use .Suffix method to manually construct the statement.

After changing this implementation, my test application was running fine creating 1,000 actors

@sdil sdil requested a review from Tochemey December 17, 2024 07:35
@sdil sdil changed the title use upsert when inserting to postgres state store Use upsert statement when inserting to postgres state store Dec 17, 2024
@Tochemey
Copy link
Owner

@sdil you are correct. The DELETE/INSERT pattern is to do what ON CONFLICT is doing. I am chocked it slows down the application. However, I do know about the suffix option of squirrel. Thanks for the PR I will take a look shortly.

Copy link
Owner

@Tochemey Tochemey left a comment

Choose a reason for hiding this comment

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

@sdil I left some few comments.

resources/durablestore_postgres.sql Outdated Show resolved Hide resolved
Co-authored-by: Arsene <[email protected]>
Signed-off-by: Mohamad Fadhil <[email protected]>
@Tochemey Tochemey merged commit c7cf58d into Tochemey:main Dec 17, 2024
1 check failed
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