Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COST] Provide descriptive Object#toString for ClusterCosts #1473

Merged
merged 5 commits into from
Feb 3, 2023

Conversation

garyparrot
Copy link
Collaborator

Context: #1463 (comment)

這個 PR 給 ClusterCost 提供 Object#toString() 實作,該實作將會暴露關於自己分數的一些細部統計資訊。給使用者一些提示這個數字背後的故事。預期套用這個 PR 後, ClusterCost 分數背後的來源會比較透明一些。

  • 修改 ClusterCost,現在一定要透過 ClusterCost#of(double)ClusterCost#of(double,Supplier<String>) 函數來建立。
  • ClusterCost#of(double, Supplier<String>) 簽名提供一個參數來指出這個 ClusterCost 的細部資訊(以字串顯示),這個字串內容會在 HasClusterCost#of() 回傳的版本中出現。
  • 給每個 HasClusterCost 的實作添加適合的 ClusterCost 敘述字串

範例

    var clusterCost =
        HasClusterCost.of(
            Map.of(
                new ReplicaNumberCost(), 1D,
                new NetworkIngressCost(), 10D,
                new NetworkEgressCost(), 10D));
    // ...
    var plan = balancer.offer(clusterInfo, Duration.ofSeconds(10));
    System.out.println(plan.initialClusterCost());
    System.out.println(plan.solution().get().proposalClusterCost());

輸出

WeightCompositeClusterCost[{"NetworkEgressCost" cost 0.3656846459646673 weight 10.0 description {2.02 GB/seconds, 1.95 GB/seconds, 3.07 GB/seconds} }, {"NetworkIngressCost" cost 0.24225888389074973 weight 10.0 description {2.02 GB/seconds, 1.95 GB/seconds, 2.57 GB/seconds} }, {"ReplicaNumberCost" cost 0.001998001998001998 weight 1.0 description LongSummaryStatistics{count=3, sum=1001, min=333, average=333.666667, max=335} }] = 0.28959206193105586
WeightCompositeClusterCost[{"NetworkEgressCost" cost 0.18654063812123348 weight 10.0 description {2.18 GB/seconds, 2.18 GB/seconds, 2.68 GB/seconds} }, {"NetworkIngressCost" cost 1.3078499909827186E-4 weight 10.0 description {2.18 GB/seconds, 2.18 GB/seconds, 2.18 GB/seconds} }, {"ReplicaNumberCost" cost 0.08191808191808192 weight 1.0 description LongSummaryStatistics{count=3, sum=1001, min=283, average=333.666667, max=365} }] = 0.09279201491054283

手動換行後的輸出

WeightCompositeClusterCost[
  {"NetworkEgressCost" cost 0.3656846459646673 weight 10.0 description {2.02 GB/seconds, 1.95 GB/seconds, 3.07 GB/seconds} },
  {"NetworkIngressCost" cost 0.24225888389074973 weight 10.0 description {2.02 GB/seconds, 1.95 GB/seconds, 2.57 GB/seconds} },
  {"ReplicaNumberCost" cost 0.001998001998001998 weight 1.0 description LongSummaryStatistics{count=3, sum=1001, min=333, average=333.666667, max=335} }
] = 0.28959206193105586
WeightCompositeClusterCost[
  {"NetworkEgressCost" cost 0.18654063812123348 weight 10.0 description {2.18 GB/seconds, 2.18 GB/seconds, 2.68 GB/seconds} }, 
  {"NetworkIngressCost" cost 1.3078499909827186E-4 weight 10.0 description {2.18 GB/seconds, 2.18 GB/seconds, 2.18 GB/seconds} }, 
  {"ReplicaNumberCost" cost 0.08191808191808192 weight 1.0 description LongSummaryStatistics{count=3, sum=1001, min=283, average=333.666667, max=365} }
] = 0.09279201491054283

@garyparrot garyparrot self-assigned this Feb 1, 2023
Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@garyparrot garyparrot merged commit d71e8d4 into opensource4you:main Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants