java springcloud version b2b2c social electricity supplier spring cloud distributed micro-services (four) Ribbon

A: What Ribbon that?
Ribbon is Netflix released open source project, the main function is to provide the client software load balancing algorithm, an intermediate layer connecting the Netflix service together. Ribbon client components, such as a series of perfect CI connection timeout, retry the like. Simply put, it is listed in the configuration file Load Balancer (referred to as LB) all machines behind, Ribbon will automatically help you to connect these machines based on certain rules (such as a simple polling, then connections, etc.). We are also very easy to use load balancing algorithm Ribbon customizable.

Two: LB scheme for classifying the
current mainstream LB schemes can be divided into two categories: one is centralized LB, LB that the use of a separate facility between consumer and provider services (either hardware, such as F5, the software can also be , such as nginx), the facility is responsible for the access request is forwarded to the service provider through a strategy; the other is in the process LB, LB logic integrated into the consumer side, consumer service registry learn from what addresses are available and then select a suitable own server from these addresses. Ribbon belongs to the latter, it is just a class library, integrated consumer process, consumer to get the address of the service provider through it.

Three: The main components of the workflow Ribbon
Ribbon core components (both interface types) are the following:

ServerList

Used to obtain the address list. It can be static (providing a fixed set of address), it can also be dynamic (from the registry regularly check the address list).

ServerListFilter

Only when using dynamic ServerList use policies for the use of certain filter out part of the address in the original list of services.

IRule

Select a service address as LB final result. Polling selection strategy, weighted according to the response time of the circuit breaker (Hystrix when available) and the like.

Ribbon choice at work will be to get a list of all the services available through ServerList, then ServerListFilter filter out part of the address, and finally the rest of the address by a server IRule selected as the final result.

Four: the main Ribbon provides load balancing strategy Introduction

1: Simple polling load balancing (RoundRobin)

 以轮询的方式依次将请求调度不同的服务器,即每次调度执行i = (i + 1) mod n,并选出第i台服务器。

2: random load balancing (Random)

 随机选择状态为UP的Server

3: Response time weighted load balancing (WeightedResponseTime)

 根据相应时间分配一个weight,相应时间越长,weight越小,被选中的可能性越低。

4: Load balancing polling sensing region (ZoneAvoidanceRule)

 复合判断server所在区域的性能和server的可用性选择server

Ribbon comes with comparative load balancing strategy

Here Insert Picture Description

Five: Ribbon alone

创建一个maven工程 名称 ribbon_client

 pom内容
 <dependencies>
    <dependency>
        <groupId>com.netflix.ribbon</groupId>
        <artifactId>ribbon-core</artifactId>
        <version>2.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.netflix.ribbon</groupId>
        <artifactId>ribbon-httpclient</artifactId>
        <version>2.2.0</version>
    </dependency>
</dependencies>

Social e-commerce platform source code, please add penguin beg: three four five three six II qi II fifty-nine

Guess you like

Origin blog.csdn.net/qq_42748864/article/details/93601500