Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XQuery - Log timetaken by a REST Call or a Method Call

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 ?

like image 268
kadalamittai Avatar asked Oct 21 '25 18:10

kadalamittai


1 Answers

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.

like image 149
grtjn Avatar answered Oct 26 '25 08:10

grtjn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!