Closed zllovesuki closed 6 years ago
The idea is great! You can measure the latency because there is PING/PONG feature in the protocol. It measures the latency between nodes. So we need to create a new Strategy (similar to CpuUsageStrategy), which ping the remote nodes with a timer and collect the current latency times. And in the select
method, it selects a node according to the latency (with sampling).
I will have a look into the source more when I find time... Also need to figure out how to measure latency efficiently and effectively.
Again, I would use heartbeat
to measure latency passively if I can, but not without changes in the protocol...
EDIT: although as per #230, heartbeat
does not work on tcp
transporter.
Merged.
@zllovesuki Could you help me to edit "Strategies" page & add Latency strategy with example in the docs?
Page: http://moleculer.services/0.12/docs/service-registry.html Edit: https://github.com/moleculerjs/site/edit/master/source/0.12/docs/service-registry.md
Thanks!
My current setup is as follows: DC A: two
moleculer
services DC B: twomoleculer
services DC C: onemoleculer
services Transporter: gnatsd with TLS on all nodes (eachmoleculer
ServiceBroker is connected to its localgnatsd
) Persistent data backend: RethinkDB replicated in all DCsHowever, DC C is relatively far away (100ms) from A/B (10ms). Currently if I call an action via the web gateway, some of the requests will be routed to DC C even though I'm requesting from DC A.
db-slugsurvival-*.*
are running on the RethinkDB hosts for database calls, but the rests are scattered and in different environments to be resilient to failures.Proposal
Implement some sort of latency-based balancer (like something that Cassandra does). Currently,
moleculer
already has a CPU-based balancer. So we can probably extend on that one somehow...Issues
We don't have a reliable way of detecting "latency" if we have a
nats
transporter between all the nodes... I can see how we can determine the latency if we are runningtcp
transporter.If you are interested in my services/actions, here it is...
Maybe even a picture: