Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance regression on closing statement with Hikari #100

Closed
NathanEckert opened this issue Oct 20, 2023 · 2 comments
Closed

Performance regression on closing statement with Hikari #100

NathanEckert opened this issue Oct 20, 2023 · 2 comments

Comments

@NathanEckert
Copy link

Driver version

Upgrade from driver 2.1.0.19 to 2.1.0.20

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.57864

Client Operating System

Linux Ubuntu 22.04.3 LTS (Jammy Jellyfish)

JAVA/JVM version

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /home/nec/.sdkman/candidates/maven/current
Java version: 11.0.20, vendor: Eclipse Adoptium, runtime: /home/nec/.sdkman/candidates/java/11.0.20-tem
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.2.0-35-generic", arch: "amd64", family: "unix"

Additional dependency:

<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
</dependency>

Problem description

When upgrading driver version, a performance regression is observed when using the driver in conjunction with Hikari.

Before the upgrade, it took 13 ms to close the statement, versus more than 2 seconds after the upgrade.

This issue is only observed with Hikari.

Reproduction code

package com.activeviam.database.redshift;

import com.activeviam.directquery.test.internal.redshift.RedshiftTestConstants;
import com.amazon.redshift.RedshiftProperty;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import lombok.Cleanup;
import org.junit.jupiter.api.Test;

public class TestPerformanceJDBCDriver {

	private static final String CONNECTION_STRING = RedshiftTestConstants.REDSHIFT_CLUSTER_URL;
	private static final String QUERY = "SELECT 1;";


	@Test
	void testPreparedStatement() throws SQLException {

		Connection connection = null;
		PreparedStatement statement = null;

		@Cleanup
		final HikariDataSource dataSource = createHikariDatasource(CONNECTION_STRING + RedshiftTestConstants.TEST_DATABASE_NAME);

		try {
			connection = dataSource.getConnection();
			statement = connection.prepareStatement(QUERY);
			statement.execute();
		} catch (SQLException e) {
			throw new RuntimeException(e);
		} finally {

			if (statement != null) {
				final long startClosingStatement = System.nanoTime();
				statement.close();
				System.out.println("Closing statement took: " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startClosingStatement) + " ms.");
			}
			if (connection != null) {
				connection.close();
			}

		}


	}

	private static HikariDataSource createHikariDatasource(final String connectionString) {
		final Properties jdbcProperties = new Properties();
		RedshiftProperty.USER.set(jdbcProperties, RedshiftTestConstants.getUsername());
		RedshiftProperty.PASSWORD.set(jdbcProperties, RedshiftTestConstants.getRedshiftPassword());

		final HikariConfig config = new HikariConfig();
		config.setDataSourceProperties(jdbcProperties);
		config.setJdbcUrl(connectionString);
		return new HikariDataSource(config);
	}
}

The previous outputs Closing statement took: 2021 ms. with driver version 2.1.0.20, and Closing statement took: 14 ms. with driver version 2.1.0.19

@bhvkshah
Copy link
Contributor

@NathanEckert we are aware of this issue and have a fix in place. It should available as part of the next release, version 2.1.0.22, slated for mid-November

@bhvkshah
Copy link
Contributor

bhvkshah commented Nov 9, 2023

Hi @NathanEckert , driver version 2.1.0.22 has been released which contains the fix for this issue. Thank you again for your contribution to the Redshift JDBC Driver!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants