-
Notifications
You must be signed in to change notification settings - Fork 69
docs: internal connection pool for Spring apps #869
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
Conversation
docs/using-the-jdbc-driver/using-plugins/UsingTheReadWriteSplittingPlugin.md
Outdated
Show resolved
Hide resolved
|
||
When a method with this annotation is hit, Spring calls conn.setReadOnly(true), executes the method, and then calls setReadOnly(false) to restore the connection's initial readOnly value. Consequently, every time the method is called, the plugin switches to the reader, executes the method, and then switches back to the writer. Although the reader connection will be cached after the first setReadOnly call, there is still some overhead when switching between the cached writer/reader connections. This constant switching is not an ideal use of the plugin because it is frequently incurring this overhead. The suggested approach for this scenario is to avoid loading the read/write splitting plugin and instead use the writer cluster URL for your write operations and the reader cluster URL for your read operations. By doing this you avoid the overhead of constantly switching between connections while still spreading load across the database instances in your cluster. | ||
|
||
#### Internal connection pools | ||
|
||
We recommend that you do not enable internal connection pools when using Spring. This is because Spring by default uses its own external connection pool. The use of both internal and external pools is not tested and may result in problematic behavior. | ||
We recommend that you do not enable internal connection pools when using Spring with default datasource configuration. This is because Spring by default uses its own external connection pool. The use of both internal and external pools is not tested and may result in problematic behavior. A Spring application should enable internal connection pool only. That's a recommended configuration. |
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.
Should we add a link for default deatasource configuration
? Not exactly sure what the default configuration is
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 rewrote this part. I hope it's a bit cleaner now.
|
||
When a method with this annotation is hit, Spring calls conn.setReadOnly(true), executes the method, and then calls setReadOnly(false) to restore the connection's initial readOnly value. Consequently, every time the method is called, the plugin switches to the reader, executes the method, and then switches back to the writer. Although the reader connection will be cached after the first setReadOnly call, there is still some overhead when switching between the cached writer/reader connections. This constant switching is not an ideal use of the plugin because it is frequently incurring this overhead. The suggested approach for this scenario is to avoid loading the read/write splitting plugin and instead use the writer cluster URL for your write operations and the reader cluster URL for your read operations. By doing this you avoid the overhead of constantly switching between connections while still spreading load across the database instances in your cluster. | ||
|
||
#### Internal connection pools | ||
|
||
We recommend that you do not enable internal connection pools when using Spring. This is because Spring by default uses its own external connection pool. The use of both internal and external pools is not tested and may result in problematic behavior. | ||
We recommend that you do not enable internal connection pools when using Spring with default datasource configuration. This is because Spring by default uses its own external connection pool. The use of both internal and external pools is not tested and may result in problematic behavior. A Spring application should enable internal connection pool only. That's a recommended configuration. |
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.
We recommend that you do not enable internal connection pools when using Spring with default datasource configuration. This is because Spring by default uses its own external connection pool. The use of both internal and external pools is not tested and may result in problematic behavior. A Spring application should enable internal connection pool only. That's a recommended configuration. | |
We recommend that you **disable** internal connection pools when using Spring with default datasource configuration. Spring by default uses its own external connection pool. The use of both internal and external pools has not been tested and may result in problematic behaviour. A Spring application should enable internal connection pool only. That's a recommended configuration. |
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 don't understand the last sentence. A Spring application should enable internal connection pool only. That's a recommended configuration.
but the first sentence said to not use internal connection pool when using Spring with default datasource configuration.
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 rewrote this part. I hope it's a bit cleaner now.
docs/using-the-jdbc-driver/using-plugins/UsingTheReadWriteSplittingPlugin.md
Outdated
Show resolved
Hide resolved
## Example | ||
[ReadWriteSplittingPostgresExample.java](../../../examples/AWSDriverExample/src/main/java/software/amazon/ReadWriteSplittingPostgresExample.java) demonstrates how to enable and configure read/write splitting with the Aws Advanced JDBC Driver. | ||
|
||
[SpringHibernateBalancedReaderOneDataSourceExample](../../../examples/SpringHibernateBalancedReaderOneDataSourceExample/README.md) demonstrates how to enable and configure read/write splitting with the Aws Advanced JDBC Driver. This example application uses a configuration with internal connection pool and provides a load-balanced reader connection according to a specified reader selection strategy. `Read/Write Splitting Plugin` and `@Transactional(readOnly = True)` play in collaboration in this example. |
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.
[SpringHibernateBalancedReaderOneDataSourceExample](../../../examples/SpringHibernateBalancedReaderOneDataSourceExample/README.md) demonstrates how to enable and configure read/write splitting with the Aws Advanced JDBC Driver. This example application uses a configuration with internal connection pool and provides a load-balanced reader connection according to a specified reader selection strategy. `Read/Write Splitting Plugin` and `@Transactional(readOnly = True)` play in collaboration in this example. | |
[SpringHibernateBalancedReaderOneDataSourceExample](../../../examples/SpringHibernateBalancedReaderOneDataSourceExample/README.md) demonstrates how to enable and configure Read/Write Splitting plugin with the AWS JDBC Driver. This example application uses a configuration with internal connection pool and provides a load-balanced reader connection according to a specified reader selection strategy. `Read/Write Splitting Plugin` and `@Transactional(readOnly = True)` play in collaboration in this example. |
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.
Adding on top of Karen's suggestion:
[SpringHibernateBalancedReaderOneDataSourceExample](../../../examples/SpringHibernateBalancedReaderOneDataSourceExample/README.md) demonstrates how to enable and configure read/write splitting with the Aws Advanced JDBC Driver. This example application uses a configuration with internal connection pool and provides a load-balanced reader connection according to a specified reader selection strategy. `Read/Write Splitting Plugin` and `@Transactional(readOnly = True)` play in collaboration in this example. | |
[SpringHibernateBalancedReaderOneDataSourceExample](../../../examples/SpringHibernateBalancedReaderOneDataSourceExample/README.md) demonstrates how to enable and configure the Read/Write Splitting plugin with the AWS JDBC Driver. This example application uses a configuration with internal connection pooling and provides a load-balanced reader connection according to a specified reader selection strategy. The `Read/Write Splitting Plugin` and `@Transactional(readOnly = True)` annotation are both used in this example. |
I'm not entirely sure what the last sentence means, does this sound right?
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've changed this sentence. Please take a look.
docs/using-the-jdbc-driver/using-plugins/UsingTheReadWriteSplittingPlugin.md
Outdated
Show resolved
Hide resolved
docs/using-the-jdbc-driver/using-plugins/UsingTheReadWriteSplittingPlugin.md
Outdated
Show resolved
Hide resolved
## Example | ||
[ReadWriteSplittingPostgresExample.java](../../../examples/AWSDriverExample/src/main/java/software/amazon/ReadWriteSplittingPostgresExample.java) demonstrates how to enable and configure read/write splitting with the Aws Advanced JDBC Driver. | ||
|
||
[SpringHibernateBalancedReaderOneDataSourceExample](../../../examples/SpringHibernateBalancedReaderOneDataSourceExample/README.md) demonstrates how to enable and configure read/write splitting with the Aws Advanced JDBC Driver. This example application uses a configuration with internal connection pool and provides a load-balanced reader connection according to a specified reader selection strategy. `Read/Write Splitting Plugin` and `@Transactional(readOnly = True)` play in collaboration in this example. |
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.
Adding on top of Karen's suggestion:
[SpringHibernateBalancedReaderOneDataSourceExample](../../../examples/SpringHibernateBalancedReaderOneDataSourceExample/README.md) demonstrates how to enable and configure read/write splitting with the Aws Advanced JDBC Driver. This example application uses a configuration with internal connection pool and provides a load-balanced reader connection according to a specified reader selection strategy. `Read/Write Splitting Plugin` and `@Transactional(readOnly = True)` play in collaboration in this example. | |
[SpringHibernateBalancedReaderOneDataSourceExample](../../../examples/SpringHibernateBalancedReaderOneDataSourceExample/README.md) demonstrates how to enable and configure the Read/Write Splitting plugin with the AWS JDBC Driver. This example application uses a configuration with internal connection pooling and provides a load-balanced reader connection according to a specified reader selection strategy. The `Read/Write Splitting Plugin` and `@Transactional(readOnly = True)` annotation are both used in this example. |
I'm not entirely sure what the last sentence means, does this sound right?
docs/using-the-jdbc-driver/using-plugins/UsingTheReadWriteSplittingPlugin.md
Outdated
Show resolved
Hide resolved
|
||
When a method with this annotation is hit, Spring calls conn.setReadOnly(true), executes the method, and then calls setReadOnly(false) to restore the connection's initial readOnly value. Consequently, every time the method is called, the plugin switches to the reader, executes the method, and then switches back to the writer. Although the reader connection will be cached after the first setReadOnly call, there is still some overhead when switching between the cached writer/reader connections. This constant switching is not an ideal use of the plugin because it is frequently incurring this overhead. The suggested approach for this scenario is to avoid loading the read/write splitting plugin and instead use the writer cluster URL for your write operations and the reader cluster URL for your read operations. By doing this you avoid the overhead of constantly switching between connections while still spreading load across the database instances in your cluster. | ||
|
||
#### Internal connection pools | ||
|
||
We recommend that you do not enable internal connection pools when using Spring. This is because Spring by default uses its own external connection pool. The use of both internal and external pools is not tested and may result in problematic behavior. | ||
We recommend that you explicitly disable internal connection pools when using Spring. You can check `spring.datasource.type` property to ensure that an external connection pooling is disabled. By default, Spring uses datasource auto-detection, and it may enable external connection pool. The use of both internal and external pools has not been tested and may result in problematic behaviour. A Spring application should enable internal connection pool only. That's a recommended configuration. |
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.
Does this paragraph mean that internal connection pooling isn't recommended to use, but if they are used, users should disable Spring's external connection pooling? And that both internal and external connection pooling shouldn't be used together? If that's the case, how does this sound:
We recommend that you explicitly disable internal connection pools when using Spring. You can check `spring.datasource.type` property to ensure that an external connection pooling is disabled. By default, Spring uses datasource auto-detection, and it may enable external connection pool. The use of both internal and external pools has not been tested and may result in problematic behaviour. A Spring application should enable internal connection pool only. That's a recommended configuration. | |
We recommend that you explicitly disable internal connection pools when using Spring. However, if you do use the driver's internal connection pooling, you can check the `spring.datasource.type` property to ensure that any external connection pooling is disabled. This is necessary because Spring uses datasource auto-detection by default, and it may enable external connection pooling. Using internal and external pools at the same time has not been tested and may result in problematic behaviour. The recommended configuration for a Spring application should either enable internal connection pooling or external connection pooling, but not both at once. |
docs/using-the-jdbc-driver/using-plugins/UsingTheReadWriteSplittingPlugin.md
Outdated
Show resolved
Hide resolved
docs/using-the-jdbc-driver/using-plugins/UsingTheReadWriteSplittingPlugin.md
Outdated
Show resolved
Hide resolved
docs/using-the-jdbc-driver/using-plugins/UsingTheReadWriteSplittingPlugin.md
Outdated
Show resolved
Hide resolved
Co-authored-by: crystall-bitquill <[email protected]>
…ttingPlugin.md Co-authored-by: crystall-bitquill <[email protected]>
…ttingPlugin.md Co-authored-by: crystall-bitquill <[email protected]>
70dec97
to
34c0abe
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
Co-authored-by: crystall-bitquill <[email protected]>
Summary
docs: internal connection pool for Spring apps
Additional Reviewers
@karenc-bq
@crystall-bitquill
@aaronchung-bitquill
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.