【springcloud 微服务】Spring Cloud Ribbon 负载均衡使用策略详解

目录

一、前言

二、什么是Ribbon

2.1 ribbon简介

2.1.1  ribbon在负载均衡中的角色

2.2 客户端负载均衡

2.3 服务端负载均衡

2.4 常用负载均衡算法

2.4.1 随机算法

2.4.2 轮询算法

2.4.3 加权轮询算法

2.4.4 IP地址hash

2.4.5 最小链接数

三、Ribbon中负载均衡策略总探究

3.1 nacos中使用ribbon过程

3.1.1 添加配置类

3.1.2 接口层调用

3.2 Ribbon中负载均衡配置策略

3.2.1 IRule

3.2.2  AbstractLoadBalancerRule

3.2.3  RandomRule

3.2.4  RoundRobinRule

3.2.5  RetryRule

3.2.6 WeightedResponseTimeRule

3.2.7 ClientConfigEnabledRoundRobinRule

3.2.8 BestAvailableRule

3.2.9 ZoneAvoidanceRule

3.2.10 AvailabilityFilteringRule

四、Ribbon负载均衡策略修改

4.1  通过配置类方式修改

4.1.1  增加一个负载均衡策略配置类

4.1.2  启动类指定负载均衡配置类

4.1.3  测试负载均衡策略是否生效

4.2  通过配置文件方式修改

4.2.1 修改启动类

4.2.2 配置文件指定具体的负载均衡策略

4.2.3 修改stock-service 的权重配置

 4.3 自定义负载均衡策略

4.3.1 自定义负载均衡类

4.3.2 配置文件中使用自定义配置类

4.3.3 启动工程并测试

4.3.4 ribbon负载均衡懒加载模式

五、Spring Cloud LoadBalancer

5.1 概述

5.1.1 RestTemplate

5.1.2 Webclient

5.2  RestTemplate 整合LoadBalancer

5.2.1 创建一个新的order模块,引入下面的依赖

5.2.2  添加如下配置文件

5.2.3 启动类

5.2.4 模拟测试

六、写在文末


一、前言

在上一篇,通过springcloud整合nacos,了解了基于nacos作为服务注册中心时实现微服务之间的快捷调用,其中,为了实现服务A对服务B的调用,在RestConfig配置类中配置RestTemplate时候,引入了一个叫做LoadBalanced的注解,于是不仅有小伙伴要问,这个注解是干嘛用的呢?本篇将详细的探讨这个问题。

二、什么是 Ribbon

2.1 ribbon简介

Spring Cloud Ribbon 是基于Netflix Ribbon 实现的一套客户端负载均衡工具,Ribbon客户端组件提供了一系列的完善的配置,如超时,重试等。

通过Load Balancer获取到服务提供的所有机器实例,Ribbon会自动基于某种规则(轮询,随机)去调用这些服务。Ribbon也可以实现我们自己的负载均衡算法。

使用SpringCloud和Ribbon实现微服务负载均衡 SpringCloud是一系列框架的集合,它利用Spring Boot的开发便利性简化了分布式系统基础设施的开发,如服务发现、配置管理、消息总线、负载均衡、断路器、数据监控等,都可以用Spring Cloud的开发模型快速构建。SpringCloud的核心思想是:构建分布式系统时,能够像开发一个简单系统一样方便,通过简单的配置,就能让系统快速启动并运行。在SpringCloud的众多组件中,Ribbon是用于客户端负载均衡的组件。 阅读详情

相关推荐

如何在VSCode中无缝集成Azure OpenAI GPT-5-codex?保姆级配置教程

本文详细介绍了在VSCode中无缝集成Azure OpenAI GPT-5-codex的完整配置教程,涵盖环境准备、Azure资源创建、本地配置、VSCode插件安装及高级定制。通过Codex CLI和config.toml文件配置,开发者可快速实现AI辅助编程,大幅提升代码生成、错误诊断和文档编写效率。

weixin_29268637的博客 565

复现YOLOv8语义分割和目标检测训练自己的数据集

训练过程首先会显示你所使用的训练的硬件设备信息,然后下一段话则是你的参数配置,紧接着是backbone信息,最后是加载信息,并告知你训练的结果会保存在runs\segment\trainxx。(1)修改数据加载配置文件,在E:\project\MODEL\YOLO\yolov8-8.2.76\ultralytics-8.2.76\ultralytics\cfg\datasets。三、训练自己的数据集,segment数据集是json格式的。如果想使用多卡训练,device='\0,1,2,xxx\'

m0_56182552的博客 2770

新手必看:四旋翼无人机PID调参实战指南(附常见问题排查)

本文为四旋翼无人机新手提供PID调参实战指南,详细解析Kp、Ki、Kd参数的实际意义及调参技巧,包含常见问题排查方法。通过系统化的调参流程和实用参考表,帮助用户快速掌握无人机飞行控制核心技能,避免常见错误,提升飞行稳定性与响应性能。

k0l1m2n3o的博客 606

2024银行科技岗笔试通关秘籍:从资料准备到实战技巧

本文系统解析了2024年银行科技岗笔试的考察内容与备考策略。文章指出,笔试是一场涵盖通用能力测试、计算机专业基础、金融科技知识和英语性格测试的复合型考试,并重点提供了数据结构与算法、计算机网络、数据库等高频考点的深度解析与实战突破技巧,帮助考生高效准备,顺利通关。

weixin_29243279的博客 123

带挂牵引车倒车运动模型推导及仿真实现

半挂牵引车在倒车时,由于鞍座主销的连接限制,其运动方式与乘用车有显著差异。例如,乘用车在右侧倒车入库时,只需确定泊车起点并将方向盘向右打死。相反,牵引车在倒车时需要先向左转方向盘,当铰接角达到防折叠的临界值时,再将方向盘向右转回,以调整牵引车与挂车至直线状态,完成泊车入库。本研究旨在建立一个基于牵引车带挂车倒车运动学模型,该模型基于以下假设: 道路在车辆行驶过程中保持平坦,无凹凸不平; 车辆以低速行驶,且在运行过程中车身不发生侧倾或俯仰; 行驶过程中,轮胎无变形,无侧向滑动,且不产

jianmo的博客 2703

【免费】最新区块链钱包和私钥的助记词碰撞器,bybit使用python开发

【免费】最新助记词钱包碰撞器,全链全网络,一周左右就有,稳定高效。

weixin_48529185的博客 1万+

【高级-RAG-优化方法】

本文介绍了两种优化RAG(检索增强生成)系统的高级方法。第一部分介绍KnowFlow项目,它采用父子分块技术,将文档分为父分块(800-1500字符)和子分块(200-400字符),通过精确匹配子分块再返回父分块内容来保证搜索精确性和上下文完整性。第二部分探讨Milvus的多种增强技术,包括查询增强(如假设问题生成、回溯提示)、索引增强(自动合并块、分层索引)、检索器增强(句子窗口检索、元数据过滤)、生成器增强(提示压缩、块排序)以及管道增强(自我反省、代理查询路由)。这些方法共同提升了RAG系统的检索效率

weixin_48585108的博客 974

支付宝个人年度账单爬虫实战:从扫码登录到数据解析的全链路解析

作为一名数据爱好者或量化分析师,获取自己的支付宝年度账单不仅是对个人消费行为的深度复盘,更是实现"数据自主权"的第一步。print(f"{row['year']}年: 收入{row['total_income']:.2f} | 支出{row['total_expense']:.2f} | 结余{row['net_savings']:.2f}"){"category": "餐饮", "amount": 12000, "count": 345},"""打开登录页,等待用户扫码,返回Cookie字典"""

2201_76125261的博客 341

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

上一篇: Spring Cloud Alibaba 整合Nacos实战
下一篇: 【springcloud 微服务】Spring Cloud Alibaba Sentinel使用详解
逆风飞翔的小叔
逆风飞翔的小叔 新星创作者: 大数据技术领域 新星创作者: 大数据技术领域
博客等级 码龄5年 1万+粉丝 219原创
评论 173
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逆风飞翔的小叔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值