Java数据库连接池 BoneCP

BoneCP是一款轻量级的JDBC连接池实现,其大小仅为几十K。本文通过一系列的单线程及多线程测试,对比了不同场景下BoneCP的表现,并详细记录了配置参数及其对性能的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

BoneCP 是一个开源的快速的 JDBC 连接池。BoneCP很小,只有四十几K(运行时需要log4jGoogle Collections的支持,这二者加起来就不小了),而相比之下 C3P0 要六百多K。另外个人觉得 BoneCP 有个缺点是,JDBC驱动的加载是在连接池之外的,这样在一些应用服务器的配置上就不够灵活。

当然,体积小并不是 BoneCP 优秀的原因,BoneCP 到底有什么突出的地方呢,请看看下面的性能测试报告:

Single Thread
  • 1,000,000 get connection / release connection requests
  • No delay between getting/releasing connection.
  • Pool size range: 20-50.
  • Acquire increment: 5
  • Helper threads: 1
  • Partition count: 1
Multi-Thread
  • 500 threads each attempting 100 get/release connection
  • No delay between getting/releasing connection.
  • Pool size range: 50-200.
  • Acquire increment: 5
  • Helper threads: 5
Multi-Thread 10ms delay
  • 500 threads each attempting 100 get/release connection
  • We introduce a 10ms delay (Thread.sleep()) between the acquire connection and the release connection to simulate work being done with the connection.
  • Pool size range: 50-200.
  • Acquire increment: 5
  • Helper threads: 5
Multi-Thread 25ms delay
  • 500 threads each attempting 100 get/release connection
  • We introduce a 25ms delay (Thread.sleep()) between the acquire connection and the release connection to simulate work being done with the connection.
  • Pool size range: 50-200.
  • Acquire increment: 5
  • Helper threads: 5
Multi-Thread 50ms delay
  • 500 threads each attempting 100 get/release connection
  • We introduce a 50ms delay (Thread.sleep()) between the acquire connection and the release connection to simulate work being done with the connection.
  • Pool size range: 50-200.
  • Acquire increment: 5
  • Helper threads: 5
Multi-Thread 75ms delay
  • 500 threads each attempting 100 get/release connection
  • We introduce a 75ms delay (Thread.sleep()) between the acquire connection and the release connection to simulate work being done with the connection.
  • Pool size range: 50-200.
  • Acquire increment: 5
  • Helper threads: 5
Prepared Statement (single threaded)
  • Fetches a single connection then calls 1,000,000 connection.prepareStatement(...) followed by an immediate statement close.
  • No delay between calls
  • Max statements: 30
  • Max statements per connection: 30
  • Helper threads: 5
Prepared Statement (multi-threaded)
  • 500 Threads each attempting 100 get/release connection with no delays. After obtaining a connection, make a call to connection.prepareStatement(...) followed by a close statement request.
  • No delay between calls
  • Pool size range: 50-200.
  • Acquire increment: 5.
  • Helper threads: 5
Prepared Statement (multi-threaded, 10ms delay)
  • 500 Threads each attempting 100 get/release connection with no delays. After obtaining a connection, make a call to connection.prepareStatement(...) followed by a close statement request.
  • 10ms delay between open connection/release connection to simulate work done by the application.
  • Pool size range: 50-200.
  • Acquire increment: 5.
  • Helper threads: 5
Prepared Statement (multi-threaded, 25ms delay)
  • 500 Threads each attempting 100 get/release connection with no delays. After obtaining a connection, make a call to connection.prepareStatement(...) followed by a close statement request.
  • 25ms delay between open connection/release connection to simulate work done by the application.
  • Pool size range: 50-200.
  • Acquire increment: 5.
  • Helper threads: 5
Prepared Statement (multi-threaded, 50ms delay)
  • 500 Threads each attempting 100 get/release connection with no delays. After obtaining a connection, make a call to connection.prepareStatement(...) followed by a close statement request.
  • 50ms delay between open connection/release connection to simulate work done by the application.
  • Pool size range: 50-200.
  • Acquire increment: 5.
  • Helper threads: 5
Prepared Statement (multi-threaded, 75ms delay)
  • 500 Threads each attempting 100 get/release connection with no delays. After obtaining a connection, make a call to connection.prepareStatement(...) followed by a close statement request.
  • 75ms delay between open connection/release connection to simulate work done by the application.
  • Pool size range: 50-200.
  • Acquire increment: 5.
  • Helper threads: 5

转载于:https://www.cnblogs.com/xyopensource/archive/2010/02/14/1668111.html

Java的世界里,HttpClient 是一个功能强大的Http请求库,然而接口非常复杂,设计上遵从正交性,简单的请求也需要写比较多的代码,更不要说隐藏在各种细节里面的高级用法了。Requests,  是一个模仿python requests 模块来设计的Http lib,拥有简单而灵活的API,在容易使用的同时,又能够满足各种高级定制的使用,可是说是当前最好用的Java Http Client Lib。 简单的请求示例:String url = ...; Response resp = Requests.get(url).text(); // post 和其他方法 resp = Requests.post(url).text(); resp = Requests.head(url).text(); //读取Http Response  int statusCode = resp.getStatusCode(); Headers headers = resp.getHeaders(); Cookies cookies = resp.getCookies(); String body = resp.getBody(); //response 返回其他类型 resp = Requests.get(url).text("UTF-8"); // get response as bytes Response resp1 = Requests.get(url).bytes(); // save response as file  Response resp2 = Requests.get(url).file("/path/to/save/file"); // url 参数: Map map = new HashMap(); map.put("k1", "v1"); map.put("k2", "v2"); Response resp = Requests.get(url).param("key1", "value1").params(map)         //.params(new Parameter(...), new Parameter(...))         .text(); // 请求头 Response resp = Requests.get(url).header("key1", "value1").headers(map)         //.headers(new Header(...), new Header(...))         .text(); // 添加Cookie: Map cookies = new HashMap(); Response resp = Requests.get(url).cookie("key1", "value1").cookies(map)         //.cookies(new Cookie(...), new Cookie(...))         .text(); //  设置 userAgent Response resp = Requests.get(url).userAgent(userAgent).text(); // 增加请求数据(post, put, patch方法) // send form-encoded data. x-www-form-urlencoded header will be send automatically Response resp = Requests.post(url).data(map).text(); // send string data String str = ...; resp = Requests.post(url).data(str, "UTF-8").text(); // send from inputStream InputStream in = ... resp = Requests.post(url).data(in).text(); // multipart 请求, 用于文件上传: Response resp = Requests.post(url).data(map).multiPart("ufile", "/path/to/file")         .multiPart(..., ...).text();请求设置://禁止自动重定向
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值