HIKARICP is a database connection pool of a rising star, known as the best performance, can be perfect to PK off the other connection pool.
Original address: http://blog.csdn.net/clementad/article/details/46928621
Official website:Https://github.com/brettwooldridge/HikariCP
Why use HIKARICP? This has to start with BONECP:
What the? Aren't there c3p0/dbcp these mature database connection pools? Always use good, why do you make a BONECP? Because, the legend of BONECP in the fast this feature to achieve the ultimate, the official data is c3p0 and so on about 25 times times. Don't believe it? I don't really believe it either. However, there is a picture of the truth ah (image from BONECP official website: http://jolbox.com/benchmarks.html):
Moreover, online for BONECP is rave, recommended article a lot of search.
However, on the MAVEN repository website (HTTP://MVNREPOSITORY.COM/ARTIFACT/COM.JOLBOX/BONECPlooking for the latest version, you will find that the latest is October 2013 (so long no new version come out?). )。 So, go again to BONECP's Githut (Https://github.com/wwadge/bonecpSee if you have recently submitted code. But found that the author of Bonecp for the project seems to have been discouraged, said to give up to HIKARICP (there is a picture of the truth):
...... What the? Another CP? ...... What is Hikari?
Hikari from Japanese, is "light" (
the light of the Sun, not the bare light) means. The author estimates that this word is used to imply that the CP is fast. I do not know whether the author is Japanese, but Japan also has a lot of good yards farmers, heard that the Japanese made out of bitcoin ...
The slogan of this product is "fast, simple, reliable". Does the fact match the slogan? There is a picture of the truth (benchmarks again):
This figure, also indirectly, once again proves that the BONECP is much stronger than c3p0, of course, compared with the "light", and weak a lot of AH.
So, how does such a good p do it? The official website explains in detailSome of the optimizations made by HIKARICP are summarized as follows:
- bytecode Simplification : Optimize the code until the least compiled bytecode, so that the CPU cache can load more program code;
- optimize proxies and interceptors : reduce code, such as HIKARICP statement proxy only 100 lines of code, only the BONECP one-tenth;
- Custom Array type (faststatementlist) instead of ArrayList: avoid a range check for each get () call, avoiding a sweep from the beginning to the end of the call to remove ();
- Custom collection type (concurrentbag): Improve the efficiency of concurrent read and write;
- other optimizations for BONECP defects , such as the study of method invocations that take more than one CPU time slice (but not exactly how to optimize them).
Many of the optimization comparisons are aimed at BONECP ... Ha ha. (Reference article: Https://github.com/brettwooldridge/HikariCP/wiki/Down-the-Rabbit-Hole)
A comparison of the code volume of several connection pools (the less code, generally means that the more efficient the execution, the less likely the bug is):
However, "Guangzhoa sell melon, self-urge self-tracing" This proverb Japanese also understand, so, the user's praise like Tide also has figure has the truth:
There are also third-party tests on speed:
Perhaps you will say, high speed, if instability is also flawed ah. Thus, a diagram of stability is also coming:
In addition, there are experiments and data support on reliability. ForDatabase connection interruptedThe case that passed the testgetconnection (), the different methods of handling CP are as follows: (all CP configured with connectiontimeout similar parameters for 5 seconds)
HIKARICP: After waiting for 5 seconds, if the connection is still not restored, a SQLExceptions exception is thrown, and the subsequent getconnection () is treated as such;
c3p0: No response at all, no hints, no "Checkouttimeout"There is no notification to the caller after the configured time-out, and then wait 2 minutes to finally wake up and return an error;
Tomcat: Return a connection, then ... If the caller uses this invalid connection to execute the SQL statement ... The results can be imagined; After about 55 seconds finally woke up, this time the getconnection () finally return an error, but did not wait for the parameter configuration of 5 seconds, but immediately return error;
BONECP: As with Tomcat, it is about 55 seconds before waking up with a normal response, and will finally wait 5 seconds to return the error;
Visible, HIKARICP is the most reasonable way to deal with. Based on this test result, the scores for each CP processing database outage are as follows:
Reference article: Https://github.com/brettwooldridge/HikariCP/wiki/Bad-Behavior:-Handling-Database-Down
Say so good, use up will be very troublesome Ah, will have a lot of parameters to configure to have such effect ah? The answer is: No. If you used the BONECP configuration of the data source, then, it is simple, just need to change the datasource, slightly adjust the parameters on the line:
data Source configuration for BONECP:
<!--BONECP Datasource--<bean id= "DATASOURCEBONECP" class= "Com.jolbox.bonecp.BoneCPDataSource" destroy-method= "Close" > <property name= "driverclass" value= "${db.driverclass}"/> <property name= " Jdbcurl "value=" ${db.url} "/> <property name=" username "value=" ${db.username} "/> <property name=" password "Value=" ${db.password} "/> <property name=" idleconnectiontestperiodinminutes "value=" 2 "/> <property name = "Idlemaxageinminutes" value= "2"/> <property name= "maxconnectionsperpartition" value= "2"/> <property Name= "minconnectionsperpartition" value= "0"/> <property name= "Partitioncount" value= "2"/> <property name = "Acquireincrement" value= "1"/> <property name= "statementscachesize" value= ""/> <property name= " Lazyinit "value=" true "/> <property name=" maxconnectionageinseconds "value=" "/> <property name=" Defaultreadonly "value=" true "/> </bean>
data Source configuration for HIKARICP:
<!--Hikari Datasource--<bean id= "Datasourcehikari" class= "Com.zaxxer.hikari.HikariDataSource" destroy-method= "Shutdown" > <!--<property name= "Driverclassname" value= "${db.driverclass}"/>--< !--no need to specify unless the system is not automatically recognized-<property name= "Jdbcurl" value= "jdbc:mysql://localhost:3306/test?useunicode=true& Characterencoding=utf-8 "/> <property name=" username "value=" ${db.username} "/> <property name=" Password " Value= "${db.password}"/> <!--configured to True when a read-only database is connected, ensure security--<property name= "ReadOnly" value= "false"/> < ;! --the maximum length of time (in milliseconds) to wait for the connection pool to allocate a connection, which is not available for this length of time SqlException, default: 30 Seconds--<property name= "ConnectionTimeout" value= "30000 "/> <!--a maximum length of time (in milliseconds) for a connected idle state, timeout is released (retired), default: 10 minutes--<property name=" IdleTimeout "value=" 600000 "/ > <!--the lifetime of a connection (milliseconds), timed out and not being used is released (retired), default: 30 minutes, recommended setting is 30 seconds less than database timeout, refer to mysql wait_timeout parameter (show variables Like '%timeout% ';)--<property name= "Maxlifetime" value= "1800000 "/> <!--the maximum number of connections allowed in the connection pool. Default value: 10, recommended formula: ((Core_count * 2) + effective_spindle_count)--<property name= "maximumpoolsize" value= ""/> &l T;/bean>
Many of these configurations use the default values, exceptMaxlifetimeAndmaximumpoolsizePay attention to your calculations.Other configurations (Sqlsessionfactory, MyBatis mapperscannerconfigurer, TransactionManager, etc.) are not changed.
Other recommendations for datasource configuration parameters:Configure your HIKARICPIdleTimeoutandMaxlifetimeSettings to being one minute less than theWait_timeoutof MySQL. For systems with a Java connection pool, it is recommended that MySQL wait_timeout use the default 8-hour (http://www.rackspace.com/knowledge_center/article/ How-to-change-the-mysql-timeout-on-a-server).
Also: For Web projects, remember to configure:destroy-method= "Shutdown"
(original articles, reproduced please indicate the CSDN blog from Clement-xu. )
Copyright NOTICE: This article is the original article, reprint please indicate the CSDN blog which is transferred from Clement-xu.
Why HIKARICP is known as the best performance Java database connection pool, how to configure the use of