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

[DISPATCHER] Maintenance of smooth weight round robin #1396

Merged
merged 10 commits into from
Jan 11, 2023

Conversation

wycccccc
Copy link
Collaborator

@wycccccc wycccccc commented Jan 6, 2023

resolve #1086

#1386
as titile, 這支pr一共做了如下幾件事:

  1. 統一使用SmoothRoundRobin處理資料的分配邏輯。
  2. 將原先在StrictDispatcher中,預排選擇節點的邏輯這一部分抽出來,變爲PreArrangementSmoothRR,方便多個Dispatcher進行使用。
  3. SmoothWeightCal只負責計算SmoothRoundRobin會用到的權重。
  4. 保證SmoothRoundRobin的thread-safe。

@wycccccc wycccccc requested a review from chia7712 January 6, 2023 09:09
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.

@wycccccc 感謝更新,這次重構得很棒,一些意見請看一下

this.roundRobinLease = roundRobinLease;
}

public static PreArrangementSmoothRR of(int preLength, Duration roundRobinLease) {
Copy link
Contributor

Choose a reason for hiding this comment

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

這個類別不錯,將統一的邏輯拉出來

這邊可以改成 package-private

var ids =
clusterInfo.nodes().stream().map(NodeInfo::id).collect(Collectors.toUnmodifiableSet());
// TODO: make ROUND_ROBIN_LENGTH configurable ???
IntStream.range(0, preLength)
Copy link
Contributor

Choose a reason for hiding this comment

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

preLength可以用roundRobin.length取代

return new PreArrangementSmoothRR(preLength, roundRobinLease);
}

synchronized void tryToUpdateRoundRobin(
Copy link
Contributor

Choose a reason for hiding this comment

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

tryToUpdate就好,因為這隻類別已經知道是RR了

import org.astraea.common.admin.NodeInfo;
import org.astraea.common.admin.ReplicaInfo;

public class PreArrangementSmoothRR {
Copy link
Contributor

Choose a reason for hiding this comment

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

可否改叫做RoundRobinKeeper

@@ -42,6 +42,30 @@ static <E> RoundRobin<E> smooth(Map<E, Double> scores) {
*/
Optional<E> next(Set<E> availableTargets);

/**
* Given initial key-score pair, it will output a preferred key with the highest current weight.
Copy link
Contributor

Choose a reason for hiding this comment

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

這個註解很棒

});
}

private double standardDeviationImperative(double avgMetrics, Map<E, Double> metrics) {
Copy link
Contributor

Choose a reason for hiding this comment

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

這段邏輯可否整合到Dispersion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

已經整合過去了。

@chia7712 chia7712 changed the title Maintenance of smooth weight round robin [DISPATCHER] Maintenance of smooth weight round robin Jan 7, 2023
@chia7712
Copy link
Contributor

chia7712 commented Jan 7, 2023

@wycccccc 標題現在要加上一些簡單的分類,到時候合併的時候請注意一下

@chia7712
Copy link
Contributor

chia7712 commented Jan 7, 2023

@wycccccc 接下來會有一些基礎上的變更針對 dispatcher(例如 #1401) 因此要麻煩你跟著變更調整程式碼,謝謝

@wycccccc
Copy link
Collaborator Author

標題現在要加上一些簡單的分類,到時候合併的時候請注意一下

好,之後會注意

接下來會有一些基礎上的變更針對 dispatcher(例如 #1401) 因此要麻煩你跟著變更調整程式碼,謝謝

瞭解,我再持續關注

上述問題都已處理完畢,再麻煩review。

@chia7712
Copy link
Contributor

@wycccccc 抱歉,又有一些衝突,可否在麻煩處理一下。等你這次處理完我們先完成這個 PR 再進行後續的修改

@wycccccc
Copy link
Collaborator Author

抱歉,又有一些衝突,可否在麻煩處理一下。等你這次處理完我們先完成這個 PR 再進行後續的修改

衝突已經修復,有問題我再及時處理,爭取今日睡前可以merge

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 重構的不錯

@chia7712 chia7712 merged commit 5da761c into opensource4you:main Jan 11, 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.

SmoothWeightRoundRobinDispatcher 本身必須 thread-safe
2 participants