如何优化 JDBC DB2 自动客户端重新路由 (ACR) 它花费的时间太长

How to optimize JDBC DB2 Automatic client reroute (ACR) it Takes too long

提问人:Thomas 提问时间:5/26/2023 更新时间:5/26/2023 访问量:156

问:

我们在 HADR 集群中有一个 DB2 环境。 Java 应用程序通过 JDBC 连接到数据库。如果发生错误,这应该连接到备份数据库。

此连接大约需要 50 秒

我怎样才能加快速度?

这是我的代码:

public class JDBCDB2Trial {

    private static String connectionURL = "jdbc:db2://X.XXX.db2.1:50000/db2";
    private static String fieldUserName = "Administrator";
    private static String fieldPassword = "XXXXX";
    private static String enableClientAffinitiesList ="1";
    private static String clientRerouteAlternateServerName ="X.XXX.db2.1,X.XXX.db2.2";
    private static String clientRerouteAlternatePortNumber ="50000,50000";
    private static String maxRetriesForClientReroute ="1";
    private static String retryIntervalForClientReroute ="0";
    private static String enableSeamlessFailover ="1";

    public static void main(String args[]) {

    try {
        Driver driver = (Driver) Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
        DriverManager.registerDriver(driver);
        Properties info = new Properties();
        info.put("user", fieldUserName);
        info.put("password", fieldPassword);
        info.put("enableClientAffinitiesList", enableClientAffinitiesList);
        info.put("clientRerouteAlternateServerName", clientRerouteAlternateServerName);
        info.put("clientRerouteAlternatePortNumber", clientRerouteAlternatePortNumber);
        info.put("maxRetriesForClientReroute", maxRetriesForClientReroute);
        info.put("retryIntervalForClientReroute", retryIntervalForClientReroute);
        info.put("enableSeamlessFailover", enableSeamlessFailover);
            
            
        System.out.println("Start connection Test ACR");
        final long timeStart = System.currentTimeMillis();  
        Connection theCon = DriverManager.getConnection(connectionURL, info);
        
                final long timeStop = System.currentTimeMillis(); 
        if(theCon != null){
           long time = (timeStop - timeStart)/1000;
           System.out.println("Connection successful! Needed time: " +time+"Seconds");
        }

Java JDBC DB2 ACR

评论

0赞 data_henrik 5/26/2023
你没有说任何关于一般设置的事情。故障转移时需要启动什么?如何检测错误?
0赞 Thomas 5/26/2023
问题是启动第一个数据库时不可用。切换到备用数据库大约需要 50 秒。2 个 DB2 11.5 auf 窗口、当前 DB2 驱动程序、Java 8
0赞 Mark Barinstein 6/4/2023
@Thomas尝试设置连接属性(以秒为单位)。您不必再次在属性中指定相同的服务器属性。也就是说,使用 和 代替。重试超时和计数不应该那么小。 (至少可见的行为)应该大致等于“连接等待时间”,如果你已经死了。loginTimeout=5X.XXX.db2.1clientRerouteAlternate*clientRerouteAlternateServerName ="X.XXX.db2.2"clientRerouteAlternatePortNumber ="50000"loginTimeout x 2X.XXX.db2.1

答: 暂无答案