moleculer
moleculer copied to clipboard
Load Balancing on custom metric
Is your feature request related to a problem? Please describe.
I want to use custom metrics like the cpu strategy
Additional context
I have multiple instances of one service. Every service can handle a limited amount of "slots". If no slot is available the load balancer should not try to send the request to the service which has no slots available.
What is the question or problem?
I am not sure how to make a service aware of a "dynamic" value (like the cpu in the CpuStrategy) which i could use in a custom LB-Strategy.
Example:
i have 3 instances/nodes of 1 service. This service is exposing an action called "assign". The service also has a "assigncounter" which is incremented if a "service.assign" is called at the specific instance.
Now i want to Loadbalance - so i have to know which instance has the lowest "assigncounter".
So: How could a LB-Strategy access such dynamic service variables? :)
It can be only complicated way. The CPU strategy can work because CPU usage is shared between nodes, the INFO packet contains it. But a custom value is not shared and synchronized between the nodes. For this purpose, I recommend to use Redis to store and increment the value of your variable and get this value from the Redis in your Strategy.
Ah, ok. Thanks :)
Redis is already my "plan b".
Would be nice if there would be an option to register custom stats in the future.