Comments (6)
那我知道你这个问题在哪了,etcd实现在进行diff的时候是使用了DefaultDiff
,而DefaultDiff
只对addr
进行了判断,这个是基于云环境下不可变实例的假设来做的,不过控制面动态修改权重确实是有效需求,DefaultDiff
的逻辑我来修正下吧,cc @HeyJavaBean
kitex/pkg/discovery/discovery.go
Lines 72 to 102 in f43dcb5
from kitex.
我觉得这个场景的需求不该通过强行设置负载均衡切留来实现
正常的解决方案是:你的服务1重启,在服务发现环节,服务1被剔除掉了,所以client的可用下游里面就没有服务1。当服务1完成重启后,重新注册回来,流量就正常分摊给5个下游了。
要达到上面的效果,你需要配合注册中心、健康检查这些手段来实现对应的代码。
from kitex.
@HeyJavaBean 我现在的业务就是你说的这种方式实现的。对于不需要100%保证业务无影响的情况下这样是没问题,但是要确保重启的绝对安全还是要无业务的情况下才稳妥,所以想到了先切流量再重启。
from kitex.
那我感觉从负载均衡可能做不到。不过既然你能知道要下线A服务(比如你还知道他的IP什么的),你可以尝试通过kitex的自定义服务发现resolver例添加逻辑,直接判断然后拦截掉A的服务发现结果?
from kitex.
不过从Picker创建的实现来看,权重为0的实例会被过滤掉,不会出现说流量分配到权重为0的实例的情况,可以给下Kitex初始化代码以及版本么
kitex/pkg/loadbalance/weighted_balancer.go
Lines 93 to 106 in f43dcb5
from kitex.
@jizhuozhi 如下:
- kitex版本:kitex --version =》v0.9.1
- 初始化Client:
c, err := demo.NewClient(
variable.BuildClientName(hd.name()),
client.WithMuxConnection(2),
client.WithRPCTimeout(60time.Second),
client.WithLoadBalancer(loadbalance.NewWeightedRandomBalancer()),
client.WithConnectTimeout(10time.Second),
client.WithFailureRetry(newFailurePolicy()),
client.WithResolver(reg),
)
操作流程:
- 2个微服务(A,B)正常启动后,ETCD里的weight都为10,此时2个微服务负载比例50%;
- 调整ETCD中A服务的weight=0,即使等待一会后,A服务还是会有流量,不会为0
- 调整ETCD中B服务的weight=9999999,A服务的weight不修改仍为10,此时流量基本都到A服务了,B服务基本没流量(目前我是采用这种方案在切流量)
from kitex.
Related Issues (20)
- 客户端访问服务出现 cannot assign requested address HOT 5
- kitex自定义脚手架模板里想获得hello.thrift里namespace怎么获得 HOT 4
- kitex会考虑和wego一样模版内置sprig函数吗? HOT 1
- Remove Go version restrictions for newer versions HOT 5
- 请求帮助:kitex 单 Server 多 Service HOT 14
- 篡改自定义nacos注册信息 HOT 3
- 自定义模板生成报错 HOT 1
- WithCodec 似乎没生效
- 通过jmeter压测工具调用服务端报错:no kitex compressor registered found for:gzip HOT 2
- 会不会支持最新版本的 thrift HOT 1
- thrift 好像不兼容 HOT 8
- 泛化调用的IDL无法解析官方推荐的字段校验 HOT 4
- 关于 Error 的一些疑问 HOT 10
- Failed to detect current executable: cannot find executable path HOT 3
- 监控server侧回调缺乏信息 HOT 2
- 服务几天没访问后就访问不了了 HOT 2
- 用hertz当client端去调用kitex的时候偶尔会出现KITEX: New grpc Client connection failed, network-unilx, address-go-online-sales-auth-v2:8080, error-dial unix go-online-sales-auth-v2:8080: connect: no such file or directorv 重启一下client就好了 HOT 7
- 连接方式使用长连接池小概率报错 HOT 3
- Bug Report: 使用生成工具生成的代码包路径错误 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kitex.