Dubbo3.0 阿里大规模实践解析——URL 重构
-
前不久我们曾发表过 Dubbo 3.0 在标杆企业实战的文章,描述了 Dubbo3.0 在阿里、工商银行的实践过程、达成了单机与集群资源节省超 50% 的目标。作为 HSF2 与 Dubbo2.0 的共同继任者,Dubbo3.0 的设计目标是在阿里巴巴全面取代 HSF2 并成为下一代 云原生 服务框架,在协议、性能、服务发现模型、云原生等多个方面进行了全面升级。目前阿里内部电商系统、饿了么、 钉钉 、达摩院、阿里云等大量业务均已实现 Dubbo3.0 广泛升级,社区用户也涵盖了包括工商银行、小米、平安健康等众多企业。
要支撑阿里百万集群级实例和双十一万亿级服务调用,性能提升一直是 Dubbo3.0 关注的重点,在本篇文章中,我们将简要介绍 Dubbo3.0 性能优化的关键一环——URL 重构。
URL 简介
Aliware
定义
因特网上的可用资源可以用简单字符串来表示,该文档就是描述了这种字符串的语法和语义。而这些字符串则被称为:“统一资源定位器”(URL)
protocol://username:password@host:port/path?key=value&key=value
http://www.facebook.com/friends?param1=value1&param2=value2https://username:[email protected]:8080/list?version=1.0.0ftp://username:[email protected]:21/1/read.txt
192.168.1.3:20880url protocol = null, url host = 192.168.1.3, port = 20880, url path = nullfile:///home/user1/router.js?type=scripturl protocol = file, url host = null, url path = home/user1/router.jsfile://home/user1/router.js?type=script<br>url protocol = file, url host = home, url path = user1/router.jsfile:///D:/1/router.js?type=scripturl protocol = file, url host = null, url path = D:/1/router.jsfile:/D:/1/router.js?type=script同上 file:///D:/1/router.js?type=script/home/user1/router.js?type=scripturl protocol = null, url host = null, url path = home/user1/router.jshome/user1/router.js?type=scripturl protocol = null, url host = home, url path = user1/router.js
Dubbo 中的 URL
-
protocol:一般是 Ddubbo 中的各种协议 如:Dubbo thrift http zk -
username/password:用户名/密码
-
host/port:主机/端口 -
path:接口名称
-
parameters:参数键值对
dubbo://192.168.1.6:20880/moe.cnkirito.sample.HelloService?timeout=3000描述一个 dubbo 协议的服务zookeeper://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?application=demo-consumer&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=1214&qos.port=33333×tamp=1545721981946描述一个 zookeeper 注册中心consumer://30.5.120.217/org.apache.dubbo.demo.DemoService?application=demo-consumer&category=consumers&check=false&dubbo=2.0.2&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=1209&qos.port=33333&side=consumer×tamp=1545721827784描述一个消费者
Dubbo 2.7
Aliware
URL 结构
地址推送模型
Dubbo 3.0
Aliware
URL 结构
地址推送模型的优化
-
URL 结构上的优化
-
多级缓存
-
延迟通知
-
字符串重用
public class URLItemCache {private static final Map<String, String> PATH_CACHE = new LRUCache<>(10000);private static final Map<String, String> PROTOCOL_CACHE = new ConcurrentHashMap<>();// 省略无关代码片段public static String checkProtocol(String _protocol) {if (_protocol == null) {return _protocol;}String cachedProtocol = PROTOCOL_CACHE.putIfAbsent(_protocol, _protocol);if (cachedProtocol != null) {return cachedProtocol;}return _protocol;}public static String checkPath(String _path) {if (_path == null) {return _path;}String cachedPath = PATH_CACHE.putIfAbsent(_path, _path);if (cachedPath != null) {return cachedPath;}return _path;}}
优化结果
为方便社区用户交流, Dub bo 社区为 Dubbo3.0 用户组建了包括 Github、 钉 钉 在内的用户沟通渠道,感兴趣的读者可自行加入讨论,与社区核心开发者及用户交流分享使用经验。 Github 社区:
https://github.com/apache/dubbo/issues/9436 钉钉交流群:34129986
作者介绍: 吴治国,Apache Dubbo 社区活跃贡献者