I have a speed test where I create and delete a single znode many times,
sequentially. If I connect to an embedded ZooKeeper server on the same
machine, each create/delete cycle takes over 100 ms. However, if I connect
to a non-embedded ZooKeeper server on the same machine, each
create/delete cycle takes only 6 ms.
This is the code that I use to start the embedded server:
package main;
import java.io.IOException;
import org.apache.zookeeper.server.ServerConfig;
import org.apache.zookeeper.server.ZooKeeperServerMain;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
public class ZooServer extends ZooKeeperServerMain implements Runnable {
private static ZooServer zooServer;
private static ServerConfig config;
public static void start(String configPath) {
config = new ServerConfig();
try {
config.parse(configPath);
} catch (ConfigException e) {
e.printStackTrace();
}
zooServer = new ZooServer();
(new Thread(zooServer)).start();
}
public static void stop() {
zooServer.shutdown();
}
@Override
public void run() {
try {
zooServer.runFromConfig(config);
} catch (IOException e) {
e.printStackTrace();
}
}
}
The config file looks like this:
tickTime=2000
dataDir=ZooKeeper files
clientPort=2181
If you would like, I can share the testing classes.
Anyone know why the embedded server is running so slowly?