mikejihbe / metrics

A metrics library for Node.js
574 stars 58 forks source link

It's necessary to invoke meter's `tick()` ever 5s for it to work properly right? #37

Open holyjak opened 7 years ago

holyjak commented 7 years ago

It's necessary to invoke meter's tick() ever 5s for it to work properly right?

If this is indeed the case then it should be documented in a comment in Meter.js and in the readme.

Thank you!

tolbertam commented 7 years ago

I think it is not necessary to call it yourself because the created EWMAs are configured to tick every 5000ms by themselves using setInterval.

I've seen in dropwizard metrics that ticking is done implicitly if necessary for the underlying EWMAs whenever a meter is marked or it's values are accessed and that it accounts for the elapsed interval (Meter.tickIfNecessary for reference). The benefit is you don't need to schedule something to do the ticks for you.

The other positive win of not using setIntervals and ticking if necessary on update/access is that it makes things a lot easier to test as one could define their own Clock implementation that you could control in your tests. What do you think of this approach? Could work pretty good, and reducing number of intervals created would be nice.