feat: added the ability to disable background stats collection #1286
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Added the ability to disable background stats collection
Motivation
While running the server, without making api calls, stats are collected constantly. This leads to CPU utilisation even when the server is idle.
TLDR of the changes
DISABLE_BACKGROUND_STATS_COLLECTIONLazyObservablethat stops the "interval" if there are no observers subscribed to it.LazyObservable, in order to prevent creation of timers/schedulers when not need.I tried to keep the existing behaviour and made the feature opt-int as I was not sure if the current behaviour isn't actually the intended one.
The screenshot below shows two containers running the code changes from this PR:
docker container run -it --rm -p 80:3001 -v /:/mnt/host:ro --privileged --name bg-collect dashdot-test:amd64docker container run -it --rm -p 81:3001 -v /:/mnt/host:ro --privileged -e DASHDOT_DISABLE_BACKGROUND_STATS_COLLECTION="true" --name non-bg dashdot-test:amd64NOTE: If you try to reproduce, there is an initial CPU utilisation coming from the speed test. After the speed test is complete, CPU settles to 4%
I'm not a TS developer so any feedback is welcome. Thank you!
Related Issue(s)
Fixes: #1050