Ali druid introduction and related configuration

1. Introduction, what is Druid

    Druid is a project on Alibaba's open source platform. The whole project consists of database connection pool, plug-in framework and SQL parser. This project is mainly to expand some limitations of JDBC, allowing programmers to achieve some special requirements, such as requesting credentials from the key service, statistical SQL information, SQL performance collection, SQL injection checking, SQL translation, etc. Programmers can customize to achieve the functions you need.

 

2. Performance related

   According to the person in charge of the Druid project, performance is not the design goal of Druid, but the test data shows that Druid's performance is better than DBCP, C3P0, Proxool, and JBoss. At present, the test connection given by the official website has failed, and the performance can only be verified in use.

 

3. Configuration

   Most of the properties of DruidDataSource refer to DBCP. If you use DBCP originally, migration is very convenient.

Official website configuration: https://github.com/alibaba/druid/wiki/DruidDataSource%E9%85%8D%E7%BD%AE

 

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
     <property name="url" value="${jdbc_url}" />
     <property name="username" value="${jdbc_user}" />
     <property name="password" value="${jdbc_password}" />

     <property name="filters" value="stat" />

     <property name="maxActive" value="20" />
     <property name="initialSize" value="1" />
     <property name="maxWait" value="60000" />
     <property name="minIdle" value="1" />

     <property name="timeBetweenEvictionRunsMillis" value="60000" />
     <property name="minEvictableIdleTimeMillis" value="300000" />

     <property name="testWhileIdle" value="true" />
     <property name="testOnBorrow" value="false" />
     <property name="testOnReturn" value="false" />

     <property name="poolPreparedStatements" value="true" />
     <property name="maxOpenPreparedStatements" value="20" />
 </bean>
 

 

In the above configuration, you usually need to configure the three items of url, username, password, and maxActive. For other configurations, refer to the DBCP configuration.

 

4. Configure monitoring statistics function Enable web monitoring statistics function in web.xml, 1

<!-- The connection pool enables the web monitoring statistics function start-->
	<filter>
		<filter-name>DruidWebStatFilter</filter-name>
		<filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
		<init-param>
			<param-name>exclusions</param-name>
			<param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>DruidWebStatFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<servlet>
		<servlet-name>DruidStatView</servlet-name>
		<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>DruidStatView</servlet-name>
		<url-pattern>/druid/*</url-pattern>
	</servlet-mapping>
	<!-- The connection pool enables web monitoring statistics end-->
 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326941959&siteId=291194637