HikariCP
什么?不是有C3P0/DBCP这些成熟的数据库连接池吗?一直用的好好的,为什么又搞出一个BoneCP来?因为,传说中BoneCP在快速这个特点上做到了极致,官方数据是C3P0等的25倍左右。不相信?其实我也不怎么信。可是,有图有真相啊(图片来自BoneCP官网:http://jolbox.com/benchmarks.html):
英文:
constrained 不舒服的,被强迫的,拘泥的;
- 字节码精简:优化代码,直到编译后的字节码最少,这样,CPU缓存可以加载更多的程序代码;
- 优化代理和拦截器:减少代码,例如HikariCP的Statement proxy只有100行代码,只有BoneCP的十分之一;
- 自定义数组类型(FastStatementList)代替ArrayList:避免每次get()调用都要进行range check,避免调用remove()时的从头到尾的扫描;
- 自定义集合类型(ConcurrentBag):提高并发读写的效率;
- 其他针对BoneCP缺陷的优化,比如对于耗时超过一个CPU时间片的方法调用的研究(但没说具体怎么优化)。
使用方法:
you can use the HikariConfig
class like so:
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://localhost:3306/simpsons");
config.setUsername("bart");
config.setPassword("51mp50n");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
HikariDataSource ds = new HikariDataSource(config);
or directly instantiate a HikariDataSource
like so:
HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl("jdbc:mysql://localhost:3306/simpsons");
ds.setUsername("bart");
ds.setPassword("51mp50n");
...
or property file based:
HikariConfig config = new HikariConfig("some/path/hikari.properties");
HikariDataSource ds = new HikariDataSource(config);
Example property file:
dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
dataSource.user=test
dataSource.password=test
dataSource.databaseName=mydb
dataSource.portNumber=5432
dataSource.serverName=localhost
- <!-- Hikari Datasource -->
- <bean id="dataSourceHikari" class="com.zaxxer.hikari.HikariDataSource" destroy-method="shutdown">
- <!-- <property name="driverClassName" value="${db.driverClass}" /> --> <!-- 无需指定,除非系统无法自动识别 -->
- <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}" />
- <!-- 连接只读数据库时配置为true, 保证安全 -->
- <property name="readOnly" value="false" />
- <!-- 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 缺省:30秒 -->
- <property name="connectionTimeout" value="30000" />
- <!-- 一个连接idle状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟 -->
- <property name="idleTimeout" value="600000" />
- <!-- 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';) -->
- <property name="maxLifetime" value="1800000" />
- <!-- 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count) -->
- <property name="maximumPoolSize" value="15" />
- </bean>
下载地址及依赖环境
======================
1 下载地址
http://mvnrepository.com/artifact/com.zaxxer/HikariCP
2 Git主页
https://github.com/brettwooldridge/HikariCP
3 依赖包
log4j-1.2.16.jar
slf4j-api-1.5.10.jar
slf4j-log4j12-1.5.10.jar
4 版本支持
Java 7 and Java 8 maven artifact:
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.4.5</version>
</dependency>
Java 6 maven artifact (maintenance mode):
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java6</artifactId>
<version>2.3.13</version>
</dependency>
What do “Connection Cycle ops/ms” and “Statement Cycle ops/ms” mean in the context of a microbenchmark of a connection pool?
In the context of a pool, we're trying to measure just the speed of pool operations -- so a "no-op" DataSource is used that does not perform actually connections or SQL. Connection Cycles measures how fast a connection can be obtained from the pool and then returned. Basically, this:
Connection conn = dataSource.getConnection();
conn.close();
Where dataSource
is a HikariDataSource (pool) and conn.close()
actually returns the Connection to the pool instead of closing the underlying DB Connection.
The Statement Cycle benchmark performs:
Statement statement = connection.createStatement();
statement.execute();
statement.close();
Because connection pools wrap Statement
(and it's subclasses) with proxies, and track them so that they can be closed when the Connection is closed, there is overhead associated with both tracking the Statement
and invoking against it. This micro-benchmark measures both.
proxool
更新时间截止2008年。速度可以,稳定性稍差,发较高的情况下会出错。
c3p0
太古老,代码及其复杂,不利于维护。貌似都比它强。
dbcp
是 apache 上的一个 java 连接池项目,也是 tomcat 使用的连接池组件。
druid
功能比较全面,且扩展性较好,比较方便对jdbc接口进行监控跟踪等。
BoneCP
13年前最快的连接池项目。2013年后不再更新,心灰意冷。
HikariCP
光连接池
HikariCP的更多相关文章
- 为什么HikariCP被号称为性能最好的Java数据库连接池,怎样配置使用
HiKariCP是数据库连接池的一个后起之秀.号称性能最好.能够完美地PK掉其它连接池. 原文地址:http://blog.csdn.net/clementad/article/details/469 ...
- spring boot + mybatis + hikaricp + swagger2 + jasypt
好久没写博客了记录下写过的东西,别到时候又忘了 文章前提:前面开发项目的时候数据池一直用的阿里的druid,这个数据池吧也不能说它不好,为什么现在想改成hikaricp数据池呢,完全是实用项目需要.d ...
- HikariCP Druid比较
HikariCP Github地址: https://github.com/brettwooldridge/HikariCP HikariCP是数据库连接池,而且是号称史上最快的, SpringBoo ...
- Spring Boot 2 + MariaDB + HikariCP基础实例
在已有SpringBoot工程中基于MariaDB驱动使用HikariCP 连接池 环境:SpringBoot2.0.2 .MariaDB驱动版本2.2.3.HikariCP2.7.8 1.在Spri ...
- Spring Boot 数据库连接池 HikariCP
简介 HikariCP 来源于日语,「光」的意思,意味着它很快!可靠的数据源,spring boot2.0 已经将 HikariCP 做为了默认的数据源链接池. 官网详细地说明了HikariCP所做的 ...
- Spring Boot HikariCP 一 ——集成多数据源
其实这里介绍的东西主要是参考的另外一篇文章,数据库读写分离的. 参考文章就把链接贴出来,里面有那位的代码,简单明了https://gitee.com/comven/dynamic-datasource ...
- 五大理由分析Springboot 2.0为什么选择HikariCP
五大理由分析Springboot 2.0为什么选择HikariCP 2018-05-04 工匠小猪猪 占小狼的博客 本文非原创,是工匠小猪猪的技术世界搜集了一些HikariCP相关的资料整理给大家的介 ...
- mybatis整合hikariCP(非spring)
mybatis整合hikariCP(非spring) 一.配置hikariCP典型的配置文件hikariPool.properties jdbcUrl=jdbc:mysql://localhost:3 ...
- springboot 2.0 mariadb hikari-cp连接池
直到今天 2018年9月29日 10:00:38 ,hikari-cp 在maven 官方仓库最新版本为2.6 SpringBoot 2.0.5 控制台输出,默认的是 2.7.9 spring-boo ...
随机推荐
- 3942: [Usaco2015 Feb]Censoring [KMP]
3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 375 Solved: 206[Subm ...
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 外部服务调用、内部服务调用优化,面向服务化的
现在的信息系统越来越复杂,越来越庞大,不仅需要内部是一个整体,而且还需要提供很多对外的服务调用. 1:别人如何调用最方便?用不同的开发语言调用.例如app.手持设备.服务器.2:服务的返回状态是什么样 ...
- java并发编程学习: 原子变量(CAS)
先上一段代码: package test; public class Program { public static int i = 0; private static class Next exte ...
- Netron开发快速上手(二):Netron序列化
Netron是一个C#开源图形库,可以帮助开发人员开发出类似Visio的作图软件.本文继前文”Netron开发快速上手(一)“讨论如何利用Netron里的序列化功能快速保存自己开发的图形对象. 一个用 ...
- iOS 关于字体根据不同屏幕尺寸等比适配的问题(zz)
http://www.jianshu.com/p/5815e81abb52 背景 去年的六月份开始了一个新的项目,此项目支持的设备从4S开始一直到6+,也就是说屏幕的尺寸最小的320x480 最大的1 ...
- .NET添加时间戳防止重放攻击
如过客户端在向服务端接口进行请求,如果请求信息进行了加密处理,被第三方截取到请求包,虽然第三方无法解密获取其中的数据,但是可以使用该请求包进行重复的请求操作.如果服务端不进行防重放攻击,就会参数服务器 ...
- .net core 一次坑爹的类库打包过程
众所周知,.net core 跨平台类库引用一定要通过nuget获得.(如有问题,欢迎指出) 打包 将普通.net project转换成.net core 的类库有两种方式: 1.新建.net cor ...
- Linux--目录结构解释(转)
/ root --- 启动Linux时使用的一些核心文件.如操作系统内核.引导程序Grub等. home --- 存储普通用户的个人文件 ftp --- 用户所有服务 httpd samba user ...
- Html页面禁止鼠标左键复制
<body leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false' onselectst ...
- ARM学习 之 如何在向内核写入系统调用
本文主要介绍两个例子:1-系统调用打印“hello kernel” 2-驱动开发板的蜂鸣器 使用的是友善之臂(Friendly ARM)的开发板,三星2440 =================== ...