Spring Boot application with HikariCP and PgPool-II - spring

I need to configure a failover cluster for Postgres. I want to use PgPool-II as failover for the failed instance of DB.
My application runs on Spring Boot 2 and uses HikariCP as datasource. HikariCP is a connection pool by itself, and PgPool uses its connection pool.
HikariCP allocate connection pool from PgPool, which gives connections from it's own pool. I understand that PgPool pool size must be greater than Hikari pool.
Can they work together? And is this a good practice to use both of them in conjuction?

Related

AWS RDS Connection and spring boot, JPA

I connect my DB (AWS RDS) to Spring boot JPA, Then my number of connections increases dramatically.
it is 12 now, I think it works spring boot 5 + browser 5, workbench 1 +, and others?
How can I reduce my number of connections? How can I maintain this connection safely?
You should be looking for Database connection pooling.
Database connection pooling is a method used to keep database connections open so they can be reused and also it will be keeping the total number of connections within a limit that we are specifying.
The default connection pool in Spring Boot is HikariCP, all you have to do is configure it properly
Sample connection pool configuration,
spring.datasource.hikari.connection-timeout = 20000
spring.datasource.hikari.minimum-idle= 10
spring.datasource.hikari.maximum-pool-size= 10
spring.datasource.hikari.idle-timeout=10000
spring.datasource.hikari.max-lifetime= 1000
spring.datasource.hikari.auto-commit =true

How to configure Couchbase connection pool

I want to configure my connection pool size for Spring Boot Couchbase application, but I can't find any property in order to set it.
A colleague suggested to use (in order to configure queryservice pool)
spring.couchbase.env.endpoints.queryservice.min-endpoints=1
spring.couchbase.env.endpoints.queryservice.max-endpoints=5
but when i do a netstat it doesn't work. i have 1 socket per node.
I am using spring boot.

SpringBoot and HikariCP relationship

SpringBoot already is managing dataConnection then why is Hikari CP needed?
I have just started using SpringBoot so do not know much about SpringBoot and Hikari relation, although i read about Hikari but couldn't find any explicit explanation about its relationship with Springboot in presence of Spring data connection.
I read that Hikari is used when we need heavy db operations with lots of connections, if it is true then should we not use Hikari in follwoing scenario?
Scenario:
There is a small application, having maximum 8-10 REST calls once in a month or maximum fortnightly.That application needs to perform some probability and statistics related calculation.
Users login on that app at a time are of maximum 2-3 in numbers.
Do we still need to use Hikari?
There are two ways to communicate with the database from your application. You can either open a new DB connection any time you wish execute some query there, or you have a connection pool. Connection pool is a collection of reusable connections that application uses for DB communication. As establishing a new connection is relatively expensive operation, using connection pool gives you a significant performance improvement.
HikariCP is one of the connection pools libraries available in java and SpringBoot uses it as a default. As you don't need to do anything special to have it in your application, just enjoy your free lunch :)
HikariCP is used as the default connection pool in SpringBoot2, it was TomcatJDBC in SpringBoot 1. You must be using it as a default in your settings. You can overwrite it by setting another connection pool in your setting properties if you need. Please find more details about the connection pools and the default configurations of Spring Boot versions here.
Hikari is the default DataSource implementation with Spring Boot 2. This means we need not add explicit dependency in the pom.xml. The spring-boot-starter-JDBC and spring-boot-starter-data-JPA resolve it by default. To sum up, you require no other steps with Spring Boot 2.
Compared to other implementations, it promises to be lightweight and better performing.
Tuning Hikari Configuration Parameters:
spring.datasource.hikari.connection-timeout = 20000 #maximum number
of milliseconds that a client will wait for a connection
spring.datasource.hikari.minimum-idle= 10 #minimum number of idle
connections maintained by HikariCP in a connection pool
spring.datasource.hikari.maximum-pool-size= 10 #maximum pool size
spring.datasource.hikari.idle-timeout=10000 #maximum idle time for
connection
spring.datasource.hikari.max-lifetime= 1000 # maximum lifetime in
milliseconds of a connection in the pool after it is closed.
spring.datasource.hikari.auto-commit =true #default auto-commit
behavior.
HikariCP is a reliable, high-performance JDBC connection pool. It is much faster, lightweight, and has better performance as compared to other connection pool APIs. Because of all these compelling reasons, HikariCP is now the default pool implementation in Spring Boot 2. In this article, we will have a closer look to configure Hikari with Spring Boot.

Hikari and test on borrow option

I use spring boot 2 with Hikari connection pool, jpa and postgres.
Is there any reason to continue to use theses options
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
spring.datasource.testWhileIdle
No, They are unknown properties to Hikari connection pool so no need ,
They exists only in Tomcat JDBC Connection Pool (used in old Spring boot) which you aren't using anymore.
Explanation of different between properties
DBCP testOnBorrow=false rollbackOnReturn=false
enableAutoCommitOnReturn=false
Issues:
testOnBorrow=false increases the likelihood of broken connections
given to your application rollbackOnReturn=false +
enableAutoCommitOnReturn=false, like the C3P0 "remediation" above can
bleed transactions between consumers or cause locks to be held for
extended periods
HikariCP Differentiators
Tests connections with isValid() before returning them from the pool,
with an optimization that bypasses the check if the connection was
utilized within the last 1000ms Tracks connection state (and
transaction state), and performs rollback() only the the case of a
non-autocommit connections with uncommitted changes

MysqlConnectionPoolDataSource or c3p0 like library?

What's the difference between MysqlConnectionPoolDataSource and C3p0, BoneCP or dbcp library for connection pooling? I don't understand why use a library if mysql connector give connection pooling.
A ConnectionPoolDataSource is not a connection pool (or at least: it shouldn't be), it is intended to be used by a DataSource that provides pooling (eg from an application server). A ConnectionPoolDataSource provides the physical connections that will be held in the connection pool. Besides creating those physical connections a ConnectionPoolDataSource shouldn't do anything else.
So if you are working in an application server, use the pooling provided by the DataSources of the application server. If you are in a standalone application or a server that doesn't provide datasources on its own, use third party connection pools like BoneCP, c3p0 or Apache DBCP. If MySQL also provides a normal DataSource that provides pooling, then you could use that.

Resources