Cas performance


#1

Hi there I am wondering why cas takes such a while compared to add - for my application I have to add/update roughly 1000 keys per servlet request, and I am finding that where the keys do not exist the adds are taking 0 to 1 ms each but the cas operations are taking 7 to 8 ms resulting in a total runtime of 7 to 8 seconds which is too long.

Here is my code, please let me know if could be doing something more efficiently. I am getting the cas using asyncGets and depending on the result I am doing an add or a set in the OperationCompletionListener :

StopWatch swloop = new StopWatch(); swloop.start(); final CountDownLatch latch = new CountDownLatch(keys.length); for (String key: keys) { OperationFuture<CASValue> f = client.asyncGets(key); f.addListener(new OperationCompletionListener() { @Override public void onComplete(OperationFuture<?> operationFuture) throws Exception { StopWatch sw = new StopWatch(); sw.start(); @SuppressWarnings("unchecked") CASValue casValue = (CASValue) operationFuture.get(); sw.stop(); System.out.println("Time for operationFuture.get()" + sw.getTime()); sw.reset(); Object presentVal = (casValue == null) ? null : casValue.getValue(); Document fd = updateObject(presentVal, articleid, unixExpiry); if (casValue == null) { sw.start(); OperationFuture f = client.add(key, (int) fd.getMaxExpiry(), gson.toJson(fd)); sw.stop(); System.out.println("Time for add: " + sw.getTime()); } else { sw.start(); CASResponse csr = client.cas(key, casValue.getCas(),(int) fd.getMaxExpiry(),gson.toJson(fd)); sw.stop(); System.out.println("Time for cas: " + sw.getTime()); } latch.countDown(); } }); } latch.await(); swloop.stop(); System.out.println("Time for all inserts: " + swloop.getTime()); Thanks