Skip to content
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

why checking connection so frequently with druid? #2344

Closed
e7 opened this issue May 8, 2019 · 7 comments
Closed

why checking connection so frequently with druid? #2344

e7 opened this issue May 8, 2019 · 7 comments
Assignees

Comments

@e7
Copy link

e7 commented May 8, 2019

datasource:
      names: master,slave0
      master:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://192.168.1.229:3306/xxxx?useSSL=false&useUnicode=true&serverTimezone=UTC&characterEncoding=UTF-8&autoReconnect=true
        username: xxxx
        password: 123456
        druid:
          test-on-borrow: false
          test-while-idle: true
          validation-query: SELECT 1
          time-between-eviction-runs-millis: 30000
          min-evictable-idle-time-millis: 30000
          connection-init-sqls: set names utf8mb4;
      slave0:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://192.168.1.229:3306/xxxx?useSSL=false&useUnicode=true&serverTimezone=UTC&characterEncoding=UTF-8&autoReconnect=true
        username: xxxx
        password: 123456
        druid:
          test-on-borrow: false
          test-while-idle: true
          validation-query: SELECT 1
          time-between-eviction-runs-millis: 30000
          min-evictable-idle-time-millis: 30000
          connection-init-sqls: set names utf8mb4;
2019-05-08 09:19:34.444  INFO 10660 --- [nio-8080-exec-7] ShardingSphere-SQL                       : Rule Type: master-slave
2019-05-08 09:19:34.444  INFO 10660 --- [nio-8080-exec-7] ShardingSphere-SQL                       : SQL: /* ping */ SELECT 1 ::: DataSources: slave0
2019-05-08 09:19:35.441  INFO 10660 --- [io-8080-exec-10] ShardingSphere-SQL                       : Rule Type: master-slave
2019-05-08 09:19:35.441  INFO 10660 --- [io-8080-exec-10] ShardingSphere-SQL                       : SQL: /* ping */ SELECT 1 ::: DataSources: slave0
2019-05-08 09:19:36.448  INFO 10660 --- [nio-8080-exec-9] ShardingSphere-SQL                       : Rule Type: master-slave
2019-05-08 09:19:36.448  INFO 10660 --- [nio-8080-exec-9] ShardingSphere-SQL                       : SQL: /* ping */ SELECT 1 ::: DataSources: slave0
2019-05-08 09:19:37.449  INFO 10660 --- [nio-8080-exec-5] ShardingSphere-SQL                       : Rule Type: master-slave
2019-05-08 09:19:37.449  INFO 10660 --- [nio-8080-exec-5] ShardingSphere-SQL                       : SQL: /* ping */ SELECT 1 ::: DataSources: slave0
2019-05-08 09:19:38.455  INFO 10660 --- [nio-8080-exec-6] ShardingSphere-SQL                       : Rule Type: master-slave
2019-05-08 09:19:38.456  INFO 10660 --- [nio-8080-exec-6] ShardingSphere-SQL                       : SQL: /* ping */ SELECT 1 ::: DataSources: slave0
2019-05-08 09:19:39.458  INFO 10660 --- [nio-8080-exec-2] ShardingSphere-SQL                       : Rule Type: master-slave
2019-05-08 09:19:39.458  INFO 10660 --- [nio-8080-exec-2] ShardingSphere-SQL                       : SQL: /* ping */ SELECT 1 ::: DataSources: slave0
2019-05-08 09:19:40.455  INFO 10660 --- [nio-8080-exec-1] ShardingSphere-SQL                       : Rule Type: master-slave
2019-05-08 09:19:40.456  INFO 10660 --- [nio-8080-exec-1] ShardingSphere-SQL                       : SQL: /* ping */ SELECT 1 ::: DataSources: slave0
@e7
Copy link
Author

e7 commented May 8, 2019

<properties>
  <java.version>1.8</java.version>
  <sharding-sphere.version>3.1.0</sharding-sphere.version>
</properties>

@KomachiSion
Copy link
Member

Hi @e7, it looks like you use sharding-jdbc-spring-boot-starter 3.1.0, you can remove druid prefix and retry. such as

datasource:
      names: master,slave0
      master:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://192.168.1.229:3306/xxxx?useSSL=false&amp;useUnicode=true&amp;serverTimezone=UTC&amp;characterEncoding=UTF-8&amp;autoReconnect=true
        username: xxxx
        password: 123456
        test-on-borrow: false
        test-while-idle: true
        validation-query: SELECT 1
        time-between-eviction-runs-millis: 30000
        min-evictable-idle-time-millis: 30000
        connection-init-sqls: set names utf8mb4;
      slave0:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://192.168.1.229:3306/xxxx?useSSL=false&amp;useUnicode=true&amp;serverTimezone=UTC&amp;characterEncoding=UTF-8&amp;autoReconnect=true
        username: xxxx
        password: 123456
        test-on-borrow: false
        test-while-idle: true
        validation-query: SELECT 1
        time-between-eviction-runs-millis: 30000
        min-evictable-idle-time-millis: 30000
        connection-init-sqls: set names utf8mb4;

@e7
Copy link
Author

e7 commented May 8, 2019

@KomachiSion Thanks for replying, I have tried it, still not working

@KomachiSion
Copy link
Member

@KomachiSion Thanks for replying, I have tried it, still not working

Can you provide your full configuration or your example code to GitHub?
I check your log info and find that it seems execute SELECT 1 by ShardingDatasource not by DruidDatasource

@e7
Copy link
Author

e7 commented May 8, 2019

Here is an example which can reproduce my problem.
example-sharding-jdbc-ping

windows 7 64bit
java8
idea 2018.3

@KomachiSion
Copy link
Member

OK, I find the reason for this problem. The problem caused by spring-boot-actuator, which will check datasource connection healthy before each invoke.
You can see some detail info in method org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator.doDataSourceHealthCheck.

If you wanna to debug for this problem, you can set breakPoint in method io.shardingsphere.shardingjdbc.jdbc.core.statement.MasterSlaveStatement.executeQuery(String sql) and check the JVM stacks.

So for ShardingSphere, it just execute a normal SQL called by spring health check. Not problems.

@e7
Copy link
Author

e7 commented May 8, 2019

@KomachiSion Yes, it's NOT a problem, thanks for your time and patience, and it can be disabled by the following configuration

management:
  health:
    db:
      enabled: false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants