Skip to content

Commit

Permalink
perf($Hikari): set Hikari CP as default connection pool
Browse files Browse the repository at this point in the history
removed Alibaba Druid

BREAKING CHANGE: removed Alibaba Druid
  • Loading branch information
johnnymillergh committed Mar 5, 2022
1 parent 67c8967 commit 7fdce5a
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 283 deletions.
15 changes: 0 additions & 15 deletions auth-center/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,6 @@
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid-spring-boot-starter.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>jconsole</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- https://github.com/jwtk/jjwt -->
<!-- Cannot Remove jjwt dependencies, cuz the login process is in here `auth-center`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,9 @@ spring:
zipkin:
base-url: http://maf-zipkin:9411
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
filters: stat,wall,log4j2
filter:
stat:
enabled: true
db-type: mysql
log-slow-sql: true
slow-sql-millis: 2000
slf4j:
enabled: true
statement-log-error-enabled: true
statement-create-after-log-enabled: false
statement-close-after-log-enabled: false
result-set-open-after-log-enabled: false
result-set-close-after-log-enabled: false
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
session-stat-enable: true
session-stat-max-count: 1000
stat-view-servlet:
enabled: true
url-pattern: /druid/*
reset-enable: false
login-username: root
login-password: maf_druid_password
allow:
type: com.zaxxer.hikari.HikariDataSource
dynamic:
primary: master_1
druid:
# connection pool size will be determined by DruidDataSourceCreatorPostProcessor.java
max-wait: 60000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
keep-alive: true
datasource:
master_1:
url: jdbc:mysql://maf-mysql-server-source:3306/muscle_and_fitness?useSSL=true&useUnicode=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,9 @@ spring:
zipkin:
base-url: http://localhost:9411
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
filters: stat,wall,log4j2
filter:
stat:
enabled: true
db-type: mysql
log-slow-sql: true
slow-sql-millis: 2000
slf4j:
enabled: true
statement-log-error-enabled: true
statement-create-after-log-enabled: false
statement-close-after-log-enabled: false
result-set-open-after-log-enabled: false
result-set-close-after-log-enabled: false
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
session-stat-enable: true
session-stat-max-count: 1000
stat-view-servlet:
enabled: true
url-pattern: /druid/*
reset-enable: false
login-username: root
login-password: maf_druid_password
allow:
type: com.zaxxer.hikari.HikariDataSource
dynamic:
primary: master_1
druid:
# connection pool size will be determined by DruidDataSourceCreatorPostProcessor.java
max-wait: 60000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
keep-alive: true
datasource:
master_1:
url: jdbc:mysql://localhost:3306/muscle_and_fitness?useSSL=true&useUnicode=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,9 @@ spring:
zipkin:
base-url: http://maf-zipkin:9411
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
filters: stat,wall,log4j2
filter:
stat:
enabled: true
db-type: mysql
log-slow-sql: true
slow-sql-millis: 2000
slf4j:
enabled: true
statement-log-error-enabled: true
statement-create-after-log-enabled: false
statement-close-after-log-enabled: false
result-set-open-after-log-enabled: false
result-set-close-after-log-enabled: false
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
session-stat-enable: true
session-stat-max-count: 1000
stat-view-servlet:
enabled: true
url-pattern: /druid/*
reset-enable: false
login-username: root
login-password: maf_druid_password
allow:
type: com.zaxxer.hikari.HikariDataSource
dynamic:
primary: master_1
druid:
# connection pool size will be determined by DruidDataSourceCreatorPostProcessor.java
max-wait: 60000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
keep-alive: true
datasource:
master_1:
url: jdbc:mysql://maf-mysql-server-source:3306/muscle_and_fitness?useSSL=true&useUnicode=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,9 @@ spring:
zipkin:
base-url: http://maf-zipkin:9411
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
filters: stat,wall,log4j2
filter:
stat:
enabled: true
db-type: mysql
log-slow-sql: true
slow-sql-millis: 2000
slf4j:
enabled: true
statement-log-error-enabled: true
statement-create-after-log-enabled: false
statement-close-after-log-enabled: false
result-set-open-after-log-enabled: false
result-set-close-after-log-enabled: false
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
session-stat-enable: true
session-stat-max-count: 1000
stat-view-servlet:
enabled: true
url-pattern: /druid/*
reset-enable: false
login-username: root
login-password: maf_druid_password
allow:
type: com.zaxxer.hikari.HikariDataSource
dynamic:
primary: master_1
druid:
# connection pool size will be determined by DruidDataSourceCreatorPostProcessor.java
max-wait: 60000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
keep-alive: true
datasource:
master_1:
url: jdbc:mysql://maf-mysql-server-source:3306/muscle_and_fitness?useSSL=true&useUnicode=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,9 @@ spring:
zipkin:
base-url: http://maf-zipkin:9411
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
filters: stat,wall,log4j2
filter:
stat:
enabled: true
db-type: mysql
log-slow-sql: true
slow-sql-millis: 2000
slf4j:
enabled: true
statement-log-error-enabled: true
statement-create-after-log-enabled: false
statement-close-after-log-enabled: false
result-set-open-after-log-enabled: false
result-set-close-after-log-enabled: false
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
session-stat-enable: true
session-stat-max-count: 1000
stat-view-servlet:
enabled: true
url-pattern: /druid/*
reset-enable: false
login-username: root
login-password: maf_druid_password
allow:
type: com.zaxxer.hikari.HikariDataSource
dynamic:
primary: master_1
druid:
# connection pool size will be determined by DruidDataSourceCreatorPostProcessor.java
max-wait: 60000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
keep-alive: true
datasource:
master_1:
url: jdbc:mysql://maf-mysql-server-source:3306/muscle_and_fitness?useSSL=true&useUnicode=true
Expand Down
15 changes: 0 additions & 15 deletions maf-mis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,6 @@
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid-spring-boot-starter.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>jconsole</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Apache POI - Java API To Access Microsoft Format Files -->
<dependency>
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
<spring-content.version>1.0.0.M5</spring-content.version>
<spring-boot-admin-starter-server.version>2.6.2</spring-boot-admin-starter-server.version>
<spring-boot-admin-starter-client.version>2.6.2</spring-boot-admin-starter-client.version>
<druid-spring-boot-starter.version>1.2.8</druid-spring-boot-starter.version>
<mybatis-plus-boot-starter.version>3.5.1</mybatis-plus-boot-starter.version>
<dynamic-datasource-spring-boot-starter.version>3.5.1</dynamic-datasource-spring-boot-starter.version>
<sharding-sphere.version>4.1.1</sharding-sphere.version>
Expand Down
16 changes: 0 additions & 16 deletions spring-cloud-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,6 @@
<version>${dynamic-datasource-spring-boot-starter.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid-spring-boot-starter.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>jconsole</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- The Apache Commons Object Pooling Library -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.jmsoftware.maf.springcloudstarter.database;

import cn.hutool.db.ds.DataSourceWrapper;
import com.alibaba.druid.util.JdbcUtils;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.plugin.MasterSlaveAutoRoutingPlugin;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceCreatorAutoConfiguration;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
import lombok.SneakyThrows;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.beans.factory.annotation.Qualifier;
Expand All @@ -28,36 +25,29 @@
* @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 6/27/2021 8:15 AM
**/
@Slf4j
@RequiredArgsConstructor
@ConditionalOnClass({MybatisPlusAutoConfiguration.class, DynamicDataSourceCreatorAutoConfiguration.class})
public class DataSourceConfiguration {
private final DynamicRoutingDataSource dynamicRoutingDataSource;

/**
* Primary data source. Had to configure DynamicRoutingDataSource as primary. Otherwise
* MasterSlaveAutoRoutingPlugin will not be able to be injected datasource correctly.
*
* @param dynamicRoutingDataSource the dynamic routing data source
* @return the data source
* @see MasterSlaveAutoRoutingPlugin
*/
@Bean
@Primary
@SneakyThrows
public DataSource primaryDataSource(DynamicRoutingDataSource dynamicRoutingDataSource,
DynamicDataSourceProperties dynamicDataSourceProperties) {
val jdbcUrl = dynamicDataSourceProperties
.getDatasource()
.get(dynamicDataSourceProperties.getPrimary())
.getUrl();
val driverClassName = JdbcUtils.getDriverClassName(jdbcUrl);
val wrappedDataSource = DataSourceWrapper.wrap(dynamicRoutingDataSource, driverClassName);
log.info("Wrapping 'DynamicRoutingDataSource' as 'primaryDataSource', jdbcUrl: {}, driverClassName: {}, " +
"wrappedDataSource: {}", jdbcUrl, driverClassName, wrappedDataSource);
return wrappedDataSource;
public DataSource primaryDataSource() {
log.info("Setting 'DynamicRoutingDataSource' as 'primaryDataSource', {}", dynamicRoutingDataSource);
return dynamicRoutingDataSource;
}

@Bean
@QuartzDataSource
@ConditionalOnProperty(prefix = "spring.quartz", name = "job-store-type", havingValue = "jdbc")
public DataSource quartzDataSource(DynamicRoutingDataSource dynamicRoutingDataSource) {
public DataSource quartzDataSource() {
val quartzDataSource = dynamicRoutingDataSource.getDataSource(DataSourceEnum.QUARTZ.getDataSourceName());
log.info("Setting up quartzDataSource from 'DynamicRoutingDataSource', quartzDataSource: {}",
quartzDataSource.hashCode());
Expand Down
Loading

0 comments on commit 7fdce5a

Please sign in to comment.