ExponentiallyDecayingSample is sorted wrong
felixge opened this issue · comments
The BinaryHeap used by ExponentiallyDecayingSample is sorted wrong. The highest priority item is always on top of the tree:
https://github.com/mikejihbe/metrics/blob/master/stats/exponentially_decaying_sample.js#L34
This is bad because when the sample is full, and a new value is being added, the highest priority item is removed to make room for it:
https://github.com/mikejihbe/metrics/blob/master/stats/exponentially_decaying_sample.js#L71
This probably happened because BinaryHeap#pop is poorly named. In reality it is removing the first/top element of the heap, rather than the last as the name would indicate.
The end result of this is that Histograms look very boring as they'll settle on a rather stable sample set.