feature: introduce /load endpoint for self-reported quantised NymNode load #5326
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.
this PR introduces a new
/load
endpoint on aNymNode
to return its current load.it returns the following data:
where
Load
is quantised into the following buckets / tiers:the actual values for
NodeLoad
are determined as follows:eth
interfaces and scale them to the range of 0-1Gbps (for this initial iteration I assume the maximum network speed is 1Gbps which would be treated as fully saturated). so for example, if the node is sending at 0.5Gbps, it would get aLoad
of 0.5 and thus value ofLoad::Medium
, 0.9Gbps would getLoad
of 0.9 and value ofLoad::VeryHigh
, etc. we take the bigger value between rx and txgetloadavg
) and dividing it by the number of CPUs in the machine. for example if the average load of the machine in the last 5min was1.23
and it has 2 CPUs, then it'sLoad
would beLoad::High
(1.23 / 2 = 0.615
)Load
values, for memory usage and swap usage, i.e.:used_memory / total_memory
andused_swap / total_swap
respectively.MemoryLoad
orSwapLoad
is bigger than the current baseLoad
of the machine we have determined, if so, it's increased by one tier / bucket. For example, say the current machine load isLoad::Low
, but the memory usage is at 90% (Load::VeryHigh
). that would result in the reportedLoad
being bumped up toLoad::Medium
instead. The same logic applies with swap load, however, only if the total swap > 1GB. this is to prevent weird edge cases where the machine has hardly any swap..total
Load
uses the same "tier bumping" behaviour using the.total
and.network
loads, i.e.if network > machine
, thentotal = machine + 1
. for example ifmachine
Load
isLoad::Low
, butnetwork
Load
isLoad::Medium
, then thetotal
Load
is set toLoad::Medium
instead.This change is