'why connect zookeeper take a long time on windows?
I'm run a simple demo that using the java zookeeper client to connect zookeeper server. It take a long time(at least 10 seconds) to connect successful on windows, but it connect successful on linux very quickly. what is the reason and how to deal with it。 Thank you so much.
solft version:
OS: win11 with two virtual machine, one is ubuntu server, the other is ubuntu desktop,
java: openjdk 11,
zookeeper server: version3.7.0, deploy on ubuntu virtual machine
demo code:
public static void main(String[] args) throws Exception {
log.info("begin connect to zookeeper ================================>>");
ZooKeeper zooKeeper = new ZooKeeper("192.168.1.16", 30000, watchedEvent -> {
});
log.info("connect zookeeper success =================================>>");
zooKeeper.close();
log.info("zookeeper is closed...");
}
result and logs:
- demo code run on Win11:
[04-04-22 11:57:32:013 CST] main INFO provider.ProviderStartup: begin connect to zookeeper ================================>>
[04-04-22 11:57:41:087 CST] main INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC
[04-04-22 11:57:41:087 CST] main INFO zookeeper.ZooKeeper: Client environment:java.version=11
[04-04-22 11:57:41:088 CST] main INFO zookeeper.ZooKeeper: Client environment:java.home=D:\jdk-11
[04-04-22 11:57:41:088 CST] main INFO zookeeper.ZooKeeper: Client environment:os.name=Windows 10
[04-04-22 11:57:41:088 CST] main INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
[04-04-22 11:57:41:088 CST] main INFO zookeeper.ZooKeeper: Client environment:os.version=10.0
[04-04-22 11:57:41:096 CST] main INFO zookeeper.ZooKeeper: Initiating client connection, connectString=192.168.1.16 sessionTimeout=30000 watcher=com.gonnaup.dubbo.provider.ProviderStartup$$Lambda$29/0x00000008000dc840@799d4f69
[04-04-22 11:57:41:102 CST] main INFO common.X509Util: Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
[04-04-22 11:57:41:384 CST] main INFO zookeeper.ClientCnxnSocket: jute.maxbuffer value is 1048575 Bytes
[04-04-22 11:57:41:393 CST] main INFO zookeeper.ClientCnxn: zookeeper.request.timeout value is 0. feature enabled=false
[04-04-22 11:57:41:393 CST] main INFO provider.ProviderStartup: connect zookeeper success =================================>>
[04-04-22 11:57:59:472 CST] main-SendThread(192.168.1.16:2181) INFO zookeeper.ClientCnxn: Opening socket connection to server 192.168.1.16/192.168.1.16:2181.
[04-04-22 11:57:59:473 CST] main-SendThread(192.168.1.16:2181) INFO zookeeper.ClientCnxn: SASL config status: Will not attempt to authenticate using SASL (unknown error)
[04-04-22 11:57:59:476 CST] main-SendThread(192.168.1.16:2181) INFO zookeeper.ClientCnxn: Socket connection established, initiating session, client: /192.168.1.8:2474, server: 192.168.1.16/192.168.1.16:2181
[04-04-22 11:57:59:596 CST] main INFO provider.ProviderStartup: zookeeper is closed...
[04-04-22 11:57:59:596 CST] main-EventThread INFO zookeeper.ClientCnxn: EventThread shut down for session: 0x100001dd5b40058
I omitted some useless logs to reduce the number of words.It can be seen from the logging time that It takes a long time from the connection to the end(see the '======>>' flag).
- demo code run on ubuntu desktop virtual machine:
[04-04-22 11:57:03:739 CST] main INFO simple.ZookeeperCli: begin connect to zookeeper ================================>>
[04-04-22 11:57:03:785 CST] main INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC
[04-04-22 11:57:03:786 CST] main INFO zookeeper.ZooKeeper: Client environment:java.version=11.0.14.1
[04-04-22 11:57:03:788 CST] main INFO zookeeper.ZooKeeper: Client environment:os.name=Linux
[04-04-22 11:57:03:788 CST] main INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
[04-04-22 11:57:03:788 CST] main INFO zookeeper.ZooKeeper: Client environment:os.version=5.13.0-39-generic
[04-04-22 11:57:03:800 CST] main INFO zookeeper.ZooKeeper: Initiating client connection, connectString=192.168.1.16 sessionTimeout=30000 watcher=cn.gonnaup.simple.ZookeeperCli$$Lambda$31/0x0000000840083040@47f37ef1
[04-04-22 11:57:03:808 CST] main INFO common.X509Util: Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
[04-04-22 11:57:03:818 CST] main INFO zookeeper.ClientCnxnSocket: jute.maxbuffer value is 1048575 Bytes
[04-04-22 11:57:03:838 CST] main INFO zookeeper.ClientCnxn: zookeeper.request.timeout value is 0. feature enabled=false
[04-04-22 11:57:03:849 CST] main INFO simple.ZookeeperCli: connect zookeeper success =================================>>
[04-04-22 11:57:03:941 CST] main-SendThread(192.168.1.16:2181) INFO zookeeper.ClientCnxn: Opening socket connection to server 192.168.1.16/192.168.1.16:2181.
[04-04-22 11:57:03:943 CST] main-SendThread(192.168.1.16:2181) INFO zookeeper.ClientCnxn: SASL config status: Will not attempt to authenticate using SASL (unknown error)
[04-04-22 11:57:03:964 CST] main-SendThread(192.168.1.16:2181) INFO zookeeper.ClientCnxn: Socket connection established, initiating session, client: /10.0.2.15:56596, server: 192.168.1.16/192.168.1.16:2181
[04-04-22 11:57:04:109 CST] main INFO zookeeper.ZooKeeper: Session: 0x100001dd5b40057 closed
[04-04-22 11:57:04:109 CST] main INFO simple.ZookeeperCli: zookeeper is closed...
[04-04-22 11:57:04:109 CST] main-EventThread INFO zookeeper.ClientCnxn: EventThread shut down for session: 0x100001dd5b40057
That can see connecting zookeeper and closing the connection is completion immediately.
Solution 1:[1]
I can't say this is your problem exactly, but do you have some type of antivirus software running on the Windows box that is scanning jar files on access? I've run into that problem on a server in the past, where an antivirus update caused all Zookeeper connections to go from less than a second to connect to approximately 60 seconds while the on-access scanner was checking all jar files that were being touched/loaded, including both Zookeeper and JVM libraries. If you have antivirus, you can try temporarily disabling it while running your connection tests to at least rule that possibility out.
Solution 2:[2]
I finally discovered the problem through debug the source code of the Zookeeper.
Before JVM instantiate the Zookeeper object, it execute the static block in Zookeeper.class which load your enviroment. There has a method InetAddress.getLocalHost().getCanonicalHostName()
which make the code running
slowly.I found a solution in getcanonicalhostname-is-very-slow. This is the Npcap Loopback Adapter
cause the slowly execution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | FreemanB |
Solution 2 | gonnaup |