Counters are now deleted after being used, not set to zero. This solves
some issues with high load on Graphite and certain graphing functions
which require null instead of 0 counters.
@mrtazz this is a patch for a conversation you had with @holybit a couple days ago on IRC. Please let me know if you want it done any differently, but the patch pretty much mirrors the change in the following gist: https://gist.github.com/3625157
Updated stats.js to delete counters
Yeah the change looks ok, but apparently it breaks the build. Can you update the appropriate tests?
This keeps the array element there, just sets it's value to undefined.
Updating the test to work with new null count change.
Added a config option delete_counters with a default: false to control the behavior of the counters metrics to delete.
The tests are still failing on this one. Likely because we need a test with the option disabled and one with the option enabled. And then test for the different outcomes.
Tests for Delete Counters Config
Added tests for the delete counters config change.
Updated the example config docs with the new option
Any thoughts on when this might be merged?
I think we should also change this to be delete(counters[key]); as it is in the gist. I don't really see the benefit of storing it as undefined and graphite will record None anyways it it doesn't receive a value afaik. So this is more or less just wasting memory. Or am I missing something here?
> a = ['a', 'b', 'c'];
[ 'a', 'b', 'c' ]
[ 'a', , 'c' ]
> a = undefined
[ 'a', , undefined ]
I can change this line to use delete if you think the memory savings will be significant.
Depends on how you define "pretty much the same". Using delete we use less memory and don't have to loop over keys for which we aren't sending values anyways. So we are also saving some amount of CPU cycles. In the = undefined variant we just set the value to be the same as if the key didn't exist but have to store it and loop over the key. So I'd say let's go with the delete version.
Sounds good, I'll get make the change and add it to the pull by tomorrow.
Changed stats.js to use delete
Changed stats.js to use delete instead of setting the values to
undefined in order to save some memory.
Fixed the tests
Fixed the tests that were broken when changing to delete
@mrtazz I have updated the code per our conversation last night to use delete() instead of setting the counters to undefined.