Search code examples
javajdbcdatabase-performance

Will Open jdbc connections to a database server slow down the performance of an application?


I have an automation script to test database which creates connection to db server and verifies table values. Meanwhile the application has got very slow. Is there any relation between open connections and performance of application?


Solution

  • Not necessarily. In fact, it is not expected that open connections will slow down the application's performance, unless it is specifically justified.

    Performance may be affected by three factors:

    • CPU usage.
    • Memory occupation.
    • I/O traffic.

    Should a JDBC connection, just for being opened and not for being used, increase the CPU usage? In principle no, unless the driver is running in background some thread of its own.

    Should it occupy a lot of memory? In principle no, because JDBC APIs are designed to recover data thorugh cursors (It should not occupy more than a simple working buffer) - unless the driver is not doing a correct garbage collection of used udata.

    Should it do a lot of I/O traffic? In principle no, unless the driver is doing some polling or something in background.

    So, as you can see, the answer is that it depends on the JCBC driver implementation. Closing a connection as soon as it is not used is a good practice for releasing resources at the server side, but usually it is not critical at the client side.