Code Monkey home page Code Monkey logo

beecp's Introduction

English|中文

☕ Introduction

BeeCP is a high-performance JDBC connection pool

⬇️ Download

Java7 or higher

<dependency>
   <groupId>com.github.chris2018998</groupId>
   <artifactId>beecp</artifactId>
   <version>3.3.0</version>
</dependency>

Java6

<dependency>
   <groupId>com.github.chris2018998</groupId>
   <artifactId>beecp</artifactId>
   <version>1.6.10</version>
</dependency>

👍 Highlight

1:Single connection threadLocal cache to improve pooling performance

2:Borrower non move waiting, saving queue entry and exit costs

3: Transfer queue reuse, which can transfer connections and exceptions

4:Connection asynchronized-add thread,which can be triggerred by releaser or waiter

🍒 Compare to HikariCP

Item BeeCP HikariCP
Key ThreadLocal + semaphore+ ConcurrentLinkedQueue +Thread FastList + ConcurrentBag + ThreadPoolExecutor
Similarity CAS,Proxy pre-generation,Driver statement cache,Jmx
Difference Balance mode,Hold-timeout,Support XA,Pool clean Pool suspend,Config runtime change
File 32 source files,Jar package 93KB 44 source files,Jar package 158KB
Performance Higher than 40%

Which defects of HikariCP?

1:Closed preparedStatements can be activation, when using MySQ-driver

2:When database down or network failed, getConnection response time == 'connectionTimeout'(if configed value is large,what happen?)

3:Exists transaction leak,when using 'setSavepoint' on connection

.....

Conclusion: faster, simpler, reliabler

🚜 Demo

Its usage is roughly similar to other pool, two reference examples below

👉 Demo1
BeeDataSourceConfig config = new BeeDataSourceConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setJdbcUrl("jdbc:mysql://localhost/test");
config.setUsername("root");
config.setPassword("root");
BeeDataSource ds=new BeeDataSource(config);
Connection con=ds.getConnection();
....
👉 Demo2

application.properties

spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.driverClassName=com.mysql.jdbc.Driver

DataSourceConfig.java

@Configuration
public class DataSourceConfig {
  @Value("${spring.datasource.username}")
  private String user;
  @Value("${spring.datasource.password}")
  private String password;
  @Value("${spring.datasource.url}")
  private String url;
  @Value("${spring.datasource.driverClassName}")
  private String driver;

  @Bean
  @Primary
  @ConfigurationProperties(prefix="spring.datasource")
  public DataSource primaryDataSource() {
    return DataSourceBuilder.create().type(cn.beecp.BeeDataSource.class).build();
  }
}

☀️ If your projects are based on springboot, we recommend BeeCP-Starter to manage your datasource(file configuration, less code, monitor-ui)

📖 Configuration item

🔠 poolName

If not configured, auto generated

🔢 fairMode

Boolean indicator,if true,pool will use fair semaphore and fair transfer policy. default value: false

🔠 initialSize

Size of connections on pool starting,if zero,pool will try to create one.default value: 0

🔢 mxActive

Max reach size of connections in pool.default value: 10

🔠 borrowSemaphoreSize

Size of semaphore in pool. default value: number of CPU cores

🔢 defaultAutoCommit

Value setting on conneciton creating and return, default value: true

🔠 defaultTransactionIsolationCode

Value setting on conneciton creating and return. default value: -999,if not set then read value from first connection

🔢 maxWait

Max wait time for one connection for borrower using 'getConnection'. unit: milliseconds, default value: 8000

🔠 idleTimeout

Max idle time of connections in pool,when reach,then remove from pool.unit: milliseconds, default value: 18000

🔢 holdTimeout

Max no-use time of borrowed connections,when reach,then return them to pool by forced close.unit: milliseconds, default value: 18000

🔠 validTestSql

Connection valid test sql on borrowed. default value: SELECT 1

🔢 validTestTimeout

Max time to get a valid test result. unit:second, default value: 3

🔠 validAssumeTime

Conenction valid assume time after last activity,if borrowed,not need test during the duration.unit: milliseconds, default value: 500

👉 More configuration items

beecp's People

Contributors

chris2018998 avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.