pmwkaa / sophia

Modern transactional key-value/row storage library.
http://sophia.systems
Other
1.86k stars 153 forks source link

stats: min latency miscalculated #161

Closed BrunoBonacci closed 6 years ago

BrunoBonacci commented 6 years ago

Hi,

The min latency is always 0.

I think the issue is here: https://github.com/pmwkaa/sophia/blob/73f5bc64a5239d6ea70e550e166674cb1b38a678/sophia/std/ss_avg.h#L27

static inline void
ss_avginit(ssavg *a)
{
    a->count = 0;
    a->total = 0;
    a->min = 0;  // min should be initialized to -1
    a->max = 0;
    a->avg = 0;
}

and the update function here: https://github.com/pmwkaa/sophia/blob/73f5bc64a5239d6ea70e550e166674cb1b38a678/sophia/std/ss_avg.h#L38

static inline void
ss_avgupdate(ssavg *a, uint32_t v)
{
    a->count++;
    a->total += v;
    a->avg = (double)a->total / (double)a->count;
    if (v < a->min)      // v will never be less than 0 therefore this always false
        a->min = v;
    if (v > a->max)
        a->max = v;
}

this should be something like:

    if (v < a->min || a->min == -1)     
        a->min = v;

So that the first time the a->min is initialized with the first value.

pmwkaa commented 6 years ago

Oh yeah, Thank you. I wonder how i missed that.