Hi, I wrote a java program, where i create a ComboPooledDataSource. Then,
i just execute one sql over and over. while the program runs, i monitor
the mysql administrator user connection. The test is single threaded, and
just execute some query over and over. So at most, the program only need 1
open connection at any given time. I set the connection pool min size to
be 5, and max to be 30. If I run the query for many round, I see the open
connections ramp up. Ideally, I would hope there is only 5 connections
(only 1 is used to serve my query). However, the open connection quickly
ramp up to more than 5, sometimes, it runs to max connection very quickly.
I wrote the test, because one time i see more than max connections being
generated, and it hangs my mysql server. Therefore, i am very concerned on
this.
This is my test case, please take a look and let me know if it is valid:
@Test
public void testC3P0() throws Exception{
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass("com.mysql.jdbc.Driver");
ds.setUser("root");
ds.setPassword("root");
ds.setJdbcUrl("jdbc:mysql://localhost:3306/podcasts_catalog");
ds.setMinPoolSize(5);
ds.setMaxPoolSize(30);
ds.setAcquireIncrement(1);
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
for (int i = 0; i < 2000000; i++) {
try {
conn = ds.getConnection();
String sql = "select * from category order by pos";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
// while (rs.next()) {
// System.out.println("name: " + rs.getString("name"));
// }
} finally {
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (conn != null && !conn.isClosed())
conn.close();
}
//sleep(1); (if do not thread.sleep 1ms, then connection ramp up to
maximum size almost immediately. if sleep for 1ms, it will ramp up more
than min, but not reaching to max so quickly)
}
DataSources.destroy(ds);
}
The only reason that connections ramp up i can think of, is that
conn.close() does not really release the actual connection, so that when
new query executed, it accquires new connection from pool.
Nobody/Anonymous
None
None
Public
|
Date: 2009-07-28 08:47 Thanks for your comment, swaldman. |
|
Date: 2009-07-28 06:02 hi, |