DeemOpen / zkui

A UI dashboard that allows CRUD operations on Zookeeper.
2.36k stars 977 forks source link

Did not wait for the zk session caused every operation become very slow #64

Open maxpaynebupt opened 5 years ago

maxpaynebupt commented 5 years ago

I can not commit or push code, so, just point out what the problem is and how to fix it.

The gui is very slow while we do any action on it, that's because every time it start up a new connection to zk server.

The problem exists in the com.deem.zkui.utils.ServletUtil.java's getZookeeper function.

It did not wait for the zk to establish connection to zk server. ''' zk = ZooKeeperUtil.INSTANCE.createZKConnection(zkServer, zkSessionTimeout); ZooKeeperUtil.INSTANCE.setDefaultAcl(globalProps.getProperty("defaultAcl")); if (zk.getState() != ZooKeeper.States.CONNECTED) { session.setAttribute("zk", null); } else { session.setAttribute("zk", zk); } '''

fix, add a sleep before check the connection status: ''' zk = ZooKeeperUtil.INSTANCE.createZKConnection(zkServer, zkSessionTimeout); ZooKeeperUtil.INSTANCE.setDefaultAcl(globalProps.getProperty("defaultAcl")); while (zk.getState() == ZooKeeper.States.CONNECTING){ Thread.sleep(100); } if (zk.getState() != ZooKeeper.States.CONNECTED) { session.setAttribute("zk", null); } else { session.setAttribute("zk", zk); } '''