简体   繁体   中英

JDBC MySQL conect to fail over node very slow

My environment have 2 MySQL server (INS1 and INS2) and when I tested failover mode with down INS1 and driver creat connection to INS2 it has very very slow to connected (It has occur on Glassfish connection pool too.)

final String connstr = "jdbc:mysql://INS1,INS2:3306/mysql";
Properties props = new Properties();
props.put("user", "xxx");
props.put("password", "xxx");
props.put("failOverReadOnly", "false");
props.put("roundRobinLoadBalance", "false");

return DriverManager.getConnection(connstr, props);

How to tune jdbc properties?

run: When INS1 run. INFO: Connected in 350 ms

INFO: Connected in 16 ms

INFO: Connected in 15 ms

INFO: Connected in 17 ms

INFO: Connected in 15 ms

INFO: Connected in 16 ms BUILD SUCCESSFUL (total time: 0 seconds)

run: When INS1 down. INFO: Connected in 1,380 ms

INFO: Connected in 1,060 ms

INFO: Connected in 1,058 ms

INFO: Connected in 1,060 ms

INFO: Connected in 1,055 ms

INFO: Connected in 1,041 ms BUILD SUCCESSFUL (total time: 6 seconds)

//Timeout for socket connect (in milliseconds), with 0 being no timeout. Only works on JDK-1.4 or newer. Defaults to '0'. props.put("connectTimeout", "100");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM