Bug 60749 - OOM when using jdbcsampler caused by perConnCache
Summary: OOM when using jdbcsampler caused by perConnCache
Status: RESOLVED DUPLICATE of bug 60085
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 3.0
Hardware: All All
: P2 critical (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
Depends on:
Reported: 2017-02-20 09:19 UTC by Ejay
Modified: 2017-02-25 14:13 UTC (History)
2 users (show)

the method "getPreparedStatement" in class AbstractJDBCTestElement. (20.32 KB, image/png)
2017-02-20 09:19 UTC, Ejay

Note You need to log in before you can comment on or make changes to this bug.
Description Ejay 2017-02-20 09:19:25 UTC
Created attachment 34766 [details]
the method "getPreparedStatement" in class AbstractJDBCTestElement.

Encounter OOM when using jdbcsampler concurrently.
  Looking into the dump with hat, I find object "perConnCache" held a lot of retained heap. (Sorry for not saving the dump file)
    Following is the definition of perConnCache in class AbstractJDBCTestElement
     *  Cache of PreparedStatements stored in a per-connection basis. Each entry of this
     *  cache is another Map mapping the statement string to the actual PreparedStatement.
     *  At one time a Connection is only held by one thread
    private static final Map<Connection, Map<String, PreparedStatement>> perConnCache =
            new ConcurrentHashMap<Connection, Map<String, PreparedStatement>>();
    The param "connection" is from the method "getConnection()" which in DBCP2.
    Jmeter3 using DBCP2 as connections pool instead of excalibur(which Jmeter2 use). Then I dig into the code in class PoolingDataSource which in DBCP2..
    public Connection getConnection() throws SQLException {
        try {
            C conn = _pool.borrowObject();
            if (conn == null) {
                return null;
            return new PoolGuardConnectionWrapper<>(conn);
        } catch(SQLException e) {
    As the above,the method "getConnection"  will return new PoolGuardConnectionWrapper<>(conn) which could generate different hashcode for the  conn returned.  So the key "connection" will not exist in the perConnCache. then it will put the "new conn" into the perConnCache,which cause memory leak. Looking the method "getPreparedStatement" in class AbstractJDBCTestElement.(attached bug2).
Comment 1 Vladimir Sitnikov 2017-02-20 09:27:25 UTC
The cache has been removed in JMeter 3.1: https://bz.apache.org/bugzilla/show_bug.cgi?id=60085
Comment 2 Philippe Mouawad 2017-02-25 14:13:26 UTC

*** This bug has been marked as a duplicate of bug 60085 ***