Created
October 10, 2019 18:50
-
-
Save prestonmcgowan/2e6546d96bcc8f66c5b595333dc61ecb to your computer and use it in GitHub Desktop.
Queries Per Second (qps) Bucketing for Analysis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
(: Queries Per Second Bucketization | |
: Requires a "last-executed" dateTime range index | |
:) | |
declare function local:qps($duration, $number) { | |
$number div ( $duration div xs:dayTimeDuration('PT1S') ) | |
}; | |
let $buckets := | |
let $ignore-empty := fn:true() | |
let $ignore-details := fn:true() | |
let $amount-of-time := xs:dayTimeDuration("P14D") | |
let $bucket-size := xs:dayTimeDuration("PT60S") | |
let $total-buckets := $amount-of-time div $bucket-size | |
for $step in (1 to $total-buckets) | |
let $oldest := fn:current-dateTime() - ( $bucket-size * $step) | |
let $newest := fn:current-dateTime() - ( $bucket-size * ($step - 1) ) | |
let $searches := | |
cts:search( | |
/saved-search, | |
cts:and-query(( | |
cts:element-range-query(xs:QName("last-executed"), ">=", $oldest), | |
cts:element-range-query(xs:QName("last-executed"), "<=", $newest) | |
)) | |
) | |
let $m := map:map() | |
let $_ := map:put($m, "total", 0) | |
let $_data := | |
for $search in $searches | |
return ( | |
map:put($m, "total", map:get($m, "total") + 1), | |
map:put($m, $search/@owner, (map:get($m, $search/@owner), 0)[1] + 1) | |
) | |
return | |
if ($ignore-empty eq fn:true() and map:get($m, "total") eq 0) then () | |
else | |
<bucket start="{$oldest}" end="{$newest}" total="{map:get($m, "total")}" qps="{local:qps($bucket-size, map:get($m, "total"))}">{ | |
if ($ignore-details eq fn:true()) then () | |
else | |
for $k in map:keys($m) | |
where $k ne "total" | |
return <owner id="{$k}" searches="{map:get($m, $k)}" /> | |
}</bucket> | |
return | |
element buckets { | |
attribute max-qps { fn:max($buckets/@qps) }, | |
$buckets | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment