不同的數(shù)據(jù)庫(kù)連接池(DBCP,C3P0,Druid,Hikari)下對(duì)mysql的insert和select性能對(duì)比

分別測(cè)試4中連接池(DBCP、C3P0、Druid、Hikari)的表現(xiàn)情況。

1.環(huán)境準(zhǔn)備

1.1 連接池配置

1.1.1 DBCP

gradle導(dǎo)入包;

implementation 'org.apache.commons:commons-dbcp2:2.9.0'

application.yml配置:

# DBCP
spring.datasource.url: jdbc:mysql://192.168.162.49:3306/gts?useSSL=false&autoReconnect=true&characterEncoding=UTF-8
spring.datasource.username: gts
spring.datasource.password: mysql
spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver
spring.datasource.type: org.apache.commons.dbcp2.BasicDataSource

需要指定spring.datasource.type。

1.1.2 C3P0

gradle導(dǎo)入包:

implementation 'com.mchange:c3p0:0.9.5.5'

application.yml配置:

## C3P0
spring.datasource.jdbcUrl: jdbc:mysql://192.168.162.49:3306/gts?useSSL=false&autoReconnect=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.user: gts
spring.datasource.password: mysql
spring.datasource.driverClass: com.mysql.cj.jdbc.Driver
spring.datasource.type: com.mchange.v2.c3p0.ComboPooledDataSource

需要指定spring.datasource.type。
C3P0不能直接復(fù)用springDataSource的默認(rèn)配置,需要單獨(dú)指定一個(gè)類:

package com.dhb.gts.javacourse.week6.mysqltest;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class C3p0DatasourceConfig {

    @Bean(name = "dataSource")
    @Qualifier(value = "dataSource")
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dataSource() {
               return DataSourceBuilder.create().type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build();
    }
    
}

1.1.3 Druid

gradle導(dǎo)入包:

implementation 'com.alibaba:druid:1.2.6'

application.yml配置:

# 數(shù)據(jù)源配置 durid
spring.datasource.url: jdbc:mysql://192.168.162.49:3306/gts?useSSL=false&autoReconnect=true&characterEncoding=UTF-8
spring.datasource.username: gts
spring.datasource.password: mysql
spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver
spring.datasource.type: com.alibaba.druid.pool.DruidDataSource

需要指定spring.datasource.type。

1.1.4 Hikari

gradle導(dǎo)入包:

implementation 'com.zaxxer:HikariCP:4.0.3'

由于Hikari是springboot中 tomcat的默認(rèn)連接池,因此無(wú)需指定type。

#數(shù)據(jù)源配置 默認(rèn)Hikari
spring.datasource.url: jdbc:mysql://192.168.162.49:3306/gts?useSSL=false&autoReconnect=true&characterEncoding=UTF-8
spring.datasource.username: gts
spring.datasource.password: mysql
spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver

1.1.5 通用配置

spring.datasource.initialSize: 5
spring.datasource.minIdle: 5
spring.datasource.maxActive: 20
spring.datasource.maxWait: 60000
spring.datasource.timeBetweenEvictionRunsMillis: 60000
spring.datasource.validationQuery: SELECT 1
spring.datasource.testWhileIdle: true
spring.datasource.testOnBorrow: false
spring.datasource.testOnReturn: false
spring.datasource.poolPreparedStatements: true
spring.datasource.maxPoolPreparedStatementPerConnectionSize: 20
spring.datasource.filters: stat

1.2 測(cè)試的API

訂單查詢類:

package com.dhb.gts.javacourse.week6.mysqltest;

import com.alibaba.fastjson.JSON;
import com.dhb.gts.javacourse.fluent.dao.intf.OrderSummaryDao;
import com.dhb.gts.javacourse.fluent.entity.OrderSummaryEntity;
import com.dhb.gts.javacourse.fluent.helper.OrderSummaryMapping;
import com.dhb.gts.javacourse.fluent.mapper.OrderDetailMapper;
import com.dhb.gts.javacourse.fluent.mapper.OrderSummaryMapper;
import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
public class QueryOrderTable {
    
    @Autowired
    OrderSummaryDao orderSummaryDao;

    @RequestMapping("/queryByKey")
    public String queryByKey(String key) {
        Stopwatch stopwatch = Stopwatch.createStarted();
        Integer orde_id = Integer.parseInt(key);
        OrderSummaryEntity entity = orderSummaryDao.selectById(orde_id);
        stopwatch.stop();
        System.out.println("通過(guò)key查詢,走索引耗時(shí):" + stopwatch);
        return JSON.toJSONString(entity);
    }

    @RequestMapping("/queryByOther")
    public String queryByKey(String orderNo, String expressNo) {
        Stopwatch stopwatch = Stopwatch.createStarted();
        Map<String, Object> map = new HashMap<>();
        if (Strings.isNotEmpty(orderNo)) {
            Integer order_no = Integer.parseInt(orderNo);
            map.put(OrderSummaryMapping.orderNo.column, order_no);
        } else if (Strings.isNotEmpty(expressNo)) {
            map.put(OrderSummaryMapping.expressNo.column, expressNo);
        }
        List<OrderSummaryEntity> entitys = orderSummaryDao.selectByMap(map);
        stopwatch.stop();
        System.out.println("不通過(guò)key查詢,全表掃描耗時(shí):" + stopwatch);
        return JSON.toJSONString(entitys);
    }
}

1.3 測(cè)試工具

通過(guò)瀏覽器和ApacheBench.

2.批量寫(xiě)入測(cè)試

在數(shù)據(jù)庫(kù)存量為100萬(wàn)條數(shù)據(jù)的基礎(chǔ)上,分別寫(xiě)入10萬(wàn)條數(shù)據(jù),每個(gè)批次為1000。情況如下:

2.1 C3P0

http://127.0.0.1:8084/randomInsertOrderTable?total=100000&batch=1000

2021-09-14 10:12:38.765  INFO 15256 --- [nio-8084-exec-2] c.d.g.j.w.m.RandomInsertOrderTable       : 總計(jì)插入批次共101次,其中,最大耗時(shí):629ms 最小耗時(shí):172ms 平均耗時(shí):260.03960396039605ms
2021-09-14 10:12:38.765  INFO 15256 --- [nio-8084-exec-2] c.d.g.j.w.m.RandomInsertOrderTable       : 批量插入數(shù)據(jù) totalSize [100000]... 共耗時(shí)[26300] ms

http://127.0.0.1:8084/randomInsertOrderTable?total=100000&batch=1000

2021-09-14 10:14:08.988  INFO 15256 --- [nio-8084-exec-5] c.d.g.j.w.m.RandomInsertOrderTable       : 總計(jì)插入批次共101次,其中,最大耗時(shí):563ms 最小耗時(shí):201ms 平均耗時(shí):274.8217821782178ms
2021-09-14 10:14:08.988  INFO 15256 --- [nio-8084-exec-5] c.d.g.j.w.m.RandomInsertOrderTable       : 批量插入數(shù)據(jù) totalSize [100000]... 共耗時(shí)[27784] ms

2.2 DBCP

DBCP:
http://127.0.0.1:8084/randomInsertOrderTable?total=100000&batch=1000

2021-09-13 20:40:05.859  INFO 18340 --- [nio-8084-exec-2] c.d.g.j.w.m.RandomInsertOrderTable       : 總計(jì)插入批次共101次,其中,最大耗時(shí):364ms 最小耗時(shí):164ms 平均耗時(shí):246.54455445544554ms
2021-09-13 20:40:05.859  INFO 18340 --- [nio-8084-exec-2] c.d.g.j.w.m.RandomInsertOrderTable       : 批量插入數(shù)據(jù) totalSize [100000]... 共耗時(shí)[24925] ms

第二次

2021-09-13 20:41:13.099  INFO 18340 --- [nio-8084-exec-5] c.d.g.j.w.m.RandomInsertOrderTable       : 總計(jì)插入批次共101次,其中,最大耗時(shí):724ms 最小耗時(shí):192ms 平均耗時(shí):265.96039603960395ms
2021-09-13 20:41:13.099  INFO 18340 --- [nio-8084-exec-5] c.d.g.j.w.m.RandomInsertOrderTable       : 批量插入數(shù)據(jù) totalSize [100000]... 共耗時(shí)[26891] ms

2.3 Druid

http://127.0.0.1:8084/randomInsertOrderTable?total=100000&batch=1000

2021-09-13 19:50:11.037  INFO 8308 --- [nio-8084-exec-1] c.d.g.j.w.m.RandomInsertOrderTable       : 總計(jì)插入批次共101次,其中,最大耗時(shí):684ms 最小耗時(shí):193ms 平均耗時(shí):310.4257425742574ms
2021-09-13 19:50:11.037  INFO 8308 --- [nio-8084-exec-1] c.d.g.j.w.m.RandomInsertOrderTable       : 批量插入數(shù)據(jù) totalSize [100000]... 共耗時(shí)[31366] ms

第二次測(cè)試:

2021-09-13 19:53:37.951  INFO 8308 --- [nio-8084-exec-6] c.d.g.j.w.m.RandomInsertOrderTable       : 總計(jì)插入批次共101次,其中,最大耗時(shí):599ms 最小耗時(shí):176ms 平均耗時(shí):231.1980198019802ms
2021-09-13 19:53:37.951  INFO 8308 --- [nio-8084-exec-6] c.d.g.j.w.m.RandomInsertOrderTable       : 批量插入數(shù)據(jù) totalSize [100000]... 共耗時(shí)[23367] ms

2.4 Hikari

http://127.0.0.1:8084/randomInsertOrderTable?total=100000&batch=1000

2021-09-13 20:58:46.881  INFO 19084 --- [nio-8084-exec-1] c.d.g.j.w.m.RandomInsertOrderTable       : 總計(jì)插入批次共101次,其中,最大耗時(shí):565ms 最小耗時(shí):195ms 平均耗時(shí):270.34653465346537ms
2021-09-13 20:58:46.882  INFO 19084 --- [nio-8084-exec-1] c.d.g.j.w.m.RandomInsertOrderTable       : 批量插入數(shù)據(jù) totalSize [100000]... 共耗時(shí)[27339] ms

http://127.0.0.1:8084/randomInsertOrderTable?total=100000&batch=1000

2021-09-13 21:00:35.252  INFO 19084 --- [nio-8084-exec-9] c.d.g.j.w.m.RandomInsertOrderTable       : 總計(jì)插入批次共101次,其中,最大耗時(shí):681ms 最小耗時(shí):187ms 平均耗時(shí):263.23762376237624ms
2021-09-13 21:00:35.252  INFO 19084 --- [nio-8084-exec-9] c.d.g.j.w.m.RandomInsertOrderTable       : 批量插入數(shù)據(jù) totalSize [100000]... 共耗時(shí)[26604] ms

2.5 匯總

測(cè)試次數(shù) C3P0 DBCP Druid Hikari
第一次 26.3s 24.9s 31.3s 27.3s
第二次 27.7s 26.8s 23.3s 26.6s

結(jié)論:不同的數(shù)據(jù)庫(kù)連接池,在單線程批次insert的時(shí)候性能差異不大。

3 主鍵查詢

3.1 DBCP

http://127.0.0.1:8084/queryByKey?key=100039

通過(guò)key查詢,走索引耗時(shí):4.932 ms
通過(guò)key查詢,走索引耗時(shí):3.223 ms
通過(guò)key查詢,走索引耗時(shí):4.227 ms

3.2 C3P0

http://127.0.0.1:8084/queryByKey?key=100045

通過(guò)key查詢,走索引耗時(shí):2.763 ms
通過(guò)key查詢,走索引耗時(shí):1.754 ms
通過(guò)key查詢,走索引耗時(shí):2.151 ms

3.3 Druid

http://127.0.0.1:8084/queryByKey?key=100036

通過(guò)key查詢,走索引耗時(shí):2.606 ms
通過(guò)key查詢,走索引耗時(shí):2.303 ms
通過(guò)key查詢,走索引耗時(shí):1.980 ms

3.4 Hikari

http://127.0.0.1:8084/queryByKey?key=100042

通過(guò)key查詢,走索引耗時(shí):3.658 ms
通過(guò)key查詢,走索引耗時(shí):3.548 ms
通過(guò)key查詢,走索引耗時(shí):2.974 ms

3.5 匯總

測(cè)試次數(shù) DBCP C3P0 Druid Hikari
第一次 4.9ms 2.7ms 2.6ms 3.6ms
第二次 3.2ms 1.7ms 2.3ms 3.1ms
第三次 4.2ms 2.1ms 2.1ms 2.9ms

結(jié)論,4種連接池對(duì)單次查詢的效率影響不大,都在毫秒級(jí),差異主要是由于數(shù)據(jù)庫(kù)數(shù)據(jù)量大小的差異,數(shù)據(jù)越多可能會(huì)導(dǎo)致查詢耗時(shí)增加。

4.全表掃描查詢

4.1 DBCP

http://127.0.0.1:8084/queryByOther?orderNo=100793

不通過(guò)key查詢,全表掃描耗時(shí):3.108 s
不通過(guò)key查詢,全表掃描耗時(shí):3.037 s
不通過(guò)key查詢,全表掃描耗時(shí):3.186 s

4.2 C3P0

http://127.0.0.1:8084/queryByOther?orderNo=100812

不通過(guò)key查詢,全表掃描耗時(shí):3.936 s
不通過(guò)key查詢,全表掃描耗時(shí):3.135 s
不通過(guò)key查詢,全表掃描耗時(shí):3.127 s

4.3 Druid

http://127.0.0.1:8084/queryByOther?orderNo=100790

不通過(guò)key查詢,全表掃描耗時(shí):2.181 s
不通過(guò)key查詢,全表掃描耗時(shí):2.633 s
不通過(guò)key查詢,全表掃描耗時(shí):2.193 s

4.4 Hikari

http://127.0.0.1:8084/queryByOther?orderNo=100797

不通過(guò)key查詢,全表掃描耗時(shí):3.376 s
不通過(guò)key查詢,全表掃描耗時(shí):3.453 s
不通過(guò)key查詢,全表掃描耗時(shí):3.063 s

4.5 匯總

測(cè)試次數(shù) DBCP C3P0 Druid Hikari
第一次 3.1s 3.9s 2.6ms 3.3s
第二次 3.0s 3.1s 2.3ms 3.4s
第三次 3.1s 3.1s 2.1ms 3.0s

結(jié)論,如果不通過(guò)索引,全表掃描的話,在100萬(wàn)級(jí)數(shù)據(jù)量上進(jìn)行全表掃描的時(shí)間將是通過(guò)索引時(shí)間的1000倍,這個(gè)時(shí)間達(dá)到了3秒左右。
需要注意的是,上述的測(cè)試每次都是測(cè)試的不同數(shù)據(jù),以避免mysql數(shù)據(jù)庫(kù)的緩存。

5 采用apachebench 進(jìn)行負(fù)載測(cè)試

由于前面每個(gè)場(chǎng)景的測(cè)試過(guò)程中,通過(guò)主鍵的查詢效率最高,另外由于mysql在第二次查詢的時(shí)候,會(huì)對(duì)數(shù)據(jù)進(jìn)行緩存,那么現(xiàn)在可以通過(guò)apachebench查詢同一條數(shù)據(jù),這條數(shù)據(jù)的性能在走緩存之后,
查詢效率是最高的,通過(guò)這種方式來(lái)對(duì)4種連接池進(jìn)行負(fù)載測(cè)試,測(cè)試結(jié)果的差異,就大致可以認(rèn)為是4種連接池的差異了。
4種連接池的通用配置參數(shù)都相同。

5.1 DBCP

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 5 -N 60

Starting at 2021/9/13 20:43:53
[Press C to stop the test]
116692  (RPS: 1838.5)
---------------Finished!----------------
Finished at 2021/9/13 20:44:56 (took 00:01:03.6372882)
Status 200:    116692

RPS: 1908.2 (requests/second)
Max: 45ms
Min: 0ms
Avg: 2ms

  50%   below 2ms
  60%   below 2ms
  70%   below 2ms
  80%   below 2ms
  90%   below 3ms
  95%   below 5ms
  98%   below 8ms
  99%   below 11ms
99.9%   below 22ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 10 -N 60

Starting at 2021/9/13 20:45:35
[Press C to stop the test]
151850  (RPS: 2389.2)
---------------Finished!----------------
Finished at 2021/9/13 20:46:39 (took 00:01:03.7269118)
Status 200:    151850

RPS: 2482.5 (requests/second)
Max: 68ms
Min: 1ms
Avg: 3.4ms

  50%   below 3ms
  60%   below 3ms
  70%   below 3ms
  80%   below 4ms
  90%   below 6ms
  95%   below 8ms
  98%   below 13ms
  99%   below 17ms
99.9%   below 31ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 20 -N 60

Starting at 2021/9/13 20:46:56
[Press C to stop the test]
153168  (RPS: 2403.7)
---------------Finished!----------------
Finished at 2021/9/13 20:48:00 (took 00:01:03.8479386)
Status 200:    153168

RPS: 2504.4 (requests/second)
Max: 124ms
Min: 1ms
Avg: 7.3ms

  50%   below 6ms
  60%   below 7ms
  70%   below 8ms
  80%   below 9ms
  90%   below 11ms
  95%   below 15ms
  98%   below 20ms
  99%   below 25ms
99.9%   below 55ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 30 -N 60

Starting at 2021/9/13 20:55:02
[Press C to stop the test]
139871  (RPS: 2198.8)
---------------Finished!----------------
Finished at 2021/9/13 20:56:06 (took 00:01:03.7289551)
Status 200:    139871

RPS: 2288.4 (requests/second)
Max: 416ms
Min: 1ms
Avg: 12.3ms

  50%   below 10ms
  60%   below 11ms
  70%   below 13ms
  80%   below 16ms
  90%   below 21ms
  95%   below 26ms
  98%   below 34ms
  99%   below 41ms
99.9%   below 68ms

5.2 C3P0

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 5 -N 60

Starting at 2021/9/14 10:16:28
[Press C to stop the test]
177537  (RPS: 2795.5)
---------------Finished!----------------
Finished at 2021/9/14 10:17:31 (took 00:01:03.6954500)
Status 200:    177537

RPS: 2901.6 (requests/second)
Max: 153ms
Min: 0ms
Avg: 1.2ms

  50%   below 1ms
  60%   below 1ms
  70%   below 1ms
  80%   below 1ms
  90%   below 2ms
  95%   below 2ms
  98%   below 4ms
  99%   below 7ms
99.9%   below 16ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 10 -N 60

Starting at 2021/9/14 10:18:19
[Press C to stop the test]
219027  (RPS: 3436.9)
---------------Finished!----------------
Finished at 2021/9/14 10:19:22 (took 00:01:03.8997966)
Status 200:    219027

RPS: 3580.4 (requests/second)
Max: 186ms
Min: 0ms
Avg: 2.2ms

  50%   below 2ms
  60%   below 2ms
  70%   below 2ms
  80%   below 3ms
  90%   below 4ms
  95%   below 5ms
  98%   below 9ms
  99%   below 12ms
99.9%   below 35ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 20 -N 60

Starting at 2021/9/14 10:37:44
[Press C to stop the test]
194916  (RPS: 3060.2)
---------------Finished!----------------
Finished at 2021/9/14 10:38:47 (took 00:01:03.7583865)
Status 200:    194916

RPS: 3192 (requests/second)
Max: 164ms
Min: 0ms
Avg: 5.5ms

  50%   below 3ms
  60%   below 4ms
  70%   below 5ms
  80%   below 6ms
  90%   below 9ms
  95%   below 18ms
  98%   below 35ms
  99%   below 45ms
99.9%   below 73ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 30 -N 60

Starting at 2021/9/14 10:41:14
[Press C to stop the test]
177592  (RPS: 2794.4)
---------------Finished!----------------
Finished at 2021/9/14 10:42:18 (took 00:01:03.6924274)
Status 200:    177594

RPS: 2905.8 (requests/second)
Max: 195ms
Min: 0ms
Avg: 9.3ms

  50%   below 5ms
  60%   below 6ms
  70%   below 8ms
  80%   below 12ms
  90%   below 21ms
  95%   below 34ms
  98%   below 50ms
  99%   below 63ms
99.9%   below 114ms

5.3 Druid

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 5 -N 60

Starting at 2021/9/13 20:21:08
[Press C to stop the test]
175187  (RPS: 2755.2)
---------------Finished!----------------
Finished at 2021/9/13 20:22:12 (took 00:01:03.7623277)
Status 200:    175187

RPS: 2864.2 (requests/second)
Max: 38ms
Min: 0ms
Avg: 1.3ms

  50%   below 1ms
  60%   below 1ms
  70%   below 1ms
  80%   below 1ms
  90%   below 2ms
  95%   below 2ms
  98%   below 4ms
  99%   below 7ms
99.9%   below 14ms

sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 10 -N 60

Starting at 2021/9/13 20:02:50
[Press C to stop the test]
212730  (RPS: 3351)1)
---------------Finished!----------------
Finished at 2021/9/13 20:03:54 (took 00:01:03.5864881)
Status 200:    212730

RPS: 3481.4 (requests/second)
Max: 81ms
Min: 0ms
Avg: 2.2ms

  50%   below 2ms
  60%   below 2ms
  70%   below 2ms
  80%   below 3ms
  90%   below 4ms
  95%   below 5ms
  98%   below 9ms
  99%   below 13ms
99.9%   below 35ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 20 -N 60

Starting at 2021/9/13 20:11:50
[Press C to stop the test]
203228  (RPS: 3200)1)
---------------Finished!----------------
Finished at 2021/9/13 20:12:54 (took 00:01:03.6655223)
Status 200:    203228

RPS: 3322.7 (requests/second)
Max: 157ms
Min: 0ms
Avg: 5.3ms

  50%   below 4ms
  60%   below 4ms
  70%   below 5ms
  80%   below 6ms
  90%   below 8ms
  95%   below 13ms
  98%   below 27ms
  99%   below 38ms
99.9%   below 70ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 30 -N 60

Starting at 2021/9/13 20:16:23
[Press C to stop the test]
181003  (RPS: 2844.4)
---------------Finished!----------------
Finished at 2021/9/13 20:17:27 (took 00:01:03.6971351)
Status 200:    181003

RPS: 2964.6 (requests/second)
Max: 177ms
Min: 0ms
Avg: 9.1ms

  50%   below 6ms
  60%   below 7ms
  70%   below 8ms
  80%   below 10ms
  90%   below 16ms
  95%   below 29ms
  98%   below 49ms
  99%   below 61ms
99.9%   below 113ms

5.4 Hikari

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 5 -N 60

Starting at 2021/9/13 21:06:49
[Press C to stop the test]
185323  (RPS: 2913.2)
---------------Finished!----------------
Finished at 2021/9/13 21:07:53 (took 00:01:03.7726191)
Status 200:    185323

RPS: 3030.2 (requests/second)
Max: 45ms
Min: 0ms
Avg: 1.2ms

  50%   below 1ms
  60%   below 1ms
  70%   below 1ms
  80%   below 1ms
  90%   below 2ms
  95%   below 2ms
  98%   below 4ms
  99%   below 6ms
99.9%   below 15ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 10 -N 60

Starting at 2021/9/13 21:08:30
[Press C to stop the test]
225182  (RPS: 3543.7)
---------------Finished!----------------
Finished at 2021/9/13 21:09:34 (took 00:01:03.6733168)
Status 200:    225182

RPS: 3683.4 (requests/second)
Max: 81ms
Min: 0ms
Avg: 2.1ms

  50%   below 1ms
  60%   below 2ms
  70%   below 2ms
  80%   below 2ms
  90%   below 4ms
  95%   below 5ms
  98%   below 9ms
  99%   below 13ms
99.9%   below 26ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 20 -N 60

Starting at 2021/9/13 21:10:13
[Press C to stop the test]
200447  (RPS: 3141.4)
---------------Finished!----------------
Finished at 2021/9/13 21:11:17 (took 00:01:03.9914240)
Status 200:    200447

RPS: 3276.1 (requests/second)
Max: 148ms
Min: 0ms
Avg: 5.3ms

  50%   below 4ms
  60%   below 4ms
  70%   below 5ms
  80%   below 6ms
  90%   below 9ms
  95%   below 14ms
  98%   below 32ms
  99%   below 39ms
99.9%   below 65ms

$ sb -u http://127.0.0.1:8084/queryByKey?key=100036 -c 30 -N 60

Starting at 2021/9/13 21:12:14
[Press C to stop the test]
189749  (RPS: 2983.5)
---------------Finished!----------------
Finished at 2021/9/13 21:13:17 (took 00:01:03.6197358)
189757  (RPS: 2983.6)                   Status 200:    189757

RPS: 3106.4 (requests/second)
Max: 202ms
Min: 0ms
Avg: 8.7ms

  50%   below 6ms
  60%   below 6ms
  70%   below 8ms
  80%   below 10ms
  90%   below 15ms
  95%   below 29ms
  98%   below 46ms
  99%   below 58ms
99.9%   below 108ms

5.5 匯總

通過(guò)apache bench,分別在5、10、20、30等并發(fā)的情況下進(jìn)行測(cè)試:

測(cè)試次數(shù) DBCP C3P0 Druid Hikari
5c 1908.2 R/S 2901.6 R/S 2865.2 R/S 3030.2 R/S
10c 2482.5 R/S 3580.4 R/s 3481.4 R/S 3680.4 R/S
20c 2504.4 R/S 3192 R/S 3322.7 R/S 3276.1 R/S
30c 2288.4 R/S 2905.8 R/S 2964.6 R/S 3106.4 R/S

結(jié)論:
可以通過(guò)上述測(cè)試結(jié)果發(fā)現(xiàn),Hikari > Druid > C3P0 > DBCP。
實(shí)際上Druid與C3P0差距不大。但是Druid具有良好的可監(jiān)控性,比C3P0更值得推薦。DBCP是表現(xiàn)最差的。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容