根据百度结果,推测问题可能是,当使用ip创建ZooKeeper对象时,如果host中没有ip到主机名的映射,ZooKeeper创建过程中会调用ZooInetAddress.getHostName()这个方法从网络中获取主机名,这里耗费时间太长所致。通过调试定位到SaslServerPrincipal类的static String getServerPrincipal(WrapperInetSocketAddress addr, ZKClientConfig clientConfig) {
String configuredServerPrincipal = clientConfig.getProperty(ZKClientConfig.ZOOKEEPER_SERVER_PRINCIPAL);
if (configuredServerPrincipal != null) {
// If server principal is already configured then return it
return configuredServerPrincipal;
}
String principalUserName = clientConfig.getProperty(
ZKClientConfig.ZK_SASL_CLIENT_USERNAME,
ZKClientConfig.ZK_SASL_CLIENT_USERNAME_DEFAULT);
String hostName = addr.getHostName();
......
if (canonicalize) {
WrapperInetAddress ia = addr.getAddress();
......
String canonica