haskell-github-trust / ekg-core

Library for tracking system metrics
BSD 3-Clause "New" or "Revised" License
40 stars 39 forks source link

Distribution has N/A variance and mean #24

Closed mitchellwrosen closed 5 years ago

mitchellwrosen commented 6 years ago

I'm seeing a distribution with N/A variance and mean (the json is null). I assume this is due to a division by 0, but I can't see how that's possible. I'm only using the add function which increments the count by 1.

Any idea what might be the cause? Has this been reported before?

Thanks :)

mitchellwrosen commented 6 years ago

Update: the mean and variance are NaN, not infinity, if that helps.

mitchellwrosen commented 6 years ago

Huh, this behavior is trivial for me to reproduce.

{-# language OverloadedStrings #-}

import System.Metrics
import System.Metrics.Distribution as Distribution

main :: IO ()
main = do
  s <- newStore
  d <- createDistribution "foo" s
  Distribution.add d 1
  Distribution.read d >>= print

When run with one capabilty, this prints:

Stats {mean = 1.0, variance = 0.0, count = 1, sum = 1.0, min = 0.0, max = 1.0}

But with -N2:

Stats {mean = NaN, variance = NaN, count = 1, sum = 1.0, min = 0.0, max = 1.0}
mitchellwrosen commented 6 years ago

Ah, that last data point is not interesting, just a race condition. I'm still trying to reproduce the NaN from a long-running EKG store.

mitchellwrosen commented 6 years ago

Ok, I think I understand what's happening. The distribution has 8 stripes that are combined together. If any of the stripes have not accumulated a write, the mean will be calculated as 0/0 = nan.

23Skidoo commented 5 years ago

Fixed by #25.