myBatis uses only a few connection from its BasicDataSource pool

515 views
Skip to first unread message

eran avidan

unread,
Feb 19, 2015, 3:39:58 AM2/19/15
to mybati...@googlegroups.com

I have been using myBatis with org.apache.commons.dbcp.BasicDataSource as the data source. 

for some reason, even under an impossible load, myBatis uses only a few connections from the pool (around 23). 

As you can see below my initial size of connections is 50, but some of them just stay idle.

Any ideas what could be causing this?

<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="#{'jdbc:mysql://' + mysql + ':3306/mydb?autoReconnect=true'}"/>
    <property name="username" value="user"/>
    <property name="password" value="pass"/>
    <property name="validationQuery" value="SELECT 1"/>
    <property name="testOnBorrow" value="true"/>
    <property name="maxWait" value="5000"/>
    <property name="initialSize" value="50"/>
    <property name="maxIdle" value="50"/>
    <property name="maxActive" value="1000"/>
</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="myDataSource"/>
    <property name="configLocation" value="classpath:mybatisConfiguration.xml"/>
</bean>

Travis Wellman

unread,
Feb 19, 2015, 6:22:12 PM2/19/15
to mybati...@googlegroups.com
Maybe you have something else limiting your concurrent connection usage. Even if there is, it's possible that using more connections may not make your app faster, considering network contention and disk contention. Is this a performance bottleneck?

eran avidan

unread,
Feb 24, 2015, 3:37:46 AM2/24/15
to mybati...@googlegroups.com

I am looking at mySql "show processlist" and see that many connections are not utilized. when I replace the insert line of myBatis (interface.someInsert) with a regular get connections (from the pool), I see that all the connections are utilized, so I assume the issue is with how myBatis uses the pool.

Yes, this is my performance bottleneck. Also, really hurts my scalability.
Is there a way I can manage the connection pool and just use myBatis query mapping/creation abilities?

François Schiettecatte

unread,
Feb 24, 2015, 7:18:19 AM2/24/15
to mybati...@googlegroups.com
You could try this connection pool and see if it does better:

http://www.mchange.com/projects/c3p0/

My understanding was that the myBatis pool in only really for testing.

Also I am not sure what you mean by 'not utilized’, are they showing up as ‘Sleep’?

And what is your pool configuration? By that I means these parameters:

<!--
<property name="poolMaximumActiveConnections" value="10" />
<property name="poolMaximumIdleConnections" value="5" />
<property name="poolMaximumCheckoutTime" value="20000" />
<property name="poolTimeToWait" value="20000" />
<property name="poolPingQuery" value="/* ping */ SELECT 1"" />
<property name="poolPingEnabled" value="true" />
<property name="poolPingConnectionsNotUsedFor" value="50000" />
-->


François
> --
> You received this message because you are subscribed to the Google Groups "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages