nagisa-kunhah commented on PR #3347:
URL: https://github.com/apache/dubbo-go/pull/3347#issuecomment-5155358542

   Hi @Alanxtl , 我简单整理了一下,对当前 dubbo-go 里 Adaptive Service Throttling 相关代码做了一轮梳理。
   
   因为各个模块联系还比较大,我就以server和client两边为分界梳理了两个文档:
   
   - server 侧文档:`filter/adaptivesvc/server.md`
   - client 侧文档:`filter/adaptivesvc/client.md`
   
   目前文档里主要覆盖了这些内容:
   
   - provider 侧 adaptive service filter
   - method-level limiter
   - Hill Climbing limiter
   - consumer 侧 `adaptiveService` cluster
   - P2C 如何使用 provider 返回的 `adaptive-service.remaining`
   - 当前配置入口和使用方式
   - 主要调用链
   - 涉及的 attachments / attributes
   - server / client 两侧各自的初始化和运行时流程
   
   关于迁移到 `dubbo-go-extensions`,我建议迁移实现代码,core 继续保留接口、配置入口和字符串 key。这样依赖方向会和现有 
extensions 的模式一致。extension 依赖 dubbo-go core 的接口和注册表,dubbo-go core 不反向依赖 
extension。
   
   建议迁移到 `dubbo-go-extensions` 的模块:
   
   - `filter/adaptivesvc`:provider 侧 adaptive service filter,实现 `padasvc` 
filter 的注册和请求处理。
   - `filter/adaptivesvc/limiter`:provider 侧 method-level limiter,包括 Hill 
Climbing limiter。
   - `cluster/cluster/adaptivesvc`:consumer 侧 `adaptiveService` cluster,负责选择 
provider、写入 `adaptive-service.enabled`、读取 `adaptive-service.remaining` 并更新本地 
metrics。
   - `cluster/loadbalance/p2c`:P2C load balancer。当前 `adaptiveService` cluster 
强制使用 `p2c`,并且 P2C 当前读取的是 `metrics.HillClimbing` 这个 adaptive service remaining 
指标,所以和 adaptive service 一起迁移更完整。
   - `cluster/metrics`:consumer 侧保存 provider remaining 的本地 
metrics。`adaptiveService` cluster 写入这里,P2C 从这里读取。
   
   这些模块迁到 extensions 后,extensions 可以提供一个聚合 imports 包,例如:
   
   ```go
   import (
        _ "github.com/apache/dubbo-go-extensions/imports/adaptivesvc"
   )
   ```
   
   这个 imports 包负责 blank import 上面的实现模块,把这些实现注册到 extension registry:
   
   - `extension.SetFilter("padasvc", ...)`
   - `extension.SetCluster("adaptiveService", ...)`
   - `extension.SetLoadbalance("p2c", ...)`
   
   建议继续留在 dubbo-go core 的部分:
   
   - `common/constant` 里的字符串 key:例如 
`ClusterKeyAdaptiveService`、`LoadBalanceKeyP2C`、`AdaptiveServiceProviderFilterKey`、`AdaptiveServiceEnabledKey`、`AdaptiveServiceRemainingKey`、`AdaptiveServiceInflightKey`。保留这些
 key 可以减少兼容性影响。
   - 
配置字段:`consumer.adaptive-service`、`provider.adaptive-service`、`provider.adaptive-service-verbose`
 可以继续保留在 core。
   - 配置自动写入逻辑:consumer 侧继续把 `adaptive-service` 转成 `cluster=adaptiveService` / 
`loadbalance=p2c`,provider 侧继续把 `adaptive-service` 转成 `service.filter=padasvc`。
   - 公开 options:例如 
`WithClusterAdaptiveService()`、`WithClientClusterAdaptiveService()`、`WithLoadBalanceP2C()`、`WithClientLoadBalanceP2C()`、`WithServerAdaptiveService()`、`WithServerAdaptiveServiceVerbose()`。这些
 option 只设置字符串 key,可以继续留在 core。
   
   需要调整的是注册入口:`imports/imports.go` 不应该 import `dubbo-go-extensions`,否则会形成 
`dubbo-go -> dubbo-go-extensions -> dubbo-go` 的 module 依赖环。迁移后用户需要额外引入 
extensions 的 imports 包来注册实现,例如同时引入:
   
   ```go
   import (
        _ "dubbo.apache.org/dubbo-go/v3/imports"
        _ "github.com/apache/dubbo-go-extensions/imports/adaptivesvc"
   )
   ```
   
   这样 core 继续负责配置和 key,extensions 负责实现和注册,用户侧通过 imports 提供可被配置引用的实现。
   
   另外,提到的优化,我们可以在迁移过程中进行优化和测试。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to