4

We are in the process of fine-tuning our application and I am in the process of finding out the time lag between a method call. The method can be a function call or a rest process .

let $x := fn:current-time()
let $re := xdmp:http-post('http://www.somerestdomain.com',())
let $y := fn:currrent-time()
return $x - $y

or

let $x := fn:current-time()
let $re := domain:call-some-long-running-function()
let $y := fn:currrent-time()
return $x - $y

profiling this shows me XQuery engine optimize the fn:current-time() call and always assigns $x & $y as the same value.

I found this sample code which is also having some issues w.r.t to MarkLogic http://en.wikibooks.org/wiki/XQuery/Uptime_monitor

We are using MarkLogic Xml Database and Pseudo code mentioned above refers MarkLogic API

Is there any way to find out XQuery TimeOut ?

Sofia
  • 771
  • 1
  • 8
  • 22
kadalamittai
  • 2,076
  • 1
  • 16
  • 19
  • 3
    [`current-time()`](http://www.w3.org/TR/xquery-operators/#func-current-time) is [stable](http://www.w3.org/TR/xquery-operators/#stable): _Most of the functions in the core library have the property that calling the same function twice within an ·execution scope· with the same arguments returns the same result: these functions are said to be **stable**._ –  Mar 08 '11 at 19:01
  • thats a great pointer thanks. – kadalamittai Mar 08 '11 at 20:50

2 Answers2

4

Use xdmp:elapsed-time() instead of current-time(), a new function introduced in 4.2 if I am not mistaken.

As explained by Scott and in comments above current-time() is stable and will return the same value within one run, unless you would resort to using xdmp:eval(), but that would only slow down your code a lot more.

Next to this, there is a generic way to get timing information from your queries. The easiest way is to copy a part of the relevant code into CQ ( http://developer.marklogic.com/code/cq ), and hit the Profile button in there. Under the hood that uses the functions from the Profile library ( http://developer.marklogic.com/pubs/5.0/apidocs/ProfileBuiltins.html ). These return an html table with lots of timing information. Very valueable for optimizing code in MarkLogic Server.

grtjn
  • 20,254
  • 1
  • 24
  • 35
3

MarkLogic uses multiversion concurrency and basically what that means is that each transaction increments the clock by 1 period. Since $x and $y are in the same transaction then you will always return the same timestamp.

Try the following diagnostic function.

(xdmp:http-get("http://www.marklogic.com"), xdmp:query-meters())

This will return the results of your query and some diagnostic information on your query. In your case it would be like this..

(xdmp:http-post('http://www.somerestdomain.com',()), xdmp:query-meters())
Dave Cassel
  • 8,352
  • 20
  • 38
Scott
  • 106
  • 2
  • Hi Scott. nice to know the answer. infact we are using query-meters as per the suggestion by our marklogic consultants. applying query-meters across every bottle necked function call would be code-prone. is there any generic way to enable/disable this feature??? – kadalamittai Mar 08 '11 at 20:52
  • I recommend taking a look at the [Query Performance and Tuning Guide](http://developer.marklogic.com/pubs/4.2/books/performance.pdf) (read p.26). It will have some general guidelines on how to tune your application for maximum performance. Essentially you want to isolate your queries you suspect are long running and then run them in CQ for analysis. – Scott Mar 09 '11 at 00:55
  • I don't think there is a way to disable query-meters. It's intended for isolating queries and running them separately. Ask your consultants though to make sure. – Scott Mar 09 '11 at 00:59
  • 1
    Watch out for calling `xdmp:query-meters` in production code: calling that function can take some time with some queries. As grtjn mentions, `xdmp:elapsed-time` is a cleaner approach. – mblakele Dec 09 '11 at 23:55