Database open/closed connections incorrect

Questions about YourKit Java Profiler
Post Reply
wilkejj
Posts: 4
Joined: Wed May 21, 2014 9:12 pm

Database open/closed connections incorrect

Post by wilkejj »

We recently profiled a job and Yourkit said it was opening/closing ~700 connections per second under the "Performance Charts" section - so we thought we had a problem with our connection pool.

We could not trace down where this would be happening, we came to later find out that YourKit was not telling us exactly what we thought it was - and we were able to demonstrate this with a simple test.

We wrote a very simple java app that opened a connection slept for a period of time - then closed the connection. While the java app was up and running - there should have been 1 connection open - the profiler said there were 0 connections open. This appears to be a bug in Yourkit - has anyone else seen this?

This was the simple example we used

Code: Select all

package _connectionTest;

//STEP 1. Import required packages
import java.sql.*;
import java.util.Properties;

import oracle.jdbc.pool.OracleDataSource;

public class connectionTest {
    // JDBC driver name and database URL
    static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";
    static final String DB_URL = "jdbc:oracle:thin:@192.168.56.103:1521:sid";

    // Database credentials
    static final String USER = "username";
    static final String PASS = "password";

    public static void main(String[] args) throws Exception {
        OracleDataSource dataSource = new OracleDataSource();
        Properties props = new Properties();
        dataSource.setURL(DB_URL);
        dataSource.setUser(USER);
        dataSource.setPassword(PASS);
        dataSource.setConnectionCachingEnabled(true);

        Connection conn = null;
        Statement stmt = null;
        try {
            // STEP 2: Register JDBC driver
//            Class.forName("oracle.jdbc.driver.OracleDriver");

            // STEP 3: Open a connection
            System.out.println("Connecting to database...");
//            conn = DriverManager.getConnection(DB_URL, USER, PASS);
            conn = dataSource.getConnection();

            // STEP 4: Execute a query
            System.out.println("Creating database...");
            stmt = conn.createStatement();

            String sql = "CREATE TABLE JW as select 2 from dual";
            stmt.executeUpdate(sql);

            Thread.sleep(500 * 1000);
            System.out.println("Database created successfully...");
        } catch (SQLException se) {
            // Handle errors for JDBC
            se.printStackTrace();
        } catch (Exception e) {
            // Handle errors for Class.forName
            e.printStackTrace();
        } finally {
            // finally block used to close resources
            try {
                if (stmt != null)
                    stmt.close();
            } catch (SQLException se2) {
            }// nothing we can do
            try {
                if (conn != null)
                    conn.close();
            } catch (SQLException se) {
                se.printStackTrace();
            }// end finally try
        }// end try
        System.out.println("Goodbye!");
    }// end main
}// end JDBCExample

Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Database open/closed connections incorrect

Post by Anton Katilin »

Hi,

We're trying to reproduce the problem with the example you've provided.

Meanwhile, could you please try whether the problems are reproducible with the EAP version:
http://www.yourkit.com/eap

Best regards,
Anton
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Database open/closed connections incorrect

Post by Anton Katilin »

An update:

it seems that the EAP version should fix the issue. Could you please check it with your application.
wilkejj
Posts: 4
Joined: Wed May 21, 2014 9:12 pm

Re: Database open/closed connections incorrect

Post by wilkejj »

We are seeing the same behavior on EAP build14048 with out example.

It says "1 open/1 closed" for the duration of the "job" - which is the same code attached in my first post.

I have a screen shot but don't see anywhere to attach it here.
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Database open/closed connections incorrect

Post by Anton Katilin »

Could you please send the screenshot to [email protected]

Initially you wrote:
While the java app was up and running - there should have been 1 connection open - the profiler said there were 0 connections open.
Now you write:
It says "1 open/1 closed" for the duration of the "job" - which is the same code attached in my first post.
So, what behavior do you see, and which you expect to see? From your initial post I can conclude that 1 open/1 closed is the desired result.
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Database open/closed connections incorrect

Post by Anton Katilin »

Maybe you mean that (a) it works properly for your short example but (b) does not work for the real application?
wilkejj
Posts: 4
Joined: Wed May 21, 2014 9:12 pm

Re: Database open/closed connections incorrect

Post by wilkejj »

Thank you for the quick responses - I really appreciate that. I emailed my screen shot.

It is not working as expected for either the app or the example.

I guess it should have read:
"It says "1 opened/1 closed" for the duration of the "job" - which is the same code attached in my first post."

Changing open to "opened" in past tense. There is an orange line metric for "remained open". When my system is under heavy load - I would expect that all the connections in the thread pool would be open (~90 for me) - but it says there are none.

In the example I would expect:
-Open connection
-Create simple table
-Sleep for about 8 minutes
-Have Orange line in Database Connections at 1 showing there is 1 open connection
-Close the connection
-Have the orange line go to 0
-Have the dark blue line "connection closed" go up to 1 per second
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Database open/closed connections incorrect

Post by Anton Katilin »

We've answered by email.
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Database open/closed connections incorrect

Post by Anton Katilin »

Build 14052 is supposed to solve the problem:
http://www.yourkit.com/eap
wilkejj
Posts: 4
Joined: Wed May 21, 2014 9:12 pm

Re: Database open/closed connections incorrect

Post by wilkejj »

Looks like we needed to add "=sampling" to the argument to get this to work

"-agentpath:/mnt/home/yjp-2013-build-13076/bin/linux-x86-64/libyjpagent.so=sampling"
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Database open/closed connections incorrect

Post by Anton Katilin »

Build 14060 with the fix is available for download:
http://www.yourkit.com/eap
Post Reply