Spring Cloud Ribbon is a client-side load balancing tool that provides client-side software load balancing algorithms and service invocation
- SpringCloud Tutorial collection: juejin.cn/collection/…
- Case project address: gitee.com/spzmmd/spri…
concept
Currently the Ribbon project is in maintenance mode
Centralized LB(Load balancing)
A separate load balancing facility (hardware, NGINx, etc.) between service providers and consumers is responsible for forwarding requests through policies
Process LB(Load balancing)
Load balancing logic is integrated with service consumers, who obtain which addresses are available from the registry and then choose the appropriate service based on the policy
Ribbon Local load balancing client vs. Nginx server Load balancing
- Nginx is a server load balancer (centralized LB). All requests are forwarded to Nginx and the load balancer is implemented by the server
- The Ribbon is a local load balancer (process LB). Clients fetch the service registry from the registry cache to the JVM local, and then implement remote RPC calls locally
integration
If the registry uses Eureka and the service consumer uses the Eureka client, there is no need to add Ribbon dependencies because the dependencies below are included
<! -- eureka client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
Copy the code
In other cases, Ribbon dependencies need to be added:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
Copy the code
In this example, we use the RestTemplate tool to support Ribbon load balancing. We only need to add @loadBalanced annotation to the RestTemplate Bean declaration.
Ribbon Load Balancing Algorithm (Understanding)
The Ribbon implements load balancing based on IRule. Common implementation algorithms are as follows:
- RoundRobinRule: indicates the default polling mode
- RandomRule: a RandomRule
- WeightedResponseTimeRule: The way weights are assigned based on response time, the faster the response, the greater the assigned value.
- BestAvailableRule: Select the method with the least concurrency
- RetryRule: During a configuration period, if the server selection fails, the system always tries to use subRule to select an available server
- ZoneAvoidanceRule: Selects a server for composite determination of performance in the zone where the Server is located and availability of the Server
- AvailabilityFilteringRule: to filter out the first example, choose the instance of concurrent smaller again
Ribbon custom load balancing algorithm
-
Polling algorithm formula server location subscript = Number of REST interface requests % Total number of server clusters
-
The custom load balancing algorithm reference blog.csdn.net/shunhua1988…
Communication & Connection
-
Welcome to join the Java Communication Group (QQ group number: 776241689)
-
Welcome to follow the public account “back-end technology learning and sharing” for more technical articles! PS: From Java back-end technology and basic computer knowledge to micro services, Service Mesh and big data, all of which are my research direction. I will regularly share technical dry goods in the public account, hoping to use my own strength, to help friends improve technical ability, common progress!
-
blog
- The Denver nuggets
- CSDN
- Blog garden
Original is not easy to reprint, please at the beginning of the famous article source and author. If my article helped you, please like/bookmark/follow it ❤❤❤❤❤❤