Druid Introduction

 

 

Druid Introduction 
What Druid that? 
Druid The first is a database connection pool. Druid is the best database connection pool, functionality, performance, scalability, more than the other database connection pool, including DBCP, C3P0, BoneCP, Proxool, JBoss DataSource. 
Druid Alibaba has deployed more than 600 applications, more than a year after the production of large-scale deployment of the harsh test environment. 
Druid is a JDBC component that consists of three parts: the 
plug-in based system Filter-Chain mode 
DruidDataSource Efficient management of database connection pooling 
SQL Parser 
Druid supports all JDBC-compliant databases, including Oracle, MySql, Derby, Postgresql, SQL Server, H2, etc., and Druid for Oracle and MySql to do a special optimized, such as Oracle's PS Cache memory footprint optimization, MySql detection of ping optimization. 
Monitoring functions provided by the Druid, monitor SQL execution time, ResultSet hold time, number of rows returned, updating the number of rows, number of errors, error stack information, you can clearly know that the connection pool and SQL work, it is possible to perform detailed statistics SQL performance, which is helpful for online access performance analysis database. 
 

Druid what can be done? 
Replace DBCP and C3P0. Druid provides an efficient, powerful, scalable database connection pool. 
Can monitor database access performance, Druid built provides a powerful StatFilter plugin that detailed statistics on the performance of SQL execution, which is helpful for online access performance analysis database.
Database password encryption. Write directly to the database password in the configuration file, which is not good behavior, easily lead to security problems. DruidDriver and DruidDataSource support PasswordCallback. 
SQL execution log, Druid offers different LogFilter, to support the Common - Logging, Log4j and JdkLog, you can press the need to select the appropriate LogFilter, database monitoring visits your application. 
Extended JDBC, if you want to have a demand programming for JDBC layer, Filter mechanism provided by the Druid, it is easy to write extensions JDBC layer. 
 
Druid arranged 
introduced maven project dependent jar package pom.xml:

 <dependency> 
    <the groupId> com.alibaba </ the groupId> 
    <the artifactId> Druid </ the artifactId> 
    <Version> 1.0 . 20 is </ Version> 
</ dependency 
 

data source configuration: 

copy Code
 <- - introducing profile!>   
    <the bean ID = " mybatisPropertyConfigurer "   
        class = " the org.springframework.beans.factory.config.
        <property name="order" value="1" />  
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="locations">
            <list> 
                <value>classpath:druid.properties</value>
            </list>
        </property>  
    </bean>  
   
    <!-- druid连接池配置 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">  
        <property name="url" value="${url}" />  
        <property name="username" value="${username}" />  
        <property name="password" value="${password}" />  
        <property name="filters" value="${filters}" />  
        <property name="maxActive" value="${maxActive}" />   
        <property name="initialSize" value="${initialSize}" />  
        <property name="maxWait" value="${maxWait}" />  
        <property name="timeBetweenEvictionRunsMillis" value="/>"$ {timeBetweenEvictionRunsMillis}
        <property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" />
        <property name="validationQuery" value="${validationQuery}" />  
        <property name="testWhileIdle" value="${testWhileIdle}" />  
        <property name="testOnBorrow" value="${testOnBorrow}" />  
        <property name="testOnReturn" value="${testOnReturn}" />  
        <property name="poolPreparedStatements" value="${poolPreparedStatements}" />  
        <property name="maxPoolPreparedStatementPerConnectionSize" value="${maxPoolPreparedStatementPerConnectionSize}" />
    </bean>
复制代码
 
druid.Content properties: 

16151413 is12 is. 1110. 9. 8. 7. 6. 5. 4. 32. 1
















. 1918 is
. 17
 20 is 
21 is 
22 is 
23 is 
24 
25 
26 is 
27 
28 
29 
URL = JDBC: MySQL: // localhost: 3306 / Era 
username = the root 
password = 123456 
establish a physical connection number # initialization time. Initialization occurs when the display calls the init method, the first or the getConnection 
initialSize = . 1 
Number # define the maximum connection pool 
for maxActive = 20 is 
the maximum wait time to get a connection # milliseconds. After configuring maxWait, enabled by default fair locks, concurrent efficiency will decline, if necessary, by using the configuration useUnfairLock property to true unfair lock. 
maxWait = 60000 
# whether to cache preparedStatement, which is PSCache. PSCache support database cursors huge performance boost, for example oracle. 
# Mysql5.5 not PSCache function in the following version, it is recommended to close off.5 .5 and above have PSCache, recommended that you turn.
poolPreparedStatements = false 
# To enable PSCache, must be greater than zero configuration, when greater than 0, poolPreparedStatements triggered automatically changed to true. 
# In the Druid, the PSCache not exist too much memory for an Oracle issue, this value can be configured larger, such as 100 
maxPoolPreparedStatementPerConnectionSize = 100 
# is used to detect whether the connection is valid sql, it requires a query. If validationQuery is null, testOnBorrow, testOnReturn, testWhileIdle will not its role. 
validationQuery = the SELECT ' X ' 
performs detection validationQuery connection is valid application # connection made this configuration can reduce performance. 
testOnBorrow = false 
# execution validationQuery detect whether the connection is valid on return of connection, made this configuration can degrade performance. 
testOnReturn = false
# Suggestion configured as true, does not affect performance, and ensure safety. Detecting when the application connection, if the idle time is greater than timeBetweenEvictionRunsMillis, performs detection validationQuery connection is valid. 
testWhileIdle = to true 
# attribute is a string type, alias extension arranged manner, commonly used plug: monitoring use statistics filter: STAT; Log filter used: log4j; sql injected defense filter: Wall 
Filters = STAT, Wall 
# has two meanings: a time interval detection Destroy thread connection); 2 ) testWhileIdle judgment basis, see detailed description testWhileIdle attribute 
timeBetweenEvictionRunsMillis = 3000 
# configure a minimum connection time cell survival milliseconds 
minEvictableIdleTimeMillis = 300,000 
 
 if you want to use the built-in monitoring Druid, configure a data source coupled <Property name = " Filters " value = " STAT " />Above already have. 
   Also need to add in the web.xml: 
Copy Code
<-! Web.xml Web-enabled monitoring statistics required in Web applications Servlet added this statement -> 
  <the servlet> 
      <the servlet-name> DruidStatView </ the servlet-name> 
      <servlet- class > com.alibaba.druid .support.http.StatViewServlet </ servlet- class > 
      <the init-param>   
        <-! whether to allow empty statistics, default true when not write -> 
        <param-name> resetEnable </ param-name>   
        <param- value> to true </ param-value>   
        </ the init-param>   
        <the init-param>   
        <-! user name, user name and password can not write, do not need to enter when not writing, log in directly -> 
        <param-name > loginUsername </ param-name>   
        </ the init-param>   
        <  param-the init> 
        <-! Password ->
        <param-name>loginPassword</param-name>  
        <param-value>123456</param-value>  
      </init-param>  
  </servlet>
  <servlet-mapping>
      <servlet-name>DruidStatView</servlet-name>
      <url-pattern>/druid/*</url-pattern>
  </servlet-mapping>
复制代码

 

Guess you like

Origin www.cnblogs.com/Jeely/p/12040129.html