0

我目前正在使用 ch.ethz.ssh2.Connection 连接到我在 java 中的服务器。有时它会挂在一台服务器上。(可能需要 10-15 秒)。我想知道是什么导致了这个挂起时间以及如何避免它。

连接示例

    conn = new ch.ethz.ssh2.Connection(serverName);
    conn.connect();

    boolean isAuthenticated = conn.authenticateWithPassword(user, pass);
    logger.info("Connecting to " + server);

    if (isAuthenticated == false) {
        logger.info(server + " Please check credentials");              
    } 

    sess = conn.openSession();

   // I am connecting to over 200 servers and closing them. What would be the best practice to loop thru all these servers in the minimal time.

//some servers quickly connects, while some takes some time.
why does this happen?
4

2 回答 2

1

主要问题是:是代码问题,网络问题还是服务器问题。

可以调试代码问题 - 不幸ch.ethz.ssh2.Connection的是,没有任何日志记录可能性来检测内部发生的事情。

可能您应该考虑切换 ssh 库(或将其用于有问题的服务器的一些测试)。根据我的经验,sshj非常有用。

如果是网络问题或服务器问题,您可以通过 Wireshark 检查发生的情况。如果发送了网络数据包但响应延迟,则问题不在于使用的客户端代码。

于 2017-06-15T15:46:50.503 回答
0

我的心理调试能力告诉我,服务器正在对每个连接的客户端的 IP 地址进行 DNS 查找。这些 DNS 查找要么需要很长时间才能完成,要么完全失败。DNS 查找将阻止身份验证过程,直到它完成,无论成功与否。

如果服务器是OpenSSH 服务器,则此行为由sshd config "UseDNS" 选项控制。

于 2017-06-15T17:05:44.353 回答