当前位置:网站首页>Yyds dry inventory Druid connection pool usage

Yyds dry inventory Druid connection pool usage

2022-06-26 07:31:00 Feng, crazy


brief introduction

Druid Able to provide strong ⼤ Monitoring and expansion functions of .

⼀、 send ⽤

1.1 maven To configure :

      
      
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.18</version>
</dependency>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

1.2 Integrate spring boot

      
      
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.18</version>
</dependency>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.


⼆、 Monitoring statistics

2.1 open

 ​https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatFilter​


2.2 send ⽤ And configuration StatViewServlet  

 ​https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatViewServlet%E9%85%8D%E7%BD%AE​​​​

Druid Built in provides ⼀ individual StatViewServlet⽤ Yu Zhan ⽰Druid Statistical information .

This StatViewServlet Of ⽤ Transit includes :

  • Provide monitoring information exhibition ⽰ Of html page ⾯
  • Providing monitoring information JSON API  

Be careful : send ⽤StatViewServlet, It is suggested that ⽤druid 0.2.6 Above version .

2.3 send ⽤ And configuration WebStatFilter  

 ​https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_%E9%85%8D%E7%BD%AEWebStatFilter

WebStatFilter⽤ To collect web-jdbc Associated monitoring data .

2.4 send ⽤ And configuration Spring Association monitoring

 ​https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_Druid%E5%92%8CSpring%E5%85%B3%E8%81%94%E7%9B%91%​​​​

Druid Provides Spring and Jdbc Associated monitoring of .

3、 ... and 、 Reference configuration

Database connection pool

DruidDataSource To configure

Druid Spring Boot Starter

 ​https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter

3.1 Add the configuration

      
      
spring.datasource.url=jdbc:mysql://localhost:3306/park?
useUnicode=true&characterEncoding=utf8mb4
spring.datasource.username=root
spring.datasource.password=123456
# ... Other configuration ( Optional , It's not necessary , send ⽤ If the database is embedded, the above three items can also be omitted )
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.


3.2 Configuration properties

Druid Spring Boot Starter The name of the configuration property exactly follows Druid, You can go through Spring Boot To configure ⽂ To configure Druid Database connection

Pool connection and monitoring , If it is not configured, make ⽤ The default value is .

      
      
######## JDBC To configure ########
#spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://localhost:3306/park?
useUnicode=true&characterEncoding=utf-8
spring.datasource.password=123456
spring.datasource.username=root
#spring.security.user.name=test
#spring.security.user.password=123456
################################### Start Druid To configure
###################################
######## ⼀、 Connection pool configuration ########
spring.datasource.druid.initial-size=5
spring.datasource.druid.max-active=30
spring.datasource.druid.min-idle=5
# Get the most ⼤ Waiting time (ms)
spring.datasource.druid.max-wait=60000
# Configure monitoring statistics interception filters, Remove the post monitoring boundary ⾯sql⽆ Law statistics ,'wall'⽤ In case ⽕ wall # Configure multiple English characters ⽂ Comma separated
# this ⾥ send ⽤ Are all default configurations , Sure ⾃ Definition
spring.datasource.druid.filters=stat,wall
# adopt connectProperties Property to open mergeSql function ; slow SQL Record
spring.datasource.druid.connectionproperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
# Merge multiple DruidDataSource Monitoring data
spring.datasource.druid.use-global-data-source-stat=true
# Whether the cache preparedStatement, That is to say PSCache.PSCache Yes ⽀ The performance of database with cursor is greatly improved ⼤,⽐ If you say
oracle. stay mysql The next suggestion is to close .
spring.datasource.druid.pool-prepared-statements=false
# To start ⽤PSCache, You have to configure ⼤ On 0, When ⼤ On 0 when ,poolPreparedStatements⾃ The automatic trigger is modified to true
spring.datasource.druid.max-pool-prepared-statement-per-connection-size=0
# And on ⾯ Equivalence
spring.datasource.druid.max-open-prepared-statements= 0
# ⽤ To check whether the connection is valid sql
spring.datasource.druid.validation-query=select 1 from dual
spring.datasource.druid.validation-query-timeout=60000
# Apply for connection with ⾏validationQuery Check whether the connection is valid , This configuration will degrade performance .
spring.datasource.druid.test-on-borrow=false
# Return the connection with ⾏validationQuery Check whether the connection is valid , This configuration will degrade performance .
spring.datasource.druid.test-on-return=false
# Recommended configuration is true, No performance impact , And ensure safety . Check when applying for connection , If you have free time ⼤ On
timeBetweenEvictionRunsMillis, Of board ⾏validationQuery Check whether the connection is valid
spring.datasource.druid.test-while-idle=true
# How long is the configuration interval ⾏⼀ Secondary test , Detects idle connections that need to be closed , In milliseconds
spring.datasource.druid.time-between-eviction-runs-millis=60000
# The connection remains idle ⽽ The best way not to be expelled ⼩ Time spring.datasource.druid.min-evictable-idle-time-millis=300000
spring.datasource.druid.max-evictable-idle-time-millis=300000
spring.datasource.druid.login-timeout=6000
######## ⼆、WebStatFilter To configure ########
#
## WebStatFilter To configure , Please refer to Druid Wiki, To configure _ To configure WebStatFilter
spring.datasource.druid.web-stat-filter.enabled=true
spring.datasource.druid.web-stat-filter.url-pattern=/*
spring.datasource.druid.web-statfilter.exclusions=*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*,/druid
spring.datasource.druid.web-stat-filter.session-stat-enable=
spring.datasource.druid.web-stat-filter.session-stat-max-count=
spring.datasource.druid.web-stat-filter.principal-session-name=
spring.datasource.druid.web-stat-filter.principal-cookie-name=
spring.datasource.druid.web-stat-filter.profile-enable=
######## ⼆、StatViewServlet To configure ########
#
## StatViewServlet To configure , Please refer to Druid Wiki, To configure _StatViewServlet To configure
# Start or not ⽤StatViewServlet( Monitoring page ⾯) The default value is false( Considering the security problem, it is not started by default , To start ⽤ It is recommended to set a key or ⽩ List to ensure safety )
spring.datasource.druid.stat-view-servlet.enabled=true
spring.datasource.druid.stat-view-servlet.url-pattern=/druid/*
spring.datasource.druid.stat-view-servlet.login-username=admin
spring.datasource.druid.stat-view-servlet.login-password=123456
# Forbid ⽤HTML page ⾯ Upper “Reset All” function
spring.datasource.druid.stat-view-servlet.reset-enable=false
# IP⽩ list ( Not configured or empty , All access is allowed )
spring.datasource.druid.stat-view-servlet.allow=
# IP⿊ list ( In common ,deny Prior to the allow)
spring.datasource.druid.stat-view-servlet.deny=
######## 3、 ... and 、StatViewServlet To configure ########
#
## Spring Monitoring configuration , Please refer to Druid Github Wiki, To configure _Druid and Spring Associated monitoring configuration
# Spring monitor AOP cut ⼊ spot , Such as x.y.z.service.*, Configure multiple English characters ⽂ Comma separated
spring.datasource.druid.aoppatterns=com.xiaofu.park.controller.*,com.xiaofu.park.service.*,com.xiaofu.park.dao.
*
################################### End Druid To configure
###################################
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.


3.3 filter send ⽤

⽬ The former is the following Filter Provides configuration ⽀ a , Please refer to ⽂ Or according to IDE carry ⽰(spring.datasource.druid.filter.*) Into the ⾏ To configure .

  • StatFilter
  • WallFilter
  • ConfigFilter
  • EncodingConvertFilter
  • Slf4jLogFilter
  • Log4jFilter
  • Log4j2Filter
  • CommonsLogFilter
原网站

版权声明
本文为[Feng, crazy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202171109067667.html