Druid in the field of connection pool can be said to be relatively fire, Alibaba open source of the JDBC connection pool, monitoring components, the following is a brief introduction to it.
It consists of three parts:
Druiddriver Agent driver, can provide the plug-in system based on Filter-chain mode.
Druiddatasource Efficient and manageable database connection pool.
Sqlparser.
function:
. can monitor database access performance, the Druid built-in provides a powerful Statfilter plug-in to detail SQL performance, which is useful for online analysis of database access performance.
. Replace DBCP and C3P0. Druid provides an efficient, powerful, scalable database connection pool.
. Database password encryption. Writing the database password directly in the configuration file is bad behavior and can lead to security problems. Druiddruiver and Druiddatasource both support PasswordCallback.
. SQL Execution Log, Druid provides different logfilter, can support common-logging, log4j and Jdklog, you can choose the corresponding logfilter as needed, monitor the database access you have applied.
. to extend JDBC, if you want to have programming requirements for the JDBC layer, you can easily write the JDBC layer extensions through the Filter-chain mechanism provided by Druid.
properties are similar to the DBCP connection pool, but with filters monitoring (value stat), Add the following servlet to the Web.xml to see the example: http://localhost:8080/ benbeargame_test/. Druid with spring (as long as the configuration of initialsize,maxactive can), added in fact, the configuration performance is not good, the official document does not add other attributes
<!--data source Org.apache.commons.dbcp.BasicDataSource Com.alibaba.druid.pool.DruidDataSource-->
<bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource" >
<property name= "Driverclassname" value= "Com.mysql.jdbc.Driver"/>
<property name= "url" value= "Jdbc:mysql://localhost/mybatis"/>
<property name= "username" value= "root"/>
<property name= "Password" value= "admin"/>
<!----> of Druid Connection pool
<property name= "Filters" value= "stat"/>
<!--below Druid and DBCP connection pool general ↓↓↓↓↓↓↓↓↓↓↓↓-->
<!--maxactive: Maximum number of connections-->
<property name= "maxactive" value= "/>"
<!--initialsize: Initializing connection-->
<property name= "InitialSize" value= "5"/>
</bean>
Filters Monitor Servlet
Http://localhost:8080/BenbearGame_test/druid
<servlet>
<servlet-name>DruidStatView<rvlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServlet<rvlet-class>
<rvlet>
<servlet-mapping>
<servlet-name>DruidStatView<rvlet-name>
<url-pattern>/druid/*</url-pattern>
<rvlet-mapping>
http://blog.csdn.net/yunnysunny/article/details/8657095
Executecount |
Current SQL execution times |
|
Exectime |
Current SQL Execution time |
|
Execmax |
Current SQL Maximum execution time |
|
Txn |
Number of transactions currently running |
|
Error |
Number of current SQL execution errors |
|
Update |
Number of rows already affected in the current SQL update or delete operation |
|
Fetchrow |
Number of rows that have been read in the current SQL operation |
|
Running |
Current number of SQL running |
|
Concurrent |
Current SQL maximum concurrent execution number |
|
Exechisto |
An array of time distributions for the current SQL execute operation |
Divided into 0-1,1-10,10-100,100-1000,>1000,5 time distribution area, the unit is MS |
Execrshisto |
The current SQL does execute operation and resultset Open to Closed time sum distribution array |
Ditto |
Fetchrowhisto |
Array of current SQL query time distributions |
Ditto |
Updatehisto |
Current SQL update, delete time distribution array |
Ditto |
Configuration properties:
Configuration |
Default value |
Description |
Name |
|
The significance of configuring this property is that if there are multiple data sources, the monitoring can be distinguished by name. If not configured, a name will be generated, in the form: "datasource-" + system.identityhashcode (This) |
Jdbcurl |
|
The URL of the connection database, different databases. For example: Mysql:jdbc:mysql://10.20.153.104:3306/druid2 Oracle:jdbc:oracle:thin:@10.20.149.85:1521:ocnauto |
Username |
|
User name to connect to database |
Password |
|
The password to connect to the database. If you do not want the password to be written directly in the configuration file, you can use Configfilter. Look at this in detail: https://github.com/alibaba/druid/wiki/%E4%BD%BF%E7%94%A8ConfigFilter |
Driverclassname |
Automatic identification based on URL |
This can not be matched, if not configured Druid will automatically identify the dbtype based on the URL, and then select the appropriate driverclassname |
InitialSize |
0 |
The number of physical connections that were established when the initialization was initiated. Initialization occurs when the display invokes the Init method, or when the first getconnection |
Maxactive |
8 |
Maximum number of connection pools |
Maxidle |
8 |
is no longer in use, configured and no effect |
Minidle |
|
Minimum number of connection pools |
Maxwait |
|
The maximum wait time, in milliseconds, to get the connection. When MAXWAIT is configured, the default is to enable fair locks, and concurrency is reduced, and if you need to, you can use an unfair lock by configuring the Useunfairlock property to True. |
Poolpreparedstatements |
False |
Whether to cache PreparedStatement, i.e. Pscache. Pscache is a great boost to database performance for cursors, such as Oracle. It is recommended to close under MySQL. |
Maxopenpreparedstatements |
-1 |
To enable Pscache, you must configure greater than 0 and poolpreparedstatements automatically trigger the modification to true when greater than 0 o'clock. In Druid, there will be no problem of excessive memory usage under Oracle Pscache, which can be configured to be larger, such as 100 |
Validationquery |
|
SQL that is used to detect the validity of a connection and requires a query statement. If Validationquery is Null,testonborrow, Testonreturn, Testwhileidle will not function. |
Testonborrow |
True |
When requesting a connection, performing a validationquery detection connection is valid, and making this configuration can degrade performance. |
Testonreturn |
False |
Performs a validationquery detection connection when returning a connection, and this configuration can degrade performance |
Testwhileidle |
False |
The recommended configuration is true, does not affect performance, and guarantees security. When requesting a connection, detect if the idle time is greater than timebetweenevictionrunsmillis, perform validationquery detection connection is valid. |
Timebetweenevictionrunsmillis |
|
Has two meanings: 1 Destroy thread will detect the connection interval of 2) Testwhileidle judgment basis, detailed look at the description of Testwhileidle properties |
Numtestsperevictionrun |
|
No longer used, a druiddatasource only supports a evictionrun |
Minevictableidletimemillis |
|
|
Connectioninitsqls |
|
The SQL that executes when the physical connection is initialized |
Exceptionsorter |
Automatic identification based on DBTYPE |
Discard the connection when the database throws some unrecoverable exceptions |
Filters |
|
The property type is a string that configures the extension through an alias, and the common plug-ins are: FILTER:LOG4J Defense SQL injection Filter:wall for FILTER:STAT logs for monitoring statistics |
Proxyfilters |
|
The type is LIST<COM.ALIBABA.DRUID.FILTER.FILTER>, and if both filters and Proxyfilters are configured, it is a combinatorial relationship, not a replacement relationship |