Bug #115586 When upgrading to mysql connetor/j-8.4.0, creating a connection becomes too slow
Submitted: 15 Jul 2024 3:36 Modified: 6 Dec 2024 16:18
Reporter: chen yi (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:8.4.0 OS:Windows (windows 11)
Assigned to: CPU Architecture:x86 (13th Gen Intel(R) Core(TM) i7-13700H 2.40 GHz)
Tags: slow

[15 Jul 2024 3:36] chen yi
Description:
When upgrading to mysql connetor/j-8.4.0, creating a connection becomes too slow

use 8.3.0 create a connection about 10-100ms
use 8.4.0 create a connection more than 10s

mysql server version : mysql  Ver 8.0.35 for Linux on x86_64 (MySQL Community Server - GPL)

How to repeat:
		Driver driver = DriverManager.getDriver("jdbc:mysql:replication://192.168.1.233,192.168.1.233/PRICING?useUnicode=true&characterEncoding=utf8");
		Properties properties = new Properties();
		properties.put("user", "nextop");
		properties.put("password", "nextop");
		properties.put("tcpRcvBuf", "524288");
		properties.put("tcpSndBuf", "524288");
		properties.put("cachePrepStmts", "true");
		properties.put("prepStmtCacheSize", "128");
		properties.put("allowMultiQueries", "true");
		properties.put("maintainTimeStats", "false");
		properties.put("elideSetAutoCommits", "true");
		properties.put("useLocalSessionState", "true");
		properties.put("prepStmtCacheSqlLimit", "4096");
		properties.put("nullCatalogMeansCurrent", "true");
		properties.put("rewriteBatchedStatements", "true");
		properties.put("useOldAliasMetadataBehavior", "true");
		long st = System.currentTimeMillis();
		Connection connection = driver.connect("jdbc:mysql:replication://192.168.1.233,192.168.1.233/PRICING?useUnicode=true&characterEncoding=utf8", properties);
		connection.close();
		System.out.println(System.currentTimeMillis() - st);
[17 Jul 2024 3:19] chen yi
The root cause is in ConnectionImpl L#458

this.connectionSpan.setAttribute(TelemetryAttribute.NETWORK_PEER_ADDRESS, inetSocketAddress.getHostName());

inetSocketAddress.getHostName() resolve host name too slow.
[17 Jul 2024 4:21] chen yi
When we configured DNS reverse lookup, the time taken to create connections dropped to milliseconds. However, most of our internal mysql servers currently do not have reverse lookup configured.
[17 Jul 2024 9:08] MySQL Verification Team
Hello chen yi,

Thank you for the report and feedback.

regards,
Umesh
[1 Aug 2024 8:18] MySQL Verification Team
Bug #115736 marked as duplicate of this one
[6 Dec 2024 16:18] Daniel So
Posted by developer:
 
Added the following entry to the Connector/J 9.2.0 changelog: 

"It might take a long time to create a connection to a server with Connector/J 8.4.0 or later. It was because Connector/J 8.4.0 and later always performed a reverse DNS lookup on the host IP address. With this patch, the lookup is only performed when OpenTelemetry is used, in which case the lookup is required."