当前位置:网站首页>Ribbon-负载均衡原理及部分源码
Ribbon-负载均衡原理及部分源码
2022-07-27 03:19:00 【茂桑】
前提:服务提供者有多个服务集群,不然要是只有一个服务,还负载均衡个锤子!
Ribbon负载均衡基本原理:
1、Ribbon会拦截Eureka Client客户端发出的http请求,获得服务名(userservice)
2、从Eureka中拉取动态服务列表(8081、8082。。。。。)
3、从里面选一个服务(如8081)出来(轮询、随机等算法)
4、去调用这个服务
详细步骤:
1、客户端发起http请求,比如使用RestTemplate发起;
2、LoadBalancerInterceptor负载均衡拦截器,会拦截所有这个客户端发起的http请求,进行解析,获取服务ID(实例名例如:userservice);
3、通过这个实例名,从Eureka中拉取动态服务列表;
4、Eureka返回服务列表,此时LoadBalancerInterceptor负载均衡拦截器拿到了所有的该服务实例;
5、使用IRule接口进行负载均衡,IRule规则接口包括:客户端自定义规则、轮询、随机、重试等负载均衡算法:
6、使用客户端规定好的,或者默认的负载均衡算法,从服务列表中进行选择一个,返回给RibbonLoadBanlancerClient(Ribbon负载均衡器客户端)
7、RibbonLoadBanlancerClient(Ribbon负载均衡器客户端)使用真实的ip和端口(http://127.0.0.1:8080/user/1)替换原来的“服务名+路径”(http://userservice/user/1),并发起请求
8、最终,请求到经过负载均衡之后选择的对应的服务器
当使用@LoadBalanced注解时,会自动调用spring-cloud中的Ribbon组件进行负载均衡,我们只需配置Ribbon的算法即可按我们心意进行使用
边栏推荐
- 每日一题:奇偶树
- Chapter 4 decision tree and random forest
- Is VR panoramic production a single weapon in the home decoration industry? Why is this?
- Summer meal | rich people are different from what you think (day 5) + power system power flow simulation (documents and matlab code)
- ArrayList与LinkedList区别
- 从根到叶的二进制数之和
- 2022 operation of simulated examination question bank and simulated examination platform for safety production management personnel of hazardous chemical production units
- Navicat将MySQL导出表结构以及字段说明
- Maximum subarray cumulative sum less than or equal to K
- Abstract intelligent extraction [based on Bert technology]
猜你喜欢

2022 operation of simulated examination question bank and simulated examination platform for safety production management personnel of hazardous chemical production units

Restful fast request 2022.2.2 release, supporting batch export of documents

Lixia action | Yuanqi Digitalization: existing mode or open source innovation?

452 pages, 130000 words, the overall solution of modern smart Township Xueliang project 2022 Edition

Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice

Parallels Desktop启动虚拟机“操作失败”问题解决

Redis (IX) - redis distributed lock

Subject 3: Jinan Zhangqiu line 6

Analysis of three common kinematic models of mobile chassis

Framework learning journey: init process startup process
随机推荐
商业打假系列之第一百之--无聊的制度和管理流程真的可以扔进垃圾桶-顺便分析十几个无用的Unity游戏自检项目
Subject 3: Jinan Zhangqiu line 2
PSINS工具箱中轨迹生成工具详细解析
JS to realize page Jump and parameter acquisition and loading
【SemiDrive源码分析】【驱动BringUp】41 - LCM 驱动 backlight 背光控制原理分析
零基础小白也能懂的 Redis 数据库,手把手教你易学易用!
Restful Fast Request 2022.2.2发布,支持批量导出文档
Interview question 02.05. sum of linked list
Using LCD1602 to display ultrasonic ranging
Abstract intelligent extraction [based on Bert technology]
Nonlinear optimal tracking control based on wind energy conversion system (realized by matlab code)
Detailed analysis of trajectory generation tool in psins toolbox
Interview question 16.05 factorial mantissa
CloudCompare&PCL 匹配点距离抑制
356页14万字高端商业办公综合楼弱电智能化系统2022版
DataX cannot connect to the corresponding database (yes under windows, but failed under Linux)
VR panorama gold rush "careful machine" (Part 1)
Alibaba cloud server domain name and port web page cannot access the problem record
2022 operation of simulated examination question bank and simulated examination platform for safety production management personnel of hazardous chemical production units
Search rotation sort array