Search code examples
marklogicmarklogic-9marklogic-optic-api

MarkLogic: Optics API unstable time taken/runtime


I have been playing around with MarkLogic Optics API Capabilities and noticed that the time taken to complete my code execution is unstable, where it can take up to 40 seconds or ~1-2 minutes to complete, there are also times it will also takes more then an hours which will activate a timeout error.

Is this due to caches or a certain settings that I might be missing out? Or is the low runtime due to caches from previous failed/incomplete executions? I have posted one set of my codes below as it might help in this troubleshooting.

import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy";
import module namespace ofn="http://marklogic.com/optic/expression/fn" at "/MarkLogic/optic/optic-fn.xqy";
import module namespace thsr="http://marklogic.com/xdmp/thesaurus" 
   at "/MarkLogic/thesaurus.xqy";

xdmp:set-transaction-time-limit(3600),
let $people := op:from-lexicons(
  map:entry("comments",cts:uri-reference()),
  "lexicon")
  =>op:where(
   thsr:expand(
   cts:element-word-query(xs:QName("text"),"go"), 
   thsr:lookup("/myThsrDocs/wordnet.xml", "go"),
   (), 
   (), 
   () )
  )

let $questions := op:from-sparql('SELECT * WHERE {?comment </date_commented> ?date. }', "sparql")
                => op:select(( "date", op:as('commentStr',ofn:string(op:col('comment'))) ))

return(
xdmp:elapsed-time(),
$questions  => op:join-inner(
    $people,
    op:on(
      "comments","commentStr"
    )
  )
  => op:select(("comments")) 
  => op:group-by((), op:count("Total","comments"))
  => op:result()
,
xdmp:elapsed-time()
)

Solution

  • It's probably due to different query plans being picked, and indicates a possible bug in the cost function. You should work with MarkLogic support to track down the problem and open a bug for it.