You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@dubbo.apache.org by zzy_uaf <go...@qq.com> on 2021/05/29 06:27:14 UTC

回复:建议给dubbo的外部依赖包做类隔离,以降低接入和升级成本 #7865

我们的做法是dubbo版本都结果裁剪,只保留我们需要的功能.这样依赖会大幅减少.并且dubbo的依赖pom我们也会修正.




------------------&nbsp;原始邮件&nbsp;------------------
发件人:                                                                                                                        "dev"                                                                                    <konglingzhen@douyu.tv&gt;;
发送时间:&nbsp;2021年5月28日(星期五) 中午1:53
收件人:&nbsp;"dev"<dev@dubbo.apache.org&gt;;
抄送:&nbsp;"张起灵(马勇)"<mayong@douyu.tv&gt;;"白鹭(杨鹭)"<yanglu@douyu.tv&gt;;"Jeff(吴小杰)"<jeff@douyu.tv&gt;;
主题:&nbsp;建议给dubbo的外部依赖包做类隔离,以降低接入和升级成本 #7865



Hi All:


各位老师好,我是武汉斗鱼的架构师,在实际生产中发现:Dubbo依赖冲突是困扰版本升级的主要问题。


而通过类隔离,可以有效的解决版本冲突问题,因此,想和各位探讨一下:有没有可能在Dubbo 3.0版本中引入类隔离机制?


以下是我个人的一点不成熟的想法,抛砖引玉:






Environment
&nbsp; 
Dubbo version: all
&nbsp;
Operating System version: all
&nbsp;
Java version: all
&nbsp; 
Steps to reproduce this issue
&nbsp;
dubbo依赖的jar很多,在实际开发中,经常出现Dubbo跟其它框架、业务代码共jar包,导致冲突,例如:
&nbsp; 
项目接入或者升级dubbo时,经常发生jar依赖冲突,如 Dubbo + RocketMQ共存时容易遇到netty版本冲突;
&nbsp;
在升级dubbo sdk版本时,会导致依赖的jar被连带升级,很多jar包并非100%向前兼容,从而导致业务逻辑出错;
&nbsp;
有些jar虽然maven坐标不同,但代码却有重合之处,例如:io.netty 和 org.jboss.netty 二者就有重合的类。
&nbsp; 
dubbo用户反馈的冲突案例:
&nbsp; 
解决项目导入dubbo依赖项目报红叉问题
&nbsp;
跟springboot2.x dubbo集成 jar 包冲突
&nbsp;
记一次使用dubbo过程中版本冲突导致的坑
&nbsp; 
Expected Result
&nbsp; 
通过 maven-shade-plugin,对外部依赖做类隔离,可以参考 flink-shaded 这个库
&nbsp; 
相关文档:
&nbsp; 
maven-shade-plugin
&nbsp;
flink-shaded
&nbsp; 
maven-shade-plugin的工作原理如下:
&nbsp;
1). 类隔离前(不同框架引入了同1个jar的不同版本分支,导致类冲突):
&nbsp;

&nbsp;
2). 类隔离后(通过shade插件加package前缀,对外部依赖做类隔离,来消除冲突):
&nbsp;

&nbsp;
Actual Result
&nbsp; 
Dubbo的外部依赖过多,以下是1个最简单的Dubbo用法下的依赖树:
&nbsp; [INFO] +- org.apache.dubbo:dubbo:jar:2.7.7:compile [INFO] |&nbsp; +- org.springframework:spring-context:jar:4.3.16.RELEASE:compile [INFO] |&nbsp; |&nbsp; +- org.springframework:spring-aop:jar:4.3.16.RELEASE:compile [INFO] |&nbsp; |&nbsp; +- org.springframework:spring-beans:jar:4.3.16.RELEASE:compile [INFO] |&nbsp; |&nbsp; \- org.springframework:spring-expression:jar:4.3.16.RELEASE:compile [INFO] |&nbsp; +- com.alibaba.spring:spring-context-support:jar:1.0.6:compile [INFO] |&nbsp; +- org.javassist:javassist:jar:3.20.0-GA:compile [INFO] |&nbsp; +- io.netty:netty-all:jar:4.1.25.Final:compile [INFO] |&nbsp; \- org.yaml:snakeyaml:jar:1.20:compile [INFO] +- org.apache.dubbo:dubbo-dependencies-zookeeper:pom:2.7.7:compile [INFO] |&nbsp; +- org.apache.curator:curator-recipes:jar:4.0.1:compile [INFO] |&nbsp; |&nbsp; \- org.apache.curator:curator-framework:jar:4.0.1:compile [INFO] |&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; \- org.apache.curator:curator-client:jar:4.0.1:compile [INFO] |&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \- com.google.guava:guava:jar:20.0:compile [INFO] |&nbsp; \- org.apache.zookeeper:zookeeper:jar:3.4.13:compile [INFO] |&nbsp;&nbsp;&nbsp;&nbsp; +- org.slf4j:slf4j-api:jar:1.7.25:compile [INFO] |&nbsp;&nbsp;&nbsp;&nbsp; +- org.slf4j:slf4j-log4j12:jar:1.7.25:compile [INFO] |&nbsp;&nbsp;&nbsp;&nbsp; +- log4j:log4j:jar:1.2.17:compile [INFO] |&nbsp;&nbsp;&nbsp;&nbsp; +- jline:jline:jar:0.9.94:compile [INFO] |&nbsp;&nbsp;&nbsp;&nbsp; \- org.apache.yetus:audience-annotations:jar:0.5.0:compile&nbsp; 
不是所有的冲突都能通过exclude排除来解决,例如:某框架只能用低版netty,dubbo只能用高版netty 就解决不了;
&nbsp;
即便能够通过exclude来解决,也会增加程序员的负担,从而间接提高了dubbo的使用门槛、降低了开发效率。
&nbsp; 
预期收益
&nbsp;
通过 将依赖类隔离,来减少dubbo的外部依赖数量,甚至做到0依赖,降低dubbo的接入和升级成本;
&nbsp;
类隔离实施步骤
&nbsp; 
建立1个 dubbo-shaded 代码库,可参考 flink-shaded ;
&nbsp;
定义dubbo类隔离前缀,例如:org.apache.dubbo.shaded,并在社区约定业务代码不要用里面的类;
&nbsp;
把dubbo常用的外部依赖逐步加入到 dubbo-shaded 代码库,并deploy到maven中央仓库;
&nbsp;
修改dubbo的maven-shade-plugin配置,把常用的外部依赖给shade掉;
&nbsp;
逐步shade掉外部依赖,最终做到0依赖。
&nbsp; ​











相关issue:https://github.com/apache/dubbo/issues/7865







地址:武汉市东湖高新区光谷软件园F3栋(邮编:430073)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
手机:+86-187 0167 8604
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
邮箱:konglingzhen@douyu.tv&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 网址:www.douyu.com&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 


&amp;nbsp;

Re: 建议给dubbo的外部依赖包做类隔离,以降低接入和升级成本 #7865

Posted by Xeno Amess <xe...@gmail.com>.
shade有shade自己的问题

比如如果依赖中用反射通过名字取类,你shade了,要取的类的包名改了,就死了

当然了shade掉个别依赖是一个常见方案没错,比如jacoco对asm的shade,但是你说想要把全部依赖都shade了,我感觉你这属于滥用shade


关于不同依赖中出现同一个类的问题:原则上他们不该这么做
但是懂得都懂,总有人不老实。。。管不住

感觉,把这种比较大的库单独抽一个微服务,不要直接代码交互,走api交互会更加通用性。
不知道你那边能不能接受这种性能损耗


zzy_uaf <go...@qq.com> 于 2021年5月29日周六 下午2:27写道:

> 我们的做法是dubbo版本都结果裁剪,只保留我们需要的功能.这样依赖会大幅减少.并且dubbo的依赖pom我们也会修正.
>
>
>
>
> ------------------&nbsp;原始邮件&nbsp;------------------
> 发件人:
>                                                   "dev"
>                                                                 <
> konglingzhen@douyu.tv&gt;;
> 发送时间:&nbsp;2021年5月28日(星期五) 中午1:53
> 收件人:&nbsp;"dev"<dev@dubbo.apache.org&gt;;
> 抄送:&nbsp;"张起灵(马勇)"<mayong@douyu.tv&gt;;"白鹭(杨鹭)"<yanglu@douyu.tv
> &gt;;"Jeff(吴小杰)"<jeff@douyu.tv&gt;;
> 主题:&nbsp;建议给dubbo的外部依赖包做类隔离,以降低接入和升级成本 #7865
>
>
>
> Hi All:
>
>
> 各位老师好,我是武汉斗鱼的架构师,在实际生产中发现:Dubbo依赖冲突是困扰版本升级的主要问题。
>
>
> 而通过类隔离,可以有效的解决版本冲突问题,因此,想和各位探讨一下:有没有可能在Dubbo 3.0版本中引入类隔离机制?
>
>
> 以下是我个人的一点不成熟的想法,抛砖引玉:
>
>
>
>
>
>
> Environment
> &nbsp;
> Dubbo version: all
> &nbsp;
> Operating System version: all
> &nbsp;
> Java version: all
> &nbsp;
> Steps to reproduce this issue
> &nbsp;
> dubbo依赖的jar很多,在实际开发中,经常出现Dubbo跟其它框架、业务代码共jar包,导致冲突,例如:
> &nbsp;
> 项目接入或者升级dubbo时,经常发生jar依赖冲突,如 Dubbo + RocketMQ共存时容易遇到netty版本冲突;
> &nbsp;
> 在升级dubbo sdk版本时,会导致依赖的jar被连带升级,很多jar包并非100%向前兼容,从而导致业务逻辑出错;
> &nbsp;
> 有些jar虽然maven坐标不同,但代码却有重合之处,例如:io.netty 和 org.jboss.netty 二者就有重合的类。
> &nbsp;
> dubbo用户反馈的冲突案例:
> &nbsp;
> 解决项目导入dubbo依赖项目报红叉问题
> &nbsp;
> 跟springboot2.x dubbo集成 jar 包冲突
> &nbsp;
> 记一次使用dubbo过程中版本冲突导致的坑
> &nbsp;
> Expected Result
> &nbsp;
> 通过 maven-shade-plugin,对外部依赖做类隔离,可以参考 flink-shaded 这个库
> &nbsp;
> 相关文档:
> &nbsp;
> maven-shade-plugin
> &nbsp;
> flink-shaded
> &nbsp;
> maven-shade-plugin的工作原理如下:
> &nbsp;
> 1). 类隔离前(不同框架引入了同1个jar的不同版本分支,导致类冲突):
> &nbsp;
>
> &nbsp;
> 2). 类隔离后(通过shade插件加package前缀,对外部依赖做类隔离,来消除冲突):
> &nbsp;
>
> &nbsp;
> Actual Result
> &nbsp;
> Dubbo的外部依赖过多,以下是1个最简单的Dubbo用法下的依赖树:
> &nbsp; [INFO] +- org.apache.dubbo:dubbo:jar:2.7.7:compile [INFO] |&nbsp;
> +- org.springframework:spring-context:jar:4.3.16.RELEASE:compile [INFO]
> |&nbsp; |&nbsp; +-
> org.springframework:spring-aop:jar:4.3.16.RELEASE:compile [INFO] |&nbsp;
> |&nbsp; +- org.springframework:spring-beans:jar:4.3.16.RELEASE:compile
> [INFO] |&nbsp; |&nbsp; \-
> org.springframework:spring-expression:jar:4.3.16.RELEASE:compile [INFO]
> |&nbsp; +- com.alibaba.spring:spring-context-support:jar:1.0.6:compile
> [INFO] |&nbsp; +- org.javassist:javassist:jar:3.20.0-GA:compile [INFO]
> |&nbsp; +- io.netty:netty-all:jar:4.1.25.Final:compile [INFO] |&nbsp; \-
> org.yaml:snakeyaml:jar:1.20:compile [INFO] +-
> org.apache.dubbo:dubbo-dependencies-zookeeper:pom:2.7.7:compile [INFO]
> |&nbsp; +- org.apache.curator:curator-recipes:jar:4.0.1:compile [INFO]
> |&nbsp; |&nbsp; \- org.apache.curator:curator-framework:jar:4.0.1:compile
> [INFO] |&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; \-
> org.apache.curator:curator-client:jar:4.0.1:compile [INFO] |&nbsp;
> |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \-
> com.google.guava:guava:jar:20.0:compile [INFO] |&nbsp; \-
> org.apache.zookeeper:zookeeper:jar:3.4.13:compile [INFO]
> |&nbsp;&nbsp;&nbsp;&nbsp; +- org.slf4j:slf4j-api:jar:1.7.25:compile [INFO]
> |&nbsp;&nbsp;&nbsp;&nbsp; +- org.slf4j:slf4j-log4j12:jar:1.7.25:compile
> [INFO] |&nbsp;&nbsp;&nbsp;&nbsp; +- log4j:log4j:jar:1.2.17:compile [INFO]
> |&nbsp;&nbsp;&nbsp;&nbsp; +- jline:jline:jar:0.9.94:compile [INFO]
> |&nbsp;&nbsp;&nbsp;&nbsp; \-
> org.apache.yetus:audience-annotations:jar:0.5.0:compile&nbsp;
> 不是所有的冲突都能通过exclude排除来解决,例如:某框架只能用低版netty,dubbo只能用高版netty 就解决不了;
> &nbsp;
> 即便能够通过exclude来解决,也会增加程序员的负担,从而间接提高了dubbo的使用门槛、降低了开发效率。
> &nbsp;
> 预期收益
> &nbsp;
> 通过 将依赖类隔离,来减少dubbo的外部依赖数量,甚至做到0依赖,降低dubbo的接入和升级成本;
> &nbsp;
> 类隔离实施步骤
> &nbsp;
> 建立1个 dubbo-shaded 代码库,可参考 flink-shaded ;
> &nbsp;
> 定义dubbo类隔离前缀,例如:org.apache.dubbo.shaded,并在社区约定业务代码不要用里面的类;
> &nbsp;
> 把dubbo常用的外部依赖逐步加入到 dubbo-shaded 代码库,并deploy到maven中央仓库;
> &nbsp;
> 修改dubbo的maven-shade-plugin配置,把常用的外部依赖给shade掉;
> &nbsp;
> 逐步shade掉外部依赖,最终做到0依赖。
> &nbsp; ​
>
>
>
>
>
>
>
>
>
>
>
> 相关issue:https://github.com/apache/dubbo/issues/7865
>
>
>
>
>
>
>
> 地址:武汉市东湖高新区光谷软件园F3栋(邮编:430073)
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> 手机:+86-187 0167 8604
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> 邮箱:konglingzhen@douyu.tv&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> 网址:www.douyu.com&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>
>
> &amp;nbsp;