Skip to content

Commit 7e085d5

Browse files
shwstppryadvr
andauthored
framework/db: use HikariCP as default and improvements (#9518)
Per docs, if the mysql connector is JDBC2 compliant then it should use the Connection.isValid API to test a connection. (https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#isValid-int-) This would significantly reduce query lags and API throughput, as for every SQL query one or two SELECT 1 are performed everytime a Connection is given to application logic. This should only be accepted when the driver is JDBC4 complaint. As per the docs, the connector-j can use /* ping */ before calling SELECT 1 to have light weight application pings to the server: https://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-j2ee-concepts-connection-pooling.html Replaces dbcp2 connection pool library with more performant HikariCP. With this unit tests are failing but build is passing. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> Co-authored-by: Rohit Yadav <rohityadav89@gmail.com>
1 parent 31b0ed0 commit 7e085d5

File tree

12 files changed

+229
-43
lines changed

12 files changed

+229
-43
lines changed

client/conf/db.properties.in

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ db.cloud.uri=
3434

3535

3636
# CloudStack database tuning parameters
37+
db.cloud.connectionPoolLib=hikaricp
3738
db.cloud.maxActive=250
3839
db.cloud.maxIdle=30
39-
db.cloud.maxWait=10000
40-
db.cloud.validationQuery=SELECT 1
40+
db.cloud.maxWait=600000
41+
db.cloud.minIdleConnections=5
42+
db.cloud.connectionTimeout=30000
43+
db.cloud.keepAliveTime=600000
44+
db.cloud.validationQuery=/* ping */ SELECT 1
4145
db.cloud.testOnBorrow=true
4246
db.cloud.testWhileIdle=true
4347
db.cloud.timeBetweenEvictionRunsMillis=40000
@@ -70,9 +74,13 @@ db.usage.uri=
7074

7175

7276
# usage database tuning parameters
77+
db.usage.connectionPoolLib=hikaricp
7378
db.usage.maxActive=100
7479
db.usage.maxIdle=30
75-
db.usage.maxWait=10000
80+
db.usage.maxWait=600000
81+
db.usage.minIdleConnections=5
82+
db.usage.connectionTimeout=30000
83+
db.usage.keepAliveTime=600000
7684
db.usage.url.params=serverTimezone=UTC
7785

7886
# Simulator database settings
@@ -82,9 +90,13 @@ db.simulator.host=@DBHOST@
8290
db.simulator.driver=@DBDRIVER@
8391
db.simulator.port=3306
8492
db.simulator.name=simulator
93+
db.simulator.connectionPoolLib=hikaricp
8594
db.simulator.maxActive=250
8695
db.simulator.maxIdle=30
87-
db.simulator.maxWait=10000
96+
db.simulator.maxWait=600000
97+
db.simulator.minIdleConnections=5
98+
db.simulator.connectionTimeout=30000
99+
db.simulator.keepAliveTime=600000
88100
db.simulator.autoReconnect=true
89101

90102
# Connection URI to the database "simulator". When this property is set, only the following properties will be used along with it: db.simulator.host, db.simulator.port, db.simulator.name, db.simulator.autoReconnect. Other properties will be ignored.

developer/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
<groupId>org.apache.commons</groupId>
4343
<artifactId>commons-pool2</artifactId>
4444
</dependency>
45+
<dependency>
46+
<groupId>com.zaxxer</groupId>
47+
<artifactId>HikariCP</artifactId>
48+
</dependency>
4549
<dependency>
4650
<groupId>org.jasypt</groupId>
4751
<artifactId>jasypt</artifactId>

engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ private static void initDB(String dbPropsFile, String rootPassword, String[] dat
116116
}
117117

118118
public static void main(String[] args) {
119-
120-
ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"/com/cloud/upgrade/databaseCreatorContext.xml"});
121-
appContext.getBean(ComponentContext.class);
122-
123119
String dbPropsFile = "";
124120
List<String> sqlFiles = new ArrayList<String>();
125121
List<String> upgradeClasses = new ArrayList<String>();
@@ -166,13 +162,17 @@ public static void main(String[] args) {
166162
System.exit(1);
167163
}
168164

165+
initDB(dbPropsFile, rootPassword, databases, dryRun);
166+
167+
ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"/com/cloud/upgrade/databaseCreatorContext.xml"});
168+
appContext.getBean(ComponentContext.class);
169+
169170
try {
170171
TransactionLegacy.initDataSource(dbPropsFile);
171172
} catch (IOException e) {
172173
e.printStackTrace();
173174
System.exit(1);
174175
}
175-
initDB(dbPropsFile, rootPassword, databases, dryRun);
176176

177177
// Process sql files
178178
for (String sqlFile : sqlFiles) {

engine/storage/snapshot/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
<version>${project.version}</version>
5757
<scope>compile</scope>
5858
</dependency>
59+
<dependency>
60+
<groupId>mysql</groupId>
61+
<artifactId>mysql-connector-java</artifactId>
62+
<scope>test</scope>
63+
</dependency>
5964
</dependencies>
6065
<build>
6166
<plugins>

framework/db/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
<groupId>org.apache.commons</groupId>
4141
<artifactId>commons-dbcp2</artifactId>
4242
</dependency>
43+
<dependency>
44+
<groupId>com.zaxxer</groupId>
45+
<artifactId>HikariCP</artifactId>
46+
</dependency>
4347
<dependency>
4448
<groupId>commons-io</groupId>
4549
<artifactId>commons-io</artifactId>
@@ -48,6 +52,10 @@
4852
<groupId>org.apache.commons</groupId>
4953
<artifactId>commons-pool2</artifactId>
5054
</dependency>
55+
<dependency>
56+
<groupId>mysql</groupId>
57+
<artifactId>mysql-connector-java</artifactId>
58+
</dependency>
5159
<dependency>
5260
<groupId>org.apache.cloudstack</groupId>
5361
<artifactId>cloud-utils</artifactId>

framework/db/src/main/java/com/cloud/utils/db/ConnectionConcierge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void unregister(String name) {
145145
protected String testValidity(String name, Connection conn) {
146146
if (conn != null) {
147147
synchronized (conn) {
148-
try (PreparedStatement pstmt = conn.prepareStatement("SELECT 1");) {
148+
try (PreparedStatement pstmt = conn.prepareStatement("/* ping */ SELECT 1");) {
149149
pstmt.executeQuery();
150150
} catch (Throwable th) {
151151
logger.error("Unable to keep the db connection for " + name, th);

0 commit comments

Comments
 (0)