Skip to content

Commit 7dae797

Browse files
committed
Cleanup totals
1 parent e716985 commit 7dae797

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/Equinox.CosmosStore/CosmosStore.fs

+21-18
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ module Log =
271271
Interlocked.Increment(&x.count) |> ignore
272272
Interlocked.Add(&x.rux100, int64 (ru * 100.)) |> ignore
273273
if ru < x.minRu then Interlocked.CompareExchange(&x.minRu, ru, x.minRu) |> ignore
274-
elif ru > x.maxRu then Interlocked.CompareExchange(&x.maxRu, ru, x.maxRu) |> ignore
274+
if ru > x.maxRu then Interlocked.CompareExchange(&x.maxRu, ru, x.maxRu) |> ignore
275275
Interlocked.Add(&x.ms, ms) |> ignore
276276
type internal Counters() =
277277
let buckets = System.Collections.Concurrent.ConcurrentDictionary<string, Counter>()
@@ -332,33 +332,36 @@ module Log =
332332
nameof res.Prune, res.Prune
333333
nameof res.Delete, res.Delete
334334
nameof res.Trim, res.Trim |]
335+
let isRead = function nameof res.Tip | nameof res.Read | nameof res.Prune -> true | _ -> false
335336
let buckets = stats |> Seq.collect (fun (_n, stat) -> stat.Buckets) |> Seq.distinct |> Seq.sort |> Seq.toArray
336337
if Array.isEmpty buckets then () else
337338

338339
let maxBucketLen = buckets |> Seq.map _.Length |> Seq.max
340+
let duration = res.Elapsed.TotalSeconds
341+
let mutable prevCat, catR, catW, catRRu, catWRu = null, 0L, 0L, 0., 0.
342+
let inline rps count = if duration = 0 then 0L else float count/duration |> int64
343+
let inline ups ru = if duration = 0 then 0. else ru/duration
344+
let logOnCatChange (cat: string) =
345+
if prevCat = null then prevCat <- cat
346+
elif prevCat = cat then ()
347+
else
348+
let reqs = catR + catW
349+
log.Information("{bucket} {count,6}r @ {rps,5:f0} r/s {rups,5:f0} RU/s ({rrups:f0}{r:l}/{wrups:f0}{w:l})",
350+
prevCat.PadRight maxBucketLen, reqs, rps reqs, ups (catRRu + catWRu), ups catRRu, "R", ups catWRu, "W")
351+
catR <- 0; catRRu <- 0; catW <- 0; catWRu <- 0; prevCat <- cat
339352
for bucket in buckets do
340-
let mutable rows, totalCount, totalRRu, totalWRu, totalMs = 0, 0L, 0., 0., 0L
341-
let logActivity act count maxRu minRu ru lat =
342-
let aru, ams = (if count = 0L then Double.NaN else ru/float count), (if count = 0L then Double.NaN else float lat/float count)
343-
let rut = act |> function
344-
| "TOTAL" -> "" | nameof res.Tip | nameof res.Read | nameof res.Prune -> totalRRu <- totalRRu + ru; "R"
345-
| _ -> totalWRu <- totalWRu + ru; "W"
346-
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",
347-
bucket.PadRight maxBucketLen, act, count, ru, minRu, maxRu, rut, aru, ams)
353+
bucket.Substring(0, bucket.IndexOf '/') |> logOnCatChange
348354
for act, counts in stats do
349355
match counts.TryBucket bucket with
350356
| Some stat when stat.count <> 0L ->
351357
let ru = float stat.rux100 / 100.
352-
totalCount <- totalCount + stat.count
353-
totalMs <- totalMs + stat.ms
354-
logActivity act stat.count stat.maxRu stat.minRu ru stat.ms
355-
rows <- rows + 1
358+
let rut = if isRead act then catR <- catR + stat.count; catRRu <- catRRu + ru; "R"
359+
else catW <- catW + stat.count; catWRu <- catWRu + ru; "W"
360+
let inline avg x = x / float stat.count
361+
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}",
362+
bucket.PadRight maxBucketLen, act, stat.count, stat.minRu, stat.maxRu, rut, avg (float stat.ms), rps stat.count, ups ru, ru, avg ru)
356363
| _ -> ()
357-
if rows > 1 then logActivity "TOTAL" totalCount 0 0 (totalRRu + totalWRu) totalMs
358-
let measures: (string * (TimeSpan -> float)) list = [ "s", _.TotalSeconds ]
359-
let logPeriodicRate name count rru wru = log.Information("{bucket} {count:n0} rp{unit} @ {rru,5:f1}/{wru,5:f1} R/W RU",
360-
bucket.PadRight maxBucketLen, count, name, rru, wru)
361-
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)
364+
null |> logOnCatChange
362365

363366
[<AutoOpen>]
364367
module private MicrosoftAzureCosmosWrappers =

0 commit comments

Comments
 (0)