Apache zookeeper ApacheCurator分布式锁定-性能

Apache zookeeper ApacheCurator分布式锁定-性能,apache-zookeeper,apache-curator,distributed-lock,Apache Zookeeper,Apache Curator,Distributed Lock,我们目前正在评估apache curator的分布式锁定用例。下面是我们的测试用例: public class Test { private static CuratorFramework client = CuratorFrameworkFactory.newClient("zook.company.com", new ExponentialBackoffRetry(10,5)); public static void main(String[] args) {

我们目前正在评估apache curator的分布式锁定用例。下面是我们的测试用例:

public class Test { 
    private static CuratorFramework client = CuratorFrameworkFactory.newClient("zook.company.com", new ExponentialBackoffRetry(10,5));

    public static void main(String[] args) {
        client.start();
        int numLocks = 50000;
        int numThreads = 200;
        String[] keyPool = new String[numLocks];
        for (int i = 1; i <= numLocks; i++) {
            keyPool[i - 1] = String.valueOf(100 + i);
        }
        for (int i = 0; i < numThreads; i++) {
            Thread t = new Thread(new Job(numLocks, keyPool));
            t.setName("T" + (i + 1));
            t.start();
        }
    }

    private static class Job implements Runnable {
        private int      numLocks;
        private String[] keyPool;

        public Job(int numLocks, String[] keyPool) {
            this.numLocks = numLocks;
            this.keyPool = keyPool;
        }

        @Override
        public void run() {
            while (true) {
                int l = 0;
                int h = numLocks;
                String lockKey = keyPool[(new Random().nextInt(h - l) + l)];
                InterProcessMutex lock = new InterProcessMutex(client, "/"+lockKey);
                boolean acquired = false;
                String threadName = Thread.currentThread().getName();
                try {
                    long start = System.currentTimeMillis();
                    acquired = lock.acquire(0, TimeUnit.NANOSECONDS);
                    if (acquired) {
                        long end = System.currentTimeMillis();
                        System.out.println("lock acquired in "+ (end - start) + " ms");
                    } else {
                        System.out.println("failed to get lock");
                    }
                } catch (Exception e) {
                    System.out.println(e);
                } finally {
                    if (acquired) {
                        long start = System.currentTimeMillis();
                        lock.release();
                        long end = System.currentTimeMillis();
                        System.out.println("lock released in "+(end - start)+" ms");
                    }
                }
            }
        }
    }
}
公共类测试{
private static CuratorFramework client=CuratorFrameworkFactory.newClient(“zook.company.com”,new ExponentialBackoffRetry(10,5));
公共静态void main(字符串[]args){
client.start();
int numLocks=50000;
int numThreads=200;
String[]keyPool=新字符串[numLocks];

对于(int i=1;我修改了测试,使其使用内存中的测试服务器。如果我在MacBook Pro上运行测试,没有任何特殊情况,平均锁定时间为10-20ms。测试是否与服务器在同一VPC中?可能是服务器配置?仅供参考-我只是在同一MBP上运行外部ZK实例,并获得了合理的值还有。是的,测试和zookeeper服务器在同一个VPC中。除了问题中提到的配置之外,我没有更改任何配置。此外,我尝试在zookeeper服务器上运行测试(并提供localhost而不是zook.company.com),但这同样没有带来任何显著的性能改进(75毫秒).你能在本地机器上复制我的号码吗?还有,你使用的是什么版本的ZK和Curator?好吧,使用Zookeeper-3.3.6的时间降到了30毫秒。其他一切都保持不变!!