OlivierTerrien
OlivierTerrien

Reputation: 2591

Loadbalancing with Ribbon

I have a quick question about the way Ribbon choose a server.

Assuming I have two services which can be selected by Ribbon. How Ribbon knows which service to select? Does it check both services in order to know which one is less overloaded? If yes, does it call /metrics and which metric is taken into account?

Thanks a lot for your answer

Upvotes: 2

Views: 1919

Answers (1)

Pau
Pau

Reputation: 16086

Take a look the doc wiki on Github ribbon repository:

On the section Common rules is explained some rules how Ribbon determines server availability, weigth, and so on.

There are three configurable load balancing rules RoundRobinRule, AvailabilityFilteringRule and WeightedResponseTimeRule.


RoundRobinRule

RoundRobinRule

This rule simply choose servers by round robin. It is often used as the default rule or fallback of more advanced rules.

Round robin is a method to select all the abstracts in a group equitably and in a rational order, usually starting with the first element of the list until it reaches the last element and starting again from the first element.

Take a look the method choose from the class RoundRobin:.


AvailabilityFilteringRule

AvailabilityFilteringRule

This rule will skip servers that are deemed "circuit tripped" or with high concurrent connection count.

By default, an instance is circuit tripped if the RestClient fails to make a connection to it for the last three times. Once an instance is circuit tripped, it will remain in this state for 30 seconds before the circuit is deemed as closed again. However, if it continues to fail connections, it will become "circuit tripped" again and the wait time for it to become "circuit closed" will increase exponentially to the number of consecutive failures.

It can be set via Archaius which is a Netflix library for configruation management.


WeightedResponseTimeRule

WeightedResponseTimeRule

For this rule, each server is given a weight according to its average response time. The longer the response time, the less weight it will get. The rule randomly picks a server where the possibility is determined by server's weight.

To enable WeightedResponseTimeRule, set it with the load balancer via API or set the following property

<clientName>.<clientConfigNameSpace>.NFLoadBalancerRuleClassName=com.netflix.loadbalancer.WeightedResponseTimeRule

This rule selects a server randomly but taking in account its weight.

Upvotes: 5

Related Questions