I have java spring boot application hosted on azure app service. I am running a optic query to select columns from a table with almost 10 million records. I am doing pagination using offset limit and only selecting 25 records per page.
The query runs very fast(<1 sec) in query console but it take on average 15 seconds from the application to run.
I am using Modifyplan and rowmanager in Marklogic Java client.
I am running this on production server with 3 primary and 3 secondary node. The cache settings on the group level is set to automatic.
I have tried running query with xdmp:query-meters in query console and I can see it is using triple index cache and triple index vale cache. I am expecting a response of few seconds from this application as it is further used in web applications.
The code is in client machine but it is something like this:
BasicAuthContext basicAuthContext = getBasicAuthContext(false, user,password);
DatabaseClient databaseClient= DatabaseClientFactory.newClient(host,port, "dh-FINAL",basicAuthContext);
Rowmanager rowManager= databaseClient.newRowManager();
PlanBuilder op = rowManager.newPlanBuilder();
//getTradePlan method create a queryplan
ModifyPlan plan = getTradePlan(op);
try(RowSet rows: rowManager.resultRows(plan))
This above line is where the query is executed and which takes more time in the code than in query console.
Make sure you are executing the query as the same user when comparing performance. If you are running as a user with the
adminrole in Query Console, then it may run faster than when executed by the Java client as a non-admin user. Queries executed as a user with theadminrole will bypass some security checks and avoid overhead that can make a big difference in execution times.https://help.marklogic.com/Knowledgebase/Article/View/query-performance-difference-between-admin-vs-non-admin-user
Depending upon the details, you might be able to tune the query to be more efficient. You might also consider using AMPS in order to boost the performance of some components of the query, or wrap it all in a function and AMP the entire thing, depending upon whether that makes sense for your data and security model.
https://help.marklogic.com/knowledgebase/article/View/109/0/lexicon-performance-at-scale