Comments (9)
@LearningGp @ZShUn
#1383 是2020年开发的,当时参考了Dubbo和Sofa框架的SPI,对Sentinel原有使用JDK的SPI做了增强,为了后续方便扩展。
为避免多个SPI实现冲突问题,当时考虑的是classLoader.getResource
如果遇到重复的情况,检查出后抛出异常提示,这样让开发者早点发现问题,去解决冲突。
在工作中的项目也有使用到,因为项目里Sentinel依赖是唯一的,也没有使用agent,线上一直稳定运行没有遇到这个问题。
抱歉确实没想到有项目里存在多个Sentinel包的情况,钉钉群里看到@ZShUn反馈这个场景,在#3377 对此进行修复。
@ZShUn SpiLoader中的异常实际是防止重复初始化,我们只需要保证初始化一次就好
赞同该思路;
想到的处理方法:检查到SPI实现类重复时,程序不抛异常,在日志中记录该情况便于排查,已解析过的扩展类跳过处理,让程序正常运行。相对以前抛异常的方式,这样可能灵活友好一些,不响应SPI的功能和程序的运行。
注:以前是通过classMap
里的key(Spi
注解里的value别名或者实现类名称)来验证重复的,这是导致本场景出现问题的原因,因为本场景是jar包重复,即多个文件里实现类名重复,而不是别名,应该通过类或类名来验证。因此修改后的代码在该验证的前面通过classMap
的value(实现类)来判断是否重复,如果重复则跳过继续处理;如果是不同实现类,Spi里的value重复,还是抛异常提示,因为这种是实现类的别名有冲突,提醒开发者去及时处理,它跟jar包重复这个场景不同;这种场景如果也跳过处理,则有优先级的问题,不确定是具体哪个SPI实现类优先。
maven构建项目可使用<dependencyManagement>
统一管理依赖包版本,让项目里Sentinel相关jar唯一且版本号一致;但同时使用agent的情况,导致项目里的Sentinel包重复,进一步SPI文件重复。需修改SpiLoader的处理方式,提高容错性、兼容性。
from sentinel.
from sentinel.
应用服务 Sentinel文件路径:
jar:file:/D:/xxx/maven/localRepository/com/alibaba/csp/sentinel-core/1.8.7/sentinel-core-1.8.7.jar!/META-INF/services/com.alibaba.csp.sentinel.slotchain.ProcessorSlot
Agent Sentinel 文件路径:
jar:file:/D:/project/xxx/agent/xxx-agent-0.0.1-SNAPSHOT.jar!/META-INF/services/com.alibaba.csp.sentinel.slotchain.ProcessorSlot
from sentinel.
初步看起来原因是 JVM 中存在两份 Sentinel ,我理解这是不太合理的,即便 spi 这边不抛出异常,后续功能也是未定义的可能存在很多问题,最好通过 Agent 来剔除应用服务中的依赖,使得JVM中只有一份 Sentinel。
from sentinel.
SpiLoader中的异常实际是防止重复初始化,我们只需要保证初始化一次就好。因为如果不在agent中依赖sentinel,那么就无法把通用限流功能下沉。比如根据CPU或内存进行限流
from sentinel.
可以看看这个pr,#3377
from sentinel.
#3185
#3181
此类问题有已经有多个issues了,因为在实际开发中,无法避免依赖包是否会传递sentinel依赖过来,如果按照你的说法,那么用户每次都需要把传递依赖排除
from sentinel.
#1379
#1383
这是1.8.1做的spi增强pr和为什么要做spi增强,并不存在你所说的后续有什么问题。这次修复的pr也是同一个人
from sentinel.
#3185 #3181 此类问题有已经有多个issues了,因为在实际开发中,无法避免依赖包是否会传递sentinel依赖过来,如果按照你的说法,那么用户每次都需要把传递依赖排除
确实,可能有依赖传递问题,实际开发中很常见。应修改SpiLoader处理方式,让用户体验更好。
from sentinel.
Related Issues (20)
- Improve the performance and latency for the cluster limiter
- Same name fallback/blockHandler with different parameter types cause reflect exception HOT 1
- sentinel dashboard push.,支持 nacos、apollo...实现方式
- [BUG] 多个微服务拥有相同配置,相同依赖,启动后,只有一个微服务可以在控制台看到 HOT 1
- sentinel-apache-dubbo3-adapter Specifies whether the adapter supports dubbo 3.2.x
- `defaultFallback` annotation attribute on class cause `defaultFallback` handling conflicts on methods with different return types. HOT 4
- 建议给Flow/DegradationRuleManager的规则添加append方法
- [BUG] 容器环境中tokenserver检测到的机器远多于现存应用
- [BUG] 使用nacos作为规则数据源时,获取初始化配置失败 HOT 1
- [BUG] Sentinel push Mode GatewayApiDefinitionManager.ApiDefinitionPropertyListener Deserialization fail
- Integrate Sentinel, performance torture testing with increasing number of rule configurations
- [BUG] 使用来源白名单功能时,没有设置orgin的客户端请求会立即通过,功能失效。 HOT 3
- Incorrectly described in the official document 官网文档描述有误 HOT 2
- [BUG] ParamFlowRuleManager的getRulesOfResource会有空指针异常
- 请问你们的集群模式的文档是给人看的吗,感觉讲一半,配置给一半?能不能给一个直接能配置出一个集群模式的文档?
- DefaultCircuitBreakerRuleManager在1.8.8已经可用了吗
- Persistence of gateway mode flow control rules in the Sentinel dashboard
- [BUG] 熔断规则中编辑页面没有正确显示设置的统计时长 HOT 1
- sentinel 好像不支持reactor 3.5.0 以上的版本,后续有升级计划么
- How to use it in scenarios where resource names are not fixed
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 sentinel.