DriverManager.getConnection is too slow in linux
Posted by: 오종현 남
Date: October 15, 2015 02:31AM

Hello, I'm Jack and using MySQL for my study.

i'd like to ask a question i found today.

before get started,

my environment like this.


MySQL server
version : 5.2.8-MariaDB
os: Windows ??

Java Application Server
os : linux 2.6.32-504.e16.x86_64
connector version : 5.1.36
jdk ver : 1.7.72


so the problem is,

it takes more than 4seconds on this statement to get connection.

DriverManager.getConnection(url,id,pass);

but the strange thing is, if i run this at windows machine,

it takes only 200ms.

while this hanging, i capture thead dump and found out that socket read is holding.

i'd like to reduce this 'making connection time' and understand why this happens.


java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:100)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:143)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:173)
- locked <0x000000058203d870> (a com.mysql.jdbc.util.ReadAheadInputStream)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2923)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:560)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1014)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2249)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2280)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2079)
- locked <0x0000000581da3a68> (a com.mysql.jdbc.JDBC4Connection)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at jTest.MySQLDBConnector.initializeDataBase(MySQLDBConnector.java:48)
at jTest.JavaTest.main(JavaTest.java:15)





Thanks for your help in advance.
-Jack

Options: ReplyQuote


Subject
Written By
Posted
DriverManager.getConnection is too slow in linux
October 15, 2015 02:31AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.