connection pool
Edit-
- iBatis는 JDBC 3.0이전에도 내부적으로 statement cache를 함. 그러나 ibatis session level의 cache이기 때문에 Driver level cache보다 효율이 떨어짐
- evictor 스레드가 실행될 때는 timeBetweenEviction RunMillis > 0
- Evictor 스레드 역할http://devyongsik.tistory.com/509\[http://devyongsik.tistory.com/509]
모니터링
<%@ page language="java" contentType="text/html; charset=EUC-KR" %>
<%@ page import="
java.util.*,
javax.naming.*,
javax.sql.*,
org.apache.commons.beanutils.*,
org.apache.commons.dbcp.*"
%>
<%
Context initContext = new InitialContext();
DataSource ds = (DataSource)initContext.lookup("jdbc/Sims");
BasicDataSource bds = (BasicDataSource)ds;
try {
Map<Object,Object> desc = BeanUtils.describe(bds);
%>
<%=desc%>
<%
} catch(Exception e) {
out.println(e.toString());
}
%>
DBCP
Race condition error : https://issues.apache.org/jira/browse/DBCP-270
The pool is initialized the first time one of the following methods is
invoked:
getConnection, setLogwriter, setLoginTimeout, getLoginTimeout, getLogWriter.
testOnBorrow
removeAbandoned
- long connection의 경우 의도하지 않은 connection close 현상 발생 가능
<bean id="masterDs" class="org.apache.commons.dbcp.BasicDataSource" /> … <property name="removeAbandoned" value="true" /> <property name="removeAbandonedTimeout" value="30" /> … </bean> |
if(abandonedConfig != null && abandonedConfig.getRemoveAbandoned()) connectionPool = new AbandonedObjectPool(null, abandonedConfig); else connectionPool = new GenericObjectPool(); … dataSource = new PoolingDataSource(connectionPool); |
| conn = (Connection)_pool.borrowObject(); |
if(config != null && config.getRemoveAbandoned() && getNumIdle() < 2 && getNumActive() > getMaxActive() - 3) removeAbandoned(); … if(pc.getLastUsed() ⇐ timeout && pc.getLastUsed() > 0L) remove.add(pc); … if(config == null |
!config.getRemoveAbandoned()) break MISSING_BLOCK_LABEL_54; synchronized(trace) { boolean foundObject = trace.remove(obj); |
성능비교
- JDBC SQL 구문에 클라이언트 정보 남기기 : http://kwon37xi.egloos.com/4860051