Skip to content

Conversation

@congoamz
Copy link
Contributor

@congoamz congoamz commented Mar 6, 2023

Add functionality to use internal connection pools to establish connections. The motivation for using pools comes from the read-write plugin's need to regularly establish new connections. Using pools will increase performance and decrease demands on the database by allowing connections to be re-used.

Additional Reviewers

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@Override
public Connection connect(
@NonNull String url, @NonNull Properties props) throws SQLException {
// TODO: Is this method ever called? It seems to only be referenced by tests/benchmarks. If
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, it don't recall it's ever used. Might consider to deprecate it.

JdbcCallable<Connection, SQLException> connectFunc) throws SQLException {
final Connection conn = connectFunc.call();

if (conn != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

That may need additional checks to avoid generating keys for connections that already have keys and come from connection pool. It's not part of POC certainly.

aaron-congo and others added 10 commits March 30, 2023 12:12
…ols (#27)

- updated HikariPooledConnectionProvider to use jdbcUrl instead of dataSourceClassName
- fixed issue in StaleDnsHelper where the URL was included in the comparison between cluster and instance DNS. Only the IP address should be compared
- fixed some incorrect test code in ReadWriteSplittingTests
- disabled flaky test in ReadWriteSplittingTests. The HostListProvider should be improved to verify the initial host spec role before re-enabling it
- added test for failover failure (no instances available)
- added test for failover while in a transaction

### Internal connection pooling

Whenever `setReadOnly(true)` is first called on a `Connection` object, the read-write plugin will internally open a new physical connection to a reader. After this first call, the physical reader connection will be cached for the given `Connection`. Future calls to `setReadOnly `on the same `Connection` object will not require opening a new physical connection. However, calling `setReadOnly(true)` for the first time on a new `Connection` object will require the plugin to establish another new physical connection to a reader. If your application frequently establishes new read-only connections, you can enable internal connection pooling to improve performance. When enabled, the wrapper driver will maintain an internal connection pool for each instance in the cluster. This allows the read-write plugin to reuse reader connections that were established by previous `Connection` objects.
Copy link
Contributor

Choose a reason for hiding this comment

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

However, calling setReadOnly(true) for the first time on a new Connection object will require the plugin to establish another new physical connection to a reader.

Seems to just repeat the information above.

@congoamz congoamz changed the title [WIP] Internal connection pool POC Implement internal connection pools for the read-write plugin Apr 22, 2023
@congoamz congoamz merged commit fb55ede into aws:main Apr 27, 2023
@aaron-congo aaron-congo deleted the pool-poc branch April 27, 2023 22:54
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.

5 participants