Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed May 7, 2024
1 parent 3997461 commit 812e0e2
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions src/Equinox.CosmosStore/CosmosStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -344,45 +344,34 @@ module Log =

let maxBucketLen = buckets |> Seq.map _.Length |> Seq.max
let duration = res.Elapsed.TotalSeconds
let mutable lastCat, catR, catW, catRRu, catWRu = null, 0L, 0L, 0., 0.
let mutable prevCat, catR, catW, catRRu, catWRu = null, 0L, 0L, 0., 0.
let inline rps count = if duration = 0 then 0L else float count/duration |> int64
let inline ups ru = if duration = 0 then 0. else ru/duration
let logOnCatChange (cat: string) =
if lastCat = null then lastCat <- cat
elif lastCat = cat then ()
if prevCat = null then prevCat <- cat
elif prevCat = cat then ()
else
let reqs = catR + catW
log.Information("{bucket} {count,6}r @ {rps,5:f0} r/s {rups,5:f0} RU/s ({rrups:f0}{r:l}/{wrups:f0}{w:l})",
lastCat.PadRight maxBucketLen, reqs, rps reqs, ups (catRRu + catWRu), ups catRRu, "R", ups catWRu, "W")
catR <- 0; catRRu <- 0; catW <- 0; catWRu <- 0; lastCat <- cat
prevCat.PadRight maxBucketLen, reqs, rps reqs, ups (catRRu + catWRu), ups catRRu, "R", ups catWRu, "W")
catR <- 0; catRRu <- 0; catW <- 0; catWRu <- 0; prevCat <- cat
for bucket in buckets do
bucket.Substring(0, bucket.IndexOf '/') |> logOnCatChange
let mutable rows, totalCount, totalRRu, totalWRu, totalMs = 0, 0L, 0., 0., 0L
let logActivity act count minRu maxRu totRu totLat =
let aru, ams = (if count = 0L then Double.NaN else totRu/float count), (if count = 0L then Double.NaN else float totLat/float count)
let rut = act |> function
| "TOTAL" -> " "
| nameof res.Tip | nameof res.Read | nameof res.Index | nameof res.Prune ->
catR <- catR + count; catRRu <- catRRu + totRu; totalRRu <- totalRRu + totRu; "R"
| _ -> catW <- catW + count; catWRu <- catWRu + totRu; totalWRu <- totalWRu + totRu; "W"
log.Information("{bucket} {act,-7}{count,6}r {minRu,5:f1}-{maxRu,3:f0} {rut:l}RU{lat,5:f0} ms @ {rps,5:f0} r/s {rups,5:f0} RU/s Σ {ru,7:f0} avg={avgRu,4:f1}",
bucket.PadRight maxBucketLen, act, count, minRu, maxRu, rut, ams, rps count, ups totRu, totRu, aru)
let mutable min, max = Double.MaxValue, 0.
for act, counts in stats do
match counts.TryBucket bucket with
| Some stat when stat.count <> 0L ->
let ru = float stat.rux100 / 100.
totalCount <- totalCount + stat.count
totalMs <- totalMs + stat.ms
logActivity act stat.count stat.minRu stat.maxRu ru stat.ms
if stat.minRu < min then min <- stat.minRu
if stat.maxRu > max then max <- stat.maxRu
rows <- rows + 1
let rut = act |> function
| nameof res.Tip | nameof res.Read | nameof res.Index | nameof res.Prune ->
catR <- catR + stat.count; catRRu <- catRRu + ru; "R"
| _ -> catW <- catW + stat.count; catWRu <- catWRu + ru; "W"
let aru = ru/float stat.count
let ams = float stat.ms/float stat.count
log.Information("{bucket} {act,-7}{count,6}r {minRu,5:f1}-{maxRu,3:f0} {rut:l}RU{lat,5:f0} ms @ {rps,5:f0} r/s {rups,5:f0} RU/s Σ {ru,7:f0} avg={avgRu,4:f1}",
bucket.PadRight maxBucketLen, act, stat.count, stat.minRu, stat.maxRu, rut, ams, rps stat.count, ups ru, ru, aru)
| _ -> ()
if rows > 1 then logActivity "TOTAL" totalCount min max (totalRRu + totalWRu) totalMs
null |> logOnCatChange


[<AutoOpen>]
module private MicrosoftAzureCosmosWrappers =

Expand Down

0 comments on commit 812e0e2

Please sign in to comment.