Java SDK query VS REST API query performance

Hi,

I’m using Couchbase version 6.5 CE,
I have basic querstion for production best practice to query to couchbase
I need to expose REST API using java
I’ve tried using both approach and doing performance test using JMeter and multiple thread

From my result, I’ve found that both approach only get max 2k request/sec

  1. What’s the best practice for my case? Is it using Query REST API or Java SDK?
  2. How to increase that request /sec ?

The Java SDK provides some value-add over calling the query REST API directly, most notably that it will automatically create concurrent connections to the query service when needed (up to 12, by default), plus we have experience in using Java Netty in an efficient way.

You may be able to get some small efficiencies from calling the REST API directly, simply because you will be able to parse the results directly into your target form rather than going through an intermediate QueryResult.
But personally I would leave this very far down any list of potential optimisations. I would first focus on getting the query itself fast, including checking the indexes, and making sure my code was efficiently performing the queries in sufficient parallelism. I would also look at whether some of the queries can be performed using the Key-Value API instead - if oyu know the keys, it is usually faster to perform KV operations.

1 Like

Hi @graham.pople,

Thanks for the fast response.
Yes, I agree using KV will be faster compare to query using index.
But in my case, I need to do the N1ql query using index.
For my question related to max request per second, is it already maximum number for 1 query node?
Is the option is multiply the index / query service to increase the value?

Thanks

I can’t really speak to whether that particular figure is approaching a maximum, query isn’t my wheelhouse. The query team may be able to help more with that. In general terms, there’s going to be a number of factors affecting single node performance (including storage speeds, CPU and network throughput), plus there’s how quickly the query itself can be parsed and run. And certainly, increasing the number of nodes should scale the throughput further. You can also try increasing the number of connections to query made by the Java SDK, along with checking that your code is efficiently parallelising the queries.

Hi @graham.pople,

How to increase number of connection from the java code?
I will try and see if there’s any changes

Thanks

You can set it like this:

                ClusterEnvironment env = ClusterEnvironment.builder().ioConfig(IoConfig.builder().maxHttpConnections(NUM_CONNECTIONS)).build();
                Cluster cluster = Cluster.connect("cluster-hostname", 
                        ClusterOptions.clusterOptions("username", "password").environment(env));
                
                // Use the cluster
                
                cluster.disconnect();
                env.shutdown();

Thanks @graham.pople,

I saw a little bit increment for the total req per sec.
Anyway how many total max connection is the best practice for production env?