Not just open source the best JAVA data connection pool Alibaba Druid

Not just open source the best JAVA data connection pool Alibaba Druid

happy dog

Baijiahao 17-10-24 22:21

Today is the 1024 Programmer's Day, first I wish you a happy holiday, and then give you a big killing skill. Look at the picture.

Are you worried? OK, back to the topic. Since we want to talk about data connection pool, first explain what is data continuous pool.

When there is no data connection pool, all data connections directly access the database, but now large websites have hundreds of millions of clicks and visits, it is easy to bring down the database server, and every time the connection is disconnected, it is cumbersome It is easy to lead to problems such as resource leakage and long-term unresponsiveness.

The basic idea of ​​the data connection pool is to store the database connection as an object in memory when the system is initialized. When the user needs to access the database, instead of establishing a new connection, an established idle connection is taken from the connection pool. object. After use, the user does not close the connection, but puts the connection back into the connection pool for the next request to access.

Common open source JAVA data connection pools are:

C3P0: An open source JDBC connection pool that includes DataSources objects that implement the Connection and Statement pools specified by the jdbc3 and jdbc2 extension specifications.

DBCP (DataBase connection pool): A java connection pool project on apache, which is also a connection pool component used by tomcat. Two packages are required to use dbcp alone: ​​commons-dbcp.jar, commons-pool.jar Since establishing a database connection is a very time-consuming and resource-consuming behavior, some connections are established with the database in advance through the connection pool, placed in memory, and the application When the program needs to establish a database connection, you can directly apply for one in the connection pool, and then put it back after use.

But today we are going to talk about the best one, which is the Alibaba Druid data connection pool.

Druid is first and foremost a database connection pool. Druid is currently the best database connection pool. In terms of function, performance and scalability, it surpasses other database connection pools, including DBCP, C3P0, BoneCP, Proxool, and JBoss DataSource. Druid has deployed more than 600 applications in Alibaba, and has undergone a rigorous test of large-scale deployment in production environments for more than a year.

Druid is more than just a database connection pool. Druid also includes a ProxyDriver, a set of built-in JDBC component libraries, and a SQL Parser.

Druid extends some of the limitations of JDBC, allowing programmers to request credentials from the key service, statistical SQL information, SQL performance collection, SQL injection inspection, SQL translation, etc., and can also customize to achieve their own needs. Druid is an open source project based on the Apache 2.0 license, which you can use freely and freely. Druid only supports JDK 6 and above, and does not support JDK 1.4 and JDK 5.0.

Druid supports all JDBC-compliant databases, including Oracle, MySql, Derby, Postgresql, SQL Server, H2, and more. In addition, special optimizations have been made for Oracle and MySql, such as Oracle's PS Cache memory usage optimization and MySql's ping detection optimization.

Druid is a very good choice if you want to parse a SQL statement in java and implement the transformation. Druid provides complete support for MySQL, Oracle, Postgresql, and SQL-92 SQL. This is a handwritten high-performance SQL Parser that supports the Visitor mode, making it very convenient to analyze the abstract syntax tree of SQL. Through experiments, it is found that it takes less than 10 microseconds to parse a simple SQL statement, and 30 microseconds for a complex SQL statement.

The SQL Parser provided by Druid can intercept SQL at the JDBC layer for corresponding processing, such as sub-database sub-table, auditing, etc. Druid's WallFilter to defend against SQL injection attacks is implemented through Druid's SQL Parser analysis semantics.

The most convenient way to migrate from DBCP is to change org.apache.commons.dbcp.BasicDataSource to om.alibaba.druid.pool.DruidDataSource, and it is also very convenient to migrate from C3P0.

Welcome to follow, reply, exchange and discuss

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324552240&siteId=291194637