We are currently evaluating an apache curator for a distributed use case of locking. Below is our test case:
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"); } } } } } }
The test is performed on dual-core / 7.5 GB RAM with 2G Xmx. So far, the zookeeper instance ( zook.company.com ) is running on a server with 4 cores / 15 GB with Xmx as 12G, maxClientCnxns = 5000, tickTime = 2000, initLimit = 10 and syncLimit = 5.
Both servers are in the same VPC VPC.
When we run the tests for 10 minutes, we get a lock capture time of 80 ms for more than 95% of the lock attempts. While the maximum lock capture time was 340 ms . We tried different combinations of the number of threads and the number of locks, but time is always on the side above.
Unable to find if something is wrong? Because times seem too high. Any hints
source share