Spring Cloud Ribbon Load Balancer Class 1

Source: Internet
Author: User

The Ribbon is implemented through the Iloadbalancer interface of the RIBBO when it implements client load balancing.

Abstractloadbalancer

is an abstract implementation of the Iloadbalancer interface, which defines a grouping enumeration class ServerGroup

Also implements a Chooseserver () method, where key is null, indicating that the condition of the key is ignored when the specific instance is selected

Two abstract methods are also defined

Getserverlist (ServerGroup ServerGroup): Get a different instance list based on group type

Getloadbalancerstats (): Defines the method that gets the Loadbalancerstats object.

The Loadbalancerstats object is used to store the current properties and statistics for each service instance in load balancing.

Baseloadbalancer

is the basic implementation class for Ribbon load balancing,

Defines and maintains a list of two storage service instance server objects. A checklist for storing all the service instances,

A list of instances for storing normal services

A Loadbalancerstats object that defines the properties and statistics for each service instance

Defines a Iping object that checks whether a service instance is functioning properly, defaults to NULL, and constructs a time injection

Defines the execution policy object ipingstrategy for checking service instance operations, in Baseloadbalancer

Serialpingstrategy is used by default, traverse check

Irule object that defines the processing rules for load balancing, from Baseloadbalancer

Chooseserver (Object key), which actually delegates the selection task to the Irule.choose () method, Irule defaults to

Roundrobinrule

Start ping Task: In the default constructor of Baseloadbalancer, a task is started directly to check if server is healthy

Dynamicserverlistloadbalancer<t>

An extension to the underlying load balancer. In this load balance, the dynamic updating ability of the service instance inventory is realized.

At the same time, it also has the filtering function of the service instance list. Add the following

Serverlist<t> Serverlistimpl

The ServerList inheritance structure is as follows

Has more than one ServerList implementation class in it, what is the specific implementation of the ServerList default configuration in Dynamiceserverlistloadbalancer?

Since the dynamic update of the service instance needs to be implemented in the load balancing class, the Ribbon has the ability to access the Eureka to obtain the service instance, in the package

Org.springframework.cloud.netflix.ribbon.eureka, you can find the configuration class Eurekaribbonclientconfiguration, find the following

A Domainextractingserverlist instance created here, in this class of source, also defines the class as a serverlist list. At the same time to Getinitiallistofservers ()

and Getupdatedlistofservers () are actually delegated to the internally defined ServerList list object

Implemented by the discoveryenabledniwsserverlist passed in by the constructor method.

In the Discoveryenableniwsserverlist

In the Obtainserversviadiscovery () method

The main logic is that by relying on eurekaclient to obtain a list of specific service instances Instanceinfo from the service registry, Vipaddress can be understood as a logical service name such as User-service

Then traverse, find an instance of up to convert to Discoveryenabledserver object, return

The returned results list is in the Domainextractingserverlist class and will continue to be processed by the Setzones () method

  Serverlistupdater

In the Dynamicserverlistloadbalancer class in attribute Serverlistupdater

is mainly the update to the ServerList,

and serverlistupdater the implementation of the class is not many, as follows

Pollingserverlistupdater: The default policy for dynamic service list updates, which is the default implementation in Dynamicserverlistloadbalancer,

It is updated with timed tasks

Eurekanotificationserverlistupdater need to use Eureka event listeners to drive update operations for the list of services

Serverlistfilter

Back to the Updateaction.doupdate () method, in Dynamicserverlistloadbalancer, call the Updatelistofservers () method

Call the previously mentioned serverlist.getupdatedlistofservers () to get a list of available instances of the service from the Eureka server.

Through Serverlistfilter filter filtering, the inheritance relationship is as follows

Abstractserverlistfilter: Defines an important object that is required for class filtering loadbalancerstats, which stores properties and statistics, etc.

Zoneaffinityserverlistfilter: This filter is based on "zone Affinity" to implement the filter of the service instance, the source code

After filtering, the Shouldenablezoneaffinity () method is used to determine whether the Zone Awareness feature is enabled.

Use Loadbalancerstats.getzonesnapshot () to get the underlying metrics (including number of instances, number of breaker disconnects, number of active requests, average instance load, etc.) for the same region instance after filtering

Based on a series of algorithms, the following evaluation values are calculated and compared with the threshold values set, and if a condition is met, "zone awareness" is not enabled.

can be realized when the cluster has a regional failure, can still rely on other regions of the instance for the normal service of high-availability protection.

Blackoutserverpercentage: Percentage of failure instances (number of breaker disconnects/instances) >=0.8

Activerequestsperserver: instance average load >=0.6

Availablesevers: Number of available instances (number of instances-number of breaker disconnects) <2

Defaultniwsserverlistfilter fully inherits Zoneaffinityserverlistfilter, is the default NIWS (Netflix Internal Web Server) filter

Serverlistsubsetfilter:
New filters for zonepreferenceserverlistfilter:spring cloud consolidation. Use this filter by default when integrating Eureka and ribbon with Spring cloud

Filter out instances by zone

Spring Cloud Ribbon Load Balancer Class 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.