import java.net.URI; import java.util.LinkedList; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import com.couchbase.client.CouchbaseClient; import net.spy.memcached.CASValue; import net.spy.memcached.internal.GetFuture; import net.spy.memcached.internal.OperationFuture; public class Couch1234 { public static final String KEY = "M"; public static final String VALUE = "10"; public static final int ttl = 0; public static final int size = 5; public static void main(String args[]) throws InterruptedException, ExecutionException { // Set the URIs and get a client List uris = new LinkedList(); uris.add(URI.create("http://localhost:8091/pools")); CouchbaseClient client = null; try { client = new CouchbaseClient(uris, "default", ""); } catch (Exception e) { System.err.println("Error connecting to Couchbase: " + e.getMessage()); System.exit(0); } for(int i=0;i <=1000000; i++ ) { OperationFuture setOp = client.set(KEY+i, ttl, KEY+i); // Workaround below that still gives decent performance. // The bug(?) seem to be that spymemcached get overloaded and does not properly tell/manage // that the queue is becoming full. /* Uncomment to have all keys inserted properly if (i % 1000 == 0) setOp.get(); */ if (i % 100000 == 0) System.out.println("Done with " + i); /* Object getObject = client.get(KEY+i);; if (getObject != null) { try { if (setOp.get().booleanValue()) { System.out.println("Set Succeeded"); } else { System.err.println("Set failed: " + setOp.getStatus().getMessage()); } } catch (Exception e) { System.err.println("Exception while doing set: " + e.getMessage()); } } */ } System.exit(0); } }