I understand that the GA for N1QL is currently in the works. I just wanted to provide a case of the query engine currently works for us in the manner that we intend to eventually use it.
I have the couchbase server (2.2), the query engine (dp4) and the client code (using the 2.1.0 Java SDK) all operating on the same machine (windows 7)
The code I use for this test:
package main.java.dp4Test;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.query.Query;
import com.couchbase.client.java.query.QueryResult;
import com.couchbase.client.java.query.QueryRow;
import com.couchbase.client.java.env.;
import com.couchbase.client.java.query.Statement;
import static com.couchbase.client.java.query.Select.;
import static com.couchbase.client.java.query.dsl.Expression.*;
import java.io.IOException;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.FileHandler;
import java.util.logging.SimpleFormatter;
public class SomexpLoscouwMain {
public static void main(String[] args) {
Logger logger = Logger.getLogger("MyLog"); FileHandler fh; try {
// This block configure the logger with handler and formatter fh = new FileHandler("../../theLog.log"); logger.addHandler(fh); SimpleFormatter formatter = new SimpleFormatter(); fh.setFormatter(formatter);
// the following statement is used to log any messages logger.info("My first log");
} catch (SecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder() .queryEnabled(true).queryTimeout(999999999) .build(); Cluster cluster = CouchbaseCluster.create(env, "127.0.0.1"); Bucket bucket = cluster.openBucket("beer-sample", ""); int stop = 0; long iteration = 1; long totalTime = 0; long over400 = 0; while (stop==0) {
try {
//String query = "SELECT * FROM `beer-sample`"; String query = "SELECT * FROM beer-sample LIMIT 1"; //String query = "SELECT * FROM `beer-sample` LIMIT 1"; Statement statement = select("*").from("`beer-sample`").limit(1); Query cbquery = Query.simple(query); long start = System.currentTimeMillis(); QueryResult result = bucket.query(statement); long finish = System.currentTimeMillis();
if (result.finalSuccess()) { Iterator<QueryRow> rows = result.rows(); int rowCount = 0; while (rows.hasNext()) { QueryRow row = rows.next(); //System.out.println(row.value()); rowCount++; } //System.err.println("Rows printed: " + rowCount); } else { for (JsonObject error : result.errors()) { System.err.println(error); } }
long timeToComplete = finish-start;
logger.log(Level.FINE,timeToComplete + "Ms"); } catch(Throwable t) { logger.log(Level.WARNING, t.getMessage()); continue; } iteration++;
} }
}
So, the program logs the time it takes to receive a response from the query command and any throwables that occur during the process.
Initially it works well:
Feb 11, 2015 7:01:03 PM main.java.dp4Test.SomexpLoscouwMain main
INFO: My first log
Feb 11, 2015 7:01:07 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 1435Ms
Feb 11, 2015 7:01:07 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 460Ms
Feb 11, 2015 7:01:08 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 376Ms
Feb 11, 2015 7:01:08 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 469Ms
Feb 11, 2015 7:01:09 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 425Ms
Feb 11, 2015 7:01:09 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 384Ms
Feb 11, 2015 7:01:10 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 457Ms
Feb 11, 2015 7:01:10 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 411Ms
On other occasions the time has been in the lower 200ms range on this same machine. I remember better results on the CentOS VMs, though those were with a different test than the one used here. Regardless of the usual results, however, in all cases there are occasional hiccups:
Feb 11, 2015 7:11:34 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 44824Ms
Feb 11, 2015 7:11:50 PM main.java.dp4Test.SomexpLoscouwMain main
WARNING: java.lang.IllegalStateException: Error parsing query response (in TRANSITION) at
Feb 11, 2015 7:11:51 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 309Ms
or
Feb 11, 2015 7:13:01 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 518Ms
Feb 11, 2015 7:13:02 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 832Ms
Feb 11, 2015 7:13:21 PM main.java.dp4Test.SomexpLoscouwMain main
FINE: 19066Ms
These become more frequent the longer the process runs. Eventually, I am able to notice the effects while I perform other tasks as this runs in the background.
Any thoughts on this? Should this type of volume be possible come GA, beta or alpha? Also, would there be a more appropriate way to go about making repetitive calls over a long period?
As an aside, I noticed that the SDK uses observables, which I am rather unfamiliar with. I was wondering if I need to take this into account to prevent calls from conflicting with each other.
Thank you for your time.