Skip to content

Commit

Permalink
Tidy formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed May 6, 2024
1 parent ac4cc14 commit 3997461
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/Equinox.CosmosStore/CosmosStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ module Log =
Interlocked.Increment(&x.count) |> ignore
Interlocked.Add(&x.rux100, int64 (ru * 100.)) |> ignore
if ru < x.minRu then Interlocked.CompareExchange(&x.minRu, ru, x.minRu) |> ignore
elif ru > x.maxRu then Interlocked.CompareExchange(&x.maxRu, ru, x.maxRu) |> ignore
if ru > x.maxRu then Interlocked.CompareExchange(&x.maxRu, ru, x.maxRu) |> ignore
Interlocked.Add(&x.ms, ms) |> ignore
type internal Counters() =
let buckets = System.Collections.Concurrent.ConcurrentDictionary<string, Counter>()
Expand Down Expand Up @@ -343,29 +343,45 @@ module Log =
if Array.isEmpty buckets then () else

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 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 ()
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
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 maxRu minRu ru lat =
let aru, ams = (if count = 0L then Double.NaN else ru/float count), (if count = 0L then Double.NaN else float lat/float count)
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 -> totalRRu <- totalRRu + ru; "R"
| _ -> totalWRu <- totalWRu + ru; "W"
log.Information("{bucket} {act,-8}: {count,5}r {ru,7:g0} {max,4:f1}-{min,4:f0} {rut:l}RU avg={avgRu,4:f1} RU {lat,4:g0} ms",
bucket.PadRight maxBucketLen, act, count, ru, minRu, maxRu, rut, aru, ams)
| "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.maxRu stat.minRu ru 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
| _ -> ()
if rows > 1 then logActivity "TOTAL" totalCount 0 0 (totalRRu + totalWRu) totalMs
let measures: (string * (TimeSpan -> float)) list = [ "s", _.TotalSeconds ]
let logPeriodicRate name count rru wru = log.Information("{bucket} {count:n0} rp{unit} @ {rru,5:f1}/{wru,5:f1} R/W RU",
bucket.PadRight maxBucketLen, count, name, rru, wru)
for uom, f in measures do let d = f res.Elapsed in if d <> 0. then logPeriodicRate uom (float totalCount/d |> int64) (totalRRu/d) (totalWRu/d)
if rows > 1 then logActivity "TOTAL" totalCount min max (totalRRu + totalWRu) totalMs
null |> logOnCatChange


[<AutoOpen>]
module private MicrosoftAzureCosmosWrappers =
Expand Down

0 comments on commit 3997461

Please sign in to comment.