当前位置:网站首页>The pit of c3p0 leads to concurrent performance problems
The pit of c3p0 leads to concurrent performance problems
2022-04-21 13:51:00 【post_ yuan】
In recent days, I have been doing concurrent stress testing of database combined applications , It is found that the performance of concurrent pressure measurement has not been improved , Through the application log, it is found that the main slowness is to obtain the database connection , Application and use c3p0 How to connect the pool . The main configurations of connection pool are as follows: ,
<dbConnPools>
<dbConnPool id="1" name="afa" type="0">
<property name="User" value="xxx"/>
<property name="Password" value="xxx"/>
<property name="JdbcUrl" value="jdbc:t4jdbc://172.1.1.1:23400,172.1.1.2:23400,172.1.1.3:23400/"/>
<property name="DriverClass" value="org.trafodion.jdbc.t4.T4Driver"/>
<property name="InitialPoolSize" value="64"/>
<property name="MinPoolSize" value="64"/>
<property name="MaxPoolSize" value="128"/>
<property name="AcquireIncrement" value="8"/>
<property name="AcquireRetryAttempts" value="1"/>
<property name="AcquireRetryDelay" value="1000"/>
<property name="MaxIdleTime" value="1800"/>
<property name="MaxIdleTimeExcessConnections" value="0"/>
<property name="MaxConnectionAge" value="40"/>
<property name="CheckoutTimeout" value="0"/>
<property name="AutoCommitOnClose" value="true"/>
<property name="BreakAfterAcquireFailure" value="false"/>
<property name="MaxStatements" value="0"/>
<property name="MaxStatementsPerConnection" value="0"/>
<property name="PropertyCycle" value="0"/>
<property name="UnreturnedConnectionTimeout" value="0"/>
<property name="NumHelperThreads" value="3"/>
</dbConnPool>
Connection pool settings pool size It's not small , But why is it still slow to get database connections . So create locally c3p0 The application is tested .
First download c3p0 Of 2 Drive packages ,c3p0-0.9.5.5.jar And mchange-commons-java-0.2.19.jar, Make sure if you're ready c3p0-config.xml file , The file content is configured according to the above , Then import the driver package of the database .
After completing the above steps , Create two JAVA Code program ,/c3p0test/src/c3p0test/C3P0Test.java And /c3p0test/src/c3p0test/JDBCUtils.java, The project catalogue after completion is as follows

The specific code is as follows ,
package c3p0test;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JDBCUtils {
/**
* 1. Define member variables
*/
private static DataSource ds;
/**
* 2. Read configuration file
*/
static{
ds = new ComboPooledDataSource();
}
/**
* 3. Obtain a connection
*/
public static Connection getConn() throws SQLException {
return ds.getConnection();
}
/**
* 4. Release the connection
*/
public static void close(PreparedStatement pstmt, Connection conn){
close(null,pstmt,conn);
}
public static void close(ResultSet rs, PreparedStatement pstmt, Connection conn){
if(rs!=null){
try {
rs.close();
}catch(Exception e){
e.printStackTrace();
}
}
if(pstmt!=null){
try {
pstmt.close();
}catch(Exception e){
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
package c3p0test;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class C3P0Test {
public static void main(String[] args) {
Connection conn = null;
PreparedStatement pstmt = null;
try {
//1. Get the connection
for (int i=0; i<20; i ++) {
long time1 = System.currentTimeMillis();
conn = JDBCUtils.getConn();
long time2 = System.currentTimeMillis();
System.out.println("get connection 1:"+(time2-time1));
}
//2. Definition sql
String sql = "SELECT sysdate FROM dual";
//3. Get database operation object
pstmt = conn.prepareStatement(sql);
//5. Perform the operation
pstmt.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
--c3p0-config.xml file
<c3p0-config>
<default-config>
<property name="driverClass">org.trafodion.jdbc.t4.T4Driver</property>
<property name="jdbcUrl">jdbc:t4jdbc://172.1.1.1:23400,172.1.1.2:23400,172.1.1.3:23400/:</property>
<property name="user">xxx</property>
<property name="password">xxx</property>
<property name="initialPoolSize">10</property>
<property name="minPoolSize">10</property>
<property name="maxPoolSize">20</property>
<property name="numHelperThreads">3</property>
</default-config>
</c3p0-config>
We found that ,<property name=“numHelperThreads”>3</property> This configuration can cause serious connection performance problems , Each time you get a connection, it takes a lot of time , The output of the code is as follows ,
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
MLog initialization issue: slf4j found no binding or threatened to use its (dangerously silent) NOPLogger. We consider the slf4j library not found.
May 12, 2020 8:42:37 Afternoon com.mchange.v2.log.MLog
Information : MLog clients using java 1.4+ standard logging.
May 12, 2020 8:42:38 Afternoon com.mchange.v2.c3p0.C3P0Registry
Information : Initializing c3p0-0.9.5.5 [built 11-December-2019 22:18:33 -0800; debug? true; trace: 10]
May 12, 2020 8:42:38 Afternoon com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
Information : Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1brb12zaa2gzescuwad0r|bebdb06, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.trafodion.jdbc.t4.T4Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1brb12zaa2gzescuwad0r|bebdb06, idleConnectionTestPeriod -> 0, initialPoolSize -> 10, jdbcUrl -> jdbc:t4jdbc://172.31.234.15:23400,172.31.234.16:23400,172.31.234.17:23400/:schema=afa_dz;maxStatements=400;connectionTimeout=0;clipVarchar=1;applicationName=aaaaaaaaaaaaaa, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
get connection 1:5001
get connection 1:0
get connection 1:1
get connection 1:3381
get connection 1:6
get connection 1:37
get connection 1:3328
get connection 1:17
get connection 1:18
get connection 1:3384
get connection 1:20
get connection 1:10
get connection 1:3353
get connection 1:32
get connection 1:6
get connection 1:3349
get connection 1:22
get connection 1:10
get connection 1:3330
get connection 1:40
About parameters numHelperThreads, There are blogs on the Internet that say this is c3p0 The pit of , Readers can refer to the blog c3p0 There are serious problems bug Related description of .
In the revision numHelperThreads For a relatively large value , Such as and maxPoolSize When the same, each connection is fast , The program output is as follows ,
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
MLog initialization issue: slf4j found no binding or threatened to use its (dangerously silent) NOPLogger. We consider the slf4j library not found.
May 12, 2020 8:48:50 Afternoon com.mchange.v2.log.MLog
Information : MLog clients using java 1.4+ standard logging.
May 12, 2020 8:48:51 Afternoon com.mchange.v2.c3p0.C3P0Registry
Information : Initializing c3p0-0.9.5.5 [built 11-December-2019 22:18:33 -0800; debug? true; trace: 10]
May 12, 2020 8:48:51 Afternoon com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
Information : Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1brb12zaa2h7ekk1i5y1i8|bebdb06, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.trafodion.jdbc.t4.T4Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1brb12zaa2h7ekk1i5y1i8|bebdb06, idleConnectionTestPeriod -> 0, initialPoolSize -> 20, jdbcUrl -> jdbc:t4jdbc://172.31.234.15:23400,172.31.234.16:23400,172.31.234.17:23400/:schema=afa_dz;maxStatements=400;connectionTimeout=0;clipVarchar=1;applicationName=aaaaaaaaaaaaaa, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 20, numHelperThreads -> 20, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
get connection 1:5041
get connection 1:0
get connection 1:0
get connection 1:0
get connection 1:0
get connection 1:0
get connection 1:0
get connection 1:0
get connection 1:0
get connection 1:0
get connection 1:0
get connection 1:1
get connection 1:0
get connection 1:0
get connection 1:0
get connection 1:1
get connection 1:0
get connection 1:0
get connection 1:1
get connection 1:0
版权声明
本文为[post_ yuan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211346015640.html
边栏推荐
- 深度学习与图像识别:原理与实践 笔记Day_17
- 【leetcode】516. Longest palindrome subsequence
- Promise -- several key problems
- echart常见的配置项(线、区域、文本)
- Summary of several problems of esgyndb using JDBC UDR to access remote trafodion
- The sales attribute values in sku must be filled in in pairs. Why
- EsgynDB 关于收集core信息的小技巧
- Unittest unit test (V)
- Scroll bar style modification
- Analysis of MySQL connection query cost and cost statistics
猜你喜欢

《商用密码应用与安全性评估》第四章 密码应用安全性评估实施要点-小结

EsgynDB 使用JDBC UDR访问远程Trafodion的几个问题小结

<2021SC@SDUSC>山东大学软件工程应用与实践JPress代码分析(十一)

The sales attribute values in sku must be filled in in pairs. Why

Markdown grammar and test

深度学习与图像识别:原理与实践 笔记Day_18(目标检测)续

The third project - Pacman (2)

mysql-三星索引和cost值成本计算

商用密码应用安全性评估量化评估规则(2021版)

EsgynDB CQD-traf_ lock_ ddl
随机推荐
What does it mean that the AGP transform API is abandoned?
The sales attribute values in sku must be filled in in pairs. Why
Tool function --- get parameters from the address bar
字符串 - 1. 字符串長度 (10 分)C語言標准函數庫中包括 strlen 函數,用於計算字符串的長度。作為練習,我們自己編寫一個功能與之相同的函數。
工具函数---日期格式化
EsgynDB 关于带索引的DELETE性能提升
tooltip显示更多的信息
Color gradient (columns, rings, etc.)
Detailed explanation of JVM memory allocation mechanism
JMM model of concurrent programming and three characteristics of concurrency
Deep understanding of concurrent programming
MySQL high performance business table structure and index design practice
小案例的实现
深度学习与图像识别:原理与实践 笔记Day_11
EsgynDB SQL统计模式下各对象个数
通过区块划分提高随机生成圆球干涉检查的效率
Oracle 备份失败报错ORA-04063: view SYS.KU_RADM_FPTM_VIEW has errors
第三个项目——PacMan(2)
深度学习与图像识别:原理与实践 笔记Day_10
NPM - environment