-
Notifications
You must be signed in to change notification settings - Fork 227
JDBC: Optimize writeEntity calls #1496
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
JDBC: Optimize writeEntity calls #1496
Conversation
@singhpk234 : could you give a bit more details on the error that prompted this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number is reasonable and solid. The error rate dropped and overall response time dropped as well. Thanks @singhpk234 !
...n/java/org/apache/polaris/extension/persistence/relational/jdbc/JdbcBasePersistenceImpl.java
Outdated
Show resolved
Hide resolved
...n/java/org/apache/polaris/extension/persistence/relational/jdbc/JdbcBasePersistenceImpl.java
Outdated
Show resolved
Hide resolved
@dimas-b here is the logs for he same :
|
30ead8c
to
577211c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on handle retry in another PR.
...n/java/org/apache/polaris/extension/persistence/relational/jdbc/JdbcBasePersistenceImpl.java
Outdated
Show resolved
Hide resolved
e6a4e89
to
046233f
Compare
@@ -143,12 +138,12 @@ private void persistEntity( | |||
@Nonnull PolarisCallContext callCtx, | |||
@Nonnull PolarisBaseEntity entity, | |||
PolarisBaseEntity originalEntity, | |||
Statement statement) | |||
CheckedFunction<String, Integer> fn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need such a generic type here? Could this be updateFunction
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting making this always String, Integer ? or rename fn to updateFunction, I didn't made the name explicit updateFunction as we do both insert and update :P all DMLs. is kind of done statement.exceuteUpdate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I didn't realize it's used for the different functions in Statement
. Fundamentally I guess it's something like:
public class QueryAction {
/** Returns the number of affected rows */
public int apply(String statement);
}
But using a @FunctionalInterface makes sense. For the name, maybe we can just call it as queryConsumer
or queryAction
or something to make it clear
@FunctionalInterface | ||
interface CheckedFunction<T, R> { | ||
R apply(T t) throws SQLException; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I don't think it improves the code. It feels like a case of overengineering. Personally, I still prefer the if/else
approach, it's simple, clear, and gets the job done. I'm okay with this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like T is always String and R is always int?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to @eric-maynard ' comment. Also, this interface can probably be an inner class in JdbcBasePersistenceImpl
... it is not meant for sharing, is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted this functional interface to be used across, in case such more use case comes hence i kept generics and moved its to its own class, if we want to address this for this particular use case then defining it within the JdbcBasePersistenceImpl
makes sense and removing generic also make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracting the calls out of transaction
(in the description) sounds confusing to me. As far as I can tell all DML in Postgres runs in a transaction. This PR merely changes the method of executing that transaction over the JDBC API.
@FunctionalInterface | ||
interface CheckedFunction<T, R> { | ||
R apply(T t) throws SQLException; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to @eric-maynard ' comment. Also, this interface can probably be an inner class in JdbcBasePersistenceImpl
... it is not meant for sharing, is it?
4f6b1cc
to
4f105bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, much simpler now
4f105bd
to
3e4ec1f
Compare
@singhpk234 : could you re-run the perf. tests on the final state of this PR and re-compare with |
About the change
Optimize writeEntity calls by extracting the calls out of transaction. please ref to benchmarks below for the motivation for the change.
Note : Handling transaction failures and retries are not in the scope of this pr. This is purely for optimization purpose.
Running Branchmark :
started the jdbc implementation backed Service : https://github.com/apache/polaris/pull/1470/files#diff-44e2226f0bc5712cf1cd511efd94242a08c9760b947809c7ebe76f121f480c76
Updated creds via
go to benchmark tools and run the following benchmarks :
withRunInTransaction
without runInTransaction