GithubHelp home page GithubHelp logo

sylvainlaurent / jdbc-performance-logger Goto Github PK

View Code? Open in Web Editor NEW
84.0 6.0 26.0 736 KB

A JDBC driver wrapper and GUI to analyze statement performance

License: Apache License 2.0

Java 99.36% Shell 0.64%
jdbc-driver performance-analysis

jdbc-performance-logger's Introduction

Build Status

JDBC Performance Logger

Purpose

Measuring performance of SQL statements executed through JDBC.

(click on the image below for an overview of the features) Click here for an overview of the features

Why yet another project?

Although other tools already exist around JDBC performance monitoring (log4jdbc, P6Spy, JDbMonitor...), I did not find the features I was looking for : a GUI, measurement of statement execution and ResultSet iteration, cumulative measures, commit duration...

Features

  • Graphical console (Swing-based) with analysis feature
  • filter/highlight based on statement text, minimum execution time
  • advanced filtering using custom SQL WHERE clause against the embedded H2 DB
  • group statements to count executions of identical statements and measure cumulated time
  • support for multiple connections
  • the connection between the monitored java application (JDBC proxy driver) and the console can be initiated from either side
  • Logging of bound values of prepared statements, including the name of the set* method called to bind the value (very helpful to distinguish setDate and setTimestamp to understand why Oracle does not use an index )
  • Separate measure of statement execution time, results fetch time and result set usage time (includes result processing like creation of java object)
  • Measures connection creation and commit/rollback durations
  • Handling of batched statements
  • Logging of SQLExceptions
  • Displays the queryTimeout of each statement (no value means 0 or no timeout) (since 0.5.0)
  • Displays the autoCommit status of each statement (since 0.6.0)
  • Supports new java 8 methods like executeLargeUpdate (since 0.6.2)
  • Java agent (since 0.8.0)

Requirements

  • java 8 (since 0.9)

How to download

<dependency>
    <groupId>com.github.sylvainlaurent.jdbcperflogger</groupId>
    <artifactId>jdbc-perf-logger-agent</artifactId>
    <version>...</version>
</dependency>

or

<dependency>
    <groupId>com.github.sylvainlaurent.jdbcperflogger</groupId>
    <artifactId>jdbc-perf-logger-driver</artifactId>
    <version>...</version>
</dependency>

How to setup the JDBC Driver

The driver can be setup in different ways:

As a java agent (recommended/most simple way)

Just launch the JVM with -javaagent:path/to/jdbc-perf-logger-agent-x.y.z.jar

The agent jar file is available in the lib directory of the zip or tar.gz distribution or as a maven artifact as shown above.

Manual configuration

  • If using maven, add the <dependency> snippet above (replacing the version with the latest one) to your pom.xml
  • If NOT using maven, add jdbc-perf-logger-driver jar file to the classpath of the JDBC-client application (the file can be found in the lib directory of the binary distribution)
  • Change the driver class name to ch.sla.jdbcperflogger.driver.WrappingDriver
  • Prefix your current JDBC URL with jdbcperflogger:, example: jdbcperflogger:jdbc:h2:mem: or jdbcperflogger:jdbc:oracle:thin:@myhost:1521:orcl

Advanced configuration

  • (optional) add a jdbcperflogger.xml file to the classpath (see the example file for indications). If both the driver and console are used on the same machine, there's nothing to do: the driver will try to connect to the console on localhost:4561.
  • (optional) the location of the config file can be overriden with the System property jdbcperflogger.config.location. Example : java -Djdbcperflogger.config.location=/Users/me/myjdbcperflogger.xml ....

How to use the graphical console

  • launch bin/jdbc-performance-logger-gui.sh (unix/MacOS) or bin\jdbc-performance-logger-gui.bat (requires java 8 JRE)
  • by default the console waits for connections from jdbc-logger-drivers on port 4561. All statements will be logged to the same tab
  • The console can also connect to a jdbc-perf-logger-driver instance on a specific host and port. A tab is created for each host/port combination.
  • Once a tab is opened, the status of the connection is indicated at the bottom of the panel. If the connection is broken and was initiated by the console, the console will try to reconnect regularly. If the connection was initiated by the driver, the latter will try to reconnect regularly.
  • by default the console only keeps the last 20'000 statements. The number can be changed by adding the System property maxLoggedStatements when launching the console.

Tested databases

  • H2 (lightly, used for our own unit tests)
  • Oracle 10.2/11.2/12.1
  • MySQL 5.1

Current limitations

  • No DataSource nor XADataSource class provided
  • Only the first ResultSet of queries is logged (Statement.getMoreResults() works but no effort has been put to log the fetching of those ResultSets)

Potential ClassLoader issues

There should not be any problem when using the "java agent way".

For the "driver way", here are the rules to observe :

  • The jdbc-perf-logger-driver must be able to use your bare JDBC driver
  • The DataSource you use must be able to use the jdbc-perf-logger-driver classes

Here are the most common cases with Tomcat :

  • Tomcat shared.loader includes
    • the DataSource implementation (which is by default for tomcat 7 DataSource)
    • the bare JDBC driver
    • the jdbc-perf-logger driver This is the case if you place your JDBC driver and jdbc-perf-logger driver in the lib directory of CATALINA_BASE or CATALINA_HOME. This can also be done by configuring the catalina.properties file.
  • your WAR file embeds the jars for
    • the DataSource implementation
    • the bare JDBC driver
    • the jdbc-perf-logger driver
  • the JVM classpath includes the bare JDBC driver and the jdbc-perf-logger driver and the Tomcat shared.loader includes the DataSource implementation.

Source code

The source code is available on GitHub : https://github.com/sylvainlaurent/JDBC-Performance-Logger

How to build source

Use Maven and a JDK >=8, and run mvn clean verify in the root directory of the git repository. The binary distribution is then available in jdbc-perf-logger-gui.

How to create a release

mvn release:prepare release:perform and answer the questions about version number.

Then push the commits and tags to github.

License

This software is licensed under the Apache Sotware License version 2.0, see LICENSE.txt.

This software uses and redistributes third-party software, see 3rdparty_license.txt.

jdbc-performance-logger's People

Contributors

chenzhang22 avatar dependabot[bot] avatar madness-inc avatar samybadjoudj avatar sylvainlaurent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jdbc-performance-logger's Issues

Support for java 8

There are new methods like Statement.executeLargeUpdate() in java 8.
Though they will work with the current version of the WrappingDriver, they will not appear in the console until they are taken into account by the proxy handler

Allow to specify the classname of the underlying drivers

in situations where the underlying JDBC driver is not in the JVM classpath, the DriverManager cannot discover it through META-INF/services mechanism.
We should allow to specify the class name of the wrapped driver so that the WrappingDriver can get the JDBC connection.

Set custom limit statements

Currently the limit of statements is 20'000. In some case we want to increase this threshold.
Maybe it will be a good idea to create a menu where we can set king of parameters

Feature : Add a delta timestamp column

New feature : add a column that displays the delta of time of each statement compared to a specific statement. This allows to have a running sum of time spent in the DB...

Maybe 2 columns : one for the delta of absolute time, one for the running sum of time spent ?

Support Statement.getMoreResults()

Statement.execute() then Statement.getResultSet() should be considered equivalent to executeQuery() (to record the number of rows fetched).

Besides, getMoreResults() is currently ignored, we need to support multiple resultsets

Feature: CSV export

partially implemented
TODO :

  • fix line feeds
  • export batched statements too
  • keep time-related columns together

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.