0.2.0 核心能力补充

路由能力补充

支持路由时 cluster 带权重

  • issue
  • 功能描述
    • 在当前的路由匹配逻辑中,router match 成功,会选中 router 中对应的 cluster,在这个功能中,一个
      router 允许配置多个带有权重的 cluster,在 router 匹配成功的时候,会根据 cluster 的 weight 随机返回某一个cluster
  • 配置示例
    ```json

    1. {
    2. "weighted_clusters":[
    3. {
    4. "cluster":{
    5. "name":"serverCluster1",
    6. "weight":90,
    7. "metadata_match":{
    8. "filter_metadata": {
    9. "mosn.lb": {
    10. "version": "v1"
    11. }
    12. }
    13. }
    14. }
    15. },
    16. {
    17. "cluster":{
    18. "name":"serverCluster2",
    19. "weight":10,
    20. "metadata_match":{
    21. "filter_metadata": {
    22. "mosn.lb": {
    23. "version": "v2"
    24. }
    25. }
    26. }
    27. }
    28. }
    29. ]
    30. }
  1. ## LB 能力补充
  2. + [issue](https://github.com/alipay/sofa-mosn/issues/91)
  3. ### 支持 host 带权重
  4. + 支持 host 上配置权重,用来做基于 weight LB 算法
  5. + 配置示例
  6. ```json
  7. {
  8. "hosts": [
  9. {
  10. "address": "11.166.22.163:12200",
  11. "hostname": "downstream_machine1",
  12. "weight": 1,
  13. "metadata": {
  14. "filter_metadata": {
  15. "mosn.lb": {
  16. "stage": "pre-release",
  17. "version": "1.1",
  18. "label": "gray"
  19. }
  20. }
  21. }
  22. }
  23. ]
  24. }

支持 smooth wrr loadbalancer

  • 算法实现: smoothWeightedRRLoadBalancer
  • 算法细节

    1. /*
    2. SW (smoothWeightedRRLoadBalancer) is a struct that contains weighted items and provides methods to select a weighted item.
    3. It is used for the smooth weighted round-robin balancing algorithm. This algorithm is implemented in Nginx:
    4. https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35.
    5. Algorithm is as follows: on each peer selection we increase current_weight
    6. of each eligible peer by its weight, select peer with greatest current_weight
    7. and reduce its current_weight by total number of weight points distributed
    8. among peers.
    9. In case of { 5, 1, 1 } weights this gives the following sequence of
    10. current_weight's:
    11. a b c
    12. 0 0 0 (initial state)
    13. 5 1 1 (a selected)
    14. -2 1 1
    15. 3 2 2 (a selected)
    16. -4 2 2
    17. 1 3 3 (b selected)
    18. 1 -4 3
    19. 6 -3 4 (a selected)
    20. -1 -3 4
    21. 4 -2 5 (c selected)
    22. 4 -2 -2
    23. 9 -1 -1 (a selected)
    24. 2 -1 -1
    25. 7 0 0 (a selected)
    26. 0 0 0
    27. */

XDS 能力补充

CDS 相关

  • issue
  • 提供 cluster 的添加和更新能力
    • 外部接口:TriggerClusterAddOrUpdate
    • 内部接口: AddOrUpdatePrimaryCluster
  • 提供 cluster 删除能力
    • 外部接口: TriggerClusterDel
    • 内部接口: RemovePrimaryCluster

      LDS 相关

  • issue
  • 提供 Listener 的添加和更新能力
    • 外部接口: AddOrUpdateListener
    • 内部接口: AddOrUpdateListener
  • 提供 Listener 的删除能力
    • 外部接口: DeleteListener
    • 内部接口: StopListenerRemoveListeners