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

Implementation of ReplicationThrottler interface #478

Merged
merged 11 commits into from
Aug 8, 2022

Conversation

garyparrot
Copy link
Collaborator

這個 PR 實作對 replication 進行限流的 API

Demo

public class Ignore extends RequireBrokerCluster {

  @Test
  void aaa() {
    var bootstrap = bootstrapServers();
    var topicName = Utils.randomString();
    try (Admin admin = Admin.of(bootstrap)) {
      // create topic
      System.out.println("Create topic");
      admin.creator().topic(topicName).numberOfPartitions(2).create();
      admin.migrator().partition(topicName, 0).moveTo(List.of(0));
      admin.migrator().partition(topicName, 1).moveTo(List.of(0));

      // send data
      System.out.println("Send data");
      Sender<byte[], byte[]> sender = Producer.of(bootstrap).sender();
      IntStream.range(0, 1_000_000)
          .mapToObj(x -> sender.topic(topicName).value(new byte[1024]).run())
          .map(CompletionStage::toCompletableFuture)
          .collect(Collectors.toUnmodifiableList())
          .forEach(i -> Utils.packException(() -> i.get()));

      // limit
      System.out.println("Limit bandwidth");
      var rate = DataRate.of(10, DataUnit.MiB, ChronoUnit.SECONDS);
      admin
          .replicationThrottler()
          .limitBrokerBandwidth(
              Map.of(
                  0, BrokerThrottleRate.of(rate, rate),
                  1, BrokerThrottleRate.of(rate, rate),
                  2, BrokerThrottleRate.of(rate, rate)));
      admin
          .replicationThrottler()
          .applyLogThrottle(
              ReplicaType.Leader,
              TopicThrottleSetting.allLogThrottled(topicName));
      admin
          .replicationThrottler()
          .applyLogThrottle(
              ReplicaType.Follower,
              TopicThrottleSetting.allLogThrottled(topicName));

      // Do migration
      System.out.println("Migration");
      admin.migrator().partition(topicName, 0).moveTo(List.of(0, 1));
      admin.migrator().partition(topicName, 1).moveTo(List.of(0, 1));
      Utils.sleep(Duration.ofMillis(1000));

      // sync monitor
      System.out.println("Monitor");
      ReplicaSyncingMonitor.main(new String[] {"--bootstrap.servers", bootstrap, "--track"});
    }
  }
}

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.

@garyparrot 感謝這個方便的功能,可否麻煩你也開一隻議題來討論如何實作WEB APIs?

@brandboat FYI,如果你有興趣接著把WEB APIs完成的話

app/src/main/java/org/astraea/app/admin/Builder.java Outdated Show resolved Hide resolved
app/src/main/java/org/astraea/app/admin/Builder.java Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@garyparrot garyparrot left a comment

Choose a reason for hiding this comment

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

@chia7712 這是目前預計的設計界面,你看看這樣有沒有問題,如果沒有問題的話我再完成具體實作。

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.

@garyparrot 這次能先討論介面是個很棒的流程,希望繼續保持XDD

另外請問一下replica.alter.log.dirs.io.max.bytes.per.second這個參數有要一併支援嗎?

@garyparrot
Copy link
Collaborator Author

@chia7712 我對 Throttle API 做了一些修正,你能再看一次嗎?

另外請問一下replica.alter.log.dirs.io.max.bytes.per.second這個參數有要一併支援嗎?

我從來沒有聽過這個 config 所以做了一些研究,看起來他是源自 https://cwiki.apache.org/confluence/display/KAFKA/KIP-113%3A+Support+replicas+movement+between+log+directories

  1. Add config intra.broker.throttled.rate. This config specified the maximum rate in bytes-per-second that can be used to move replica between log directories. This config defaults to MAX_LONG. The intra.broker.throttled.rate is per-broker and the specified capacity is shared by all replica-movement-threads.

如果要加入也可以,不過要放在哪裡

  1. 放在 ReplicationThrottler 裡面,這樣有人要用的時候可能比較方便,畢竟這個和 throttle 也有點關係,雖然這個參數和 replication 無關
  2. 或是做成額外的 Admin API,不過我怕如果給每個潛在的參數都做類似的事情會使 Admin API 的界面膨脹? 或是說其實這些參數的數量沒有很多,能直接這樣做。
  3. 新則一個 ReplicaMigrator#moveto(Map<Integer, Pair<String, DataRate>>),能夠順便在指出要搬移時順便限流

我覺得就邏輯上來說這個東西可能要放在 replication throttler 外面,不過如果要避免 API 變成遙控器的話,可能要放在既有的東西上,看起來 3 可能比較好一些

@chia7712
Copy link
Contributor

chia7712 commented Aug 7, 2022

新則一個 ReplicaMigrator#moveto(Map<Integer, Pair<String, DataRate>>),能夠順便在指出要搬移時順便限流
我覺得就邏輯上來說這個東西可能要放在 replication throttler 外面,不過如果要避免 API 變成遙控器的話,可能要放在既有的東西上,看起來 3 可能比較好一些

這個概念聽起來不錯,可否開個議題追蹤?

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.

@garyparrot 介面設計的很棒,我覺得可以按圖施工了。只有幾個小建議

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 garyparrot merged commit 89c18f7 into opensource4you:main Aug 8, 2022
@garyparrot garyparrot changed the title Implementation of ReplicationThrottler Implementation of ReplicationThrottler interface Aug 8, 2022
@garyparrot
Copy link
Collaborator Author

garyparrot commented Aug 10, 2022

@chia7712

Related comment: #478 (comment)

我剛剛看到 replication throttle 設定的程式碼文件,他的流量是不是限制到每個 topic 或是整個 broker?

https://github.com/apache/kafka/blob/99b9b3e84f4e98c3f07714e1de6a139a004cbc5b/core/src/main/scala/kafka/server/DynamicConfig.scala#L47-L49

"A long representing the upper bound (bytes/sec) on replication traffic for leaders enumerated in the " +
s"property ${LogConfig.LeaderReplicationThrottledReplicasProp} (for each topic). This property can be only set dynamically. It is suggested that the " +
s"limit be kept above 1MB/s for accurate behaviour."

@chia7712
Copy link
Contributor

我剛剛看到 replication throttle 設定的程式碼文件,他的流量是不是限制到每個 topic 或是整個 broker?

Topic端需要設定有哪些replica需要被限流,然後broker端設定流量上限,之後在該節點上那些被圈到的replicas的流量就會被限制住

@garyparrot
Copy link
Collaborator Author

如果我的理解沒錯,然後 Kip 73 的內容是正確的,這個限流是套用到整個節點而非 log 層級。
也就是每個節點,針對被限制的 replication target,他們的複製流量不能超過 x byte/s
而非三個 log 有 3x bytes/s

主要是限流是針對 broker 或是 topic
我覺得他的文件內看起來是, 現在有 3 個 log 會乘上變成 3x bytes/s,和我之前的理解不太一樣

@chia7712
Copy link
Contributor

主要是限流是針對 broker 或是 topic
我覺得他的文件內看起來是, 現在有 3 個 log 會乘上變成 3x bytes/s,和我之前的理解不太一樣

你是說從原始碼來看嗎?我印象中應該不是 3x bytes,而是 x bytes

@garyparrot
Copy link
Collaborator Author

garyparrot commented Aug 10, 2022

你是說從原始碼來看嗎?我印象中應該不是 3x bytes,而是 x bytes

thanks

garyparrot added a commit to garyparrot/astraea that referenced this pull request Aug 19, 2022
commit 2bd46a0f86fe3ad9a0fabebb35e6d24e1c5e2993
Author: Zheng-Xian Li <[email protected]>
Date:   Fri Aug 19 18:35:39 2022 +0800

    AAAAAAAAAAA

commit 7a2c6f4c2e0ddb0d77909bcf4645eaf1792a9df2
Author: Zheng-Xian Li <[email protected]>
Date:   Fri Aug 19 17:35:32 2022 +0800

    yes

commit 5bea879257575c339b7f079373854e1902c44cb4
Author: Zheng-Xian Li <[email protected]>
Date:   Fri Aug 19 17:04:56 2022 +0800

    qqq

commit 6f396c3101112b0321a7709495e1a4bb274e581c
Merge: e5a7f516 23d95f0
Author: Zheng-Xian Li <[email protected]>
Date:   Fri Aug 19 16:53:13 2022 +0800

    Merge remote-tracking branch 'qoo332001/migrateCost' into Balancer

    # Conflicts:
    #	app/src/main/java/org/astraea/app/cost/HasMoveCost.java
    #	app/src/main/java/org/astraea/app/cost/MoveCost.java
    #	app/src/test/java/org/astraea/app/cost/MoveCostTest.java

commit e5a7f51678b50a4b77d9d6b8e1d281b2eadf47ae
Author: Zheng-Xian Li <[email protected]>
Date:   Fri Aug 19 16:52:15 2022 +0800

    fix merge

commit 21fc423a05e151c825d761b5bc2c6554f1cbd3b1
Merge: 6c681fef 4e9544d
Author: Zheng-Xian Li <[email protected]>
Date:   Fri Aug 19 16:27:24 2022 +0800

    Merge branch 'main' into Balancer

    # Conflicts:
    #	app/src/main/java/org/astraea/app/App.java
    #	app/src/main/java/org/astraea/app/admin/ClusterBean.java
    #	app/src/main/java/org/astraea/app/balancer/BalancerUtils.java
    #	app/src/main/java/org/astraea/app/cost/ClusterCost.java
    #	app/src/main/java/org/astraea/app/cost/CostUtils.java
    #	app/src/main/java/org/astraea/app/cost/HasClusterCost.java
    #	app/src/main/java/org/astraea/app/cost/LoadCost.java
    #	app/src/main/java/org/astraea/app/cost/ReplicaDiskInCost.java
    #	app/src/main/java/org/astraea/app/cost/ReplicaLeaderCost.java
    #	app/src/main/java/org/astraea/app/metrics/jmx/MBeanClientImpl.java
    #	app/src/test/java/org/astraea/app/balancer/BalancerUtilsTest.java
    #	app/src/test/java/org/astraea/app/cost/ReplicaDiskInCostTest.java

commit 6c681fefe2d8a89fc6f60e6502ba4c69a87d91d8
Author: Zheng-Xian Li <[email protected]>
Date:   Fri Aug 19 16:21:13 2022 +0800

    initial

commit 4e9544d
Author: Chia-Ping Tsai <[email protected]>
Date:   Fri Aug 19 12:24:28 2022 +0800

    Pre-create hash code of NodeIno (opensource4you#600)

commit c4a4700
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Aug 18 23:08:28 2022 +0800

    Optimize dispatcher for large partitions (opensource4you#599)

commit 61d6fc5
Author: Ching-Hong Fang <[email protected]>
Date:   Thu Aug 18 15:47:03 2022 +0800

    Reconstruct `ReportFormat` (opensource4you#593)

commit 23d95f0
Author: qoo332001 <[email protected]>
Date:   Thu Aug 18 14:28:16 2022 +0800

    update

commit a544ee7
Author: Zheng-Xian Li <[email protected]>
Date:   Thu Aug 18 11:56:27 2022 +0800

    Revise `RebalancePlanProposal` (opensource4you#539)

    * revise proposal return type

    remove `Optional`

    * add javadoc

    * fix

    * fix javadoc

    * ShufflePlanGenerator should return just one plan when unable to propose

    * fix merge

commit eff7f21
Author: Zheng-Xian Li <[email protected]>
Date:   Thu Aug 18 02:43:40 2022 +0800

    Address the issue of replication throttle in Kafka broker implementation (opensource4you#594)

commit d40e970
Author: Xiang-Jun Sun <[email protected]>
Date:   Thu Aug 18 00:57:38 2022 +0800

    add costUtils (opensource4you#575)

commit 05e6623
Author: qoo332001 <[email protected]>
Date:   Wed Aug 17 04:35:11 2022 +0800

    add comment

commit 5e0e666
Merge: a3abf0c e8077e7
Author: qoo332001 <[email protected]>
Date:   Wed Aug 17 04:29:23 2022 +0800

    Merge branch 'main' of https://github.com/skiptests/astraea into migrateCost

commit a3abf0c
Author: qoo332001 <[email protected]>
Date:   Wed Aug 17 04:29:19 2022 +0800

    add moveCost

commit e8077e7
Author: Zheng-Xian Li <[email protected]>
Date:   Wed Aug 17 00:51:17 2022 +0800

    Implementation of `ReplicationThrottler` (opensource4you#574)

commit 0688360
Author: Chia-Ping Tsai <[email protected]>
Date:   Mon Aug 15 13:25:11 2022 +0800

    Upgrade zookeeper from 3.7.0 to 3.7.1 (opensource4you#587)

commit 7232e14
Author: Xiang-Jun Sun <[email protected]>
Date:   Sun Aug 14 23:51:51 2022 +0800

    removeMapByPartition (opensource4you#583)

    * removeMapByPartition

    * fix issues

    * remove redundant code

    * spotless

    * remove redundan comment

commit 5703206
Author: Chia-Ping Tsai <[email protected]>
Date:   Fri Aug 12 19:22:58 2022 +0800

    Enable to trace the elapsed time of assigning/revoking partitions (opensource4you#581)

commit 270a058
Author: Yi-Chen Wang <[email protected]>
Date:   Fri Aug 12 17:44:28 2022 +0800

    Enhance NodeTopicSizeCost to offer partition cost  (opensource4you#569)

commit 666c5b4
Author: Chia-Ping Tsai <[email protected]>
Date:   Fri Aug 12 11:26:42 2022 +0800

    Simplify performance report (opensource4you#578)

commit 81b360f
Author: Geordie <[email protected]>
Date:   Fri Aug 12 02:27:34 2022 +0800

    Missing stacktrace when using Utils.packException (opensource4you#567)

commit 30b8996
Author: Chia-Ping Tsai <[email protected]>
Date:   Fri Aug 12 02:08:59 2022 +0800

    Enable consumer to trace all subscriptions (opensource4you#576)

commit 20de1dd
Author: Xiang-Jun Sun <[email protected]>
Date:   Thu Aug 11 19:38:19 2022 +0800

    add ClusterCost in ReplicaDiskInCost (opensource4you#563)

commit 3c45fc5
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Aug 11 14:45:39 2022 +0800

    Add simple chaos monkey to kill consumers (opensource4you#573)

commit 69303f1
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Aug 11 01:20:09 2022 +0800

    Performance tool gets hanging when number of consumers is smaller tha… (opensource4you#571)

commit ae0147a
Author: Ching-Hong Fang <[email protected]>
Date:   Thu Aug 11 00:08:49 2022 +0800

    Wait for file writer complete (opensource4you#570)

commit 0d62821
Author: Kuan-Po Tseng <[email protected]>
Date:   Wed Aug 10 23:34:25 2022 +0800

    Fix Utils.swallowException (opensource4you#572)

commit a16c6fd
Author: Chia-Ping Tsai <[email protected]>
Date:   Wed Aug 10 11:03:35 2022 +0800

    Enable to unsubscribe/resubscribe topics/partitions (opensource4you#564)

commit 1648e7b
Author: Zhi-Mao Teng <[email protected]>
Date:   Mon Aug 8 23:20:17 2022 +0800

    Translate Run Grafana (opensource4you#373)

    * Translate Run Grafana

    * Add more description and rename file

    * change picture link

    * add a link of Prometheus doc to run_grafana

    * Add a link to README

    * fixed some descriptions

commit 09b2d94
Author: Xiang-Jun Sun <[email protected]>
Date:   Mon Aug 8 21:29:27 2022 +0800

    add ClusterCost interface (opensource4you#514)

commit 89c18f7
Author: Zheng-Xian Li <[email protected]>
Date:   Mon Aug 8 19:00:03 2022 +0800

    Implementation of `ReplicationThrottler` (opensource4you#478)

commit c31a578
Author: Chia-Ping Tsai <[email protected]>
Date:   Mon Aug 8 01:29:05 2022 +0800

    Upgrade kafka from 3.2.0 to 3.2.1 (opensource4you#561)

commit 0293711
Author: Chia-Ping Tsai <[email protected]>
Date:   Mon Aug 8 01:26:31 2022 +0800

    Upgrade gradle from 7.5.0 to 7.5.1 (opensource4you#560)

commit 8d83297
Author: Zhi-Mao Teng <[email protected]>
Date:   Sun Aug 7 23:49:28 2022 +0800

    Translate run_prometheus.sh (opensource4you#485)

    * Translate run_prometheus.sh

    * delete a redundant photo

    * add more descriptions to readme

    * fixed words

commit 95a2fc7
Author: Ching-Hong Fang <[email protected]>
Date:   Sun Aug 7 21:26:27 2022 +0800

    Add Consumer Node Metrics (opensource4you#552)

commit c52ca10
Author: YiHuan <[email protected]>
Date:   Sun Aug 7 17:32:40 2022 +0800

    Add YHL to Authors (opensource4you#558)

commit 98daa0b
Author: Geordie <[email protected]>
Date:   Sun Aug 7 00:27:23 2022 +0800

    Add Kafka controller metrics (opensource4you#554)

commit d70b167
Author: chaohengstudent <[email protected]>
Date:   Sat Aug 6 15:48:04 2022 +0800

    Add Chao-Heng to author list (opensource4you#550)

commit c5f9fba
Author: Zhi-Mao Teng <[email protected]>
Date:   Sat Aug 6 14:48:38 2022 +0800

    Translate Performance Benchmark (opensource4you#374)

    * Translate Performance Benchmark

    * Add example of using performance tool

    * rename and add more description

    * add more descriptions

    * delete some descriptions

    * add more descriptions and delete some redundant words

    * fix some descriptions

    Co-authored-by: chinghongfang <[email protected]>

commit 4cb9edb
Author: Chia-Ping Tsai <[email protected]>
Date:   Fri Aug 5 21:46:12 2022 +0800

    Fix NodeLatencyCostTest#testCost (opensource4you#548)

commit 50aa89e
Author: Xiang-Jun Sun <[email protected]>
Date:   Fri Aug 5 15:56:05 2022 +0800

    simplify sizeTimeSeries (opensource4you#547)

commit b0203a7
Author: Geordie <[email protected]>
Date:   Fri Aug 5 15:13:27 2022 +0800

    Fix TopicHandlerTest#testDeleteTopic (opensource4you#545)

commit c204e85
Author: Xiang-Jun Sun <[email protected]>
Date:   Fri Aug 5 14:41:13 2022 +0800

    Remove properties in cost (opensource4you#524)

commit 0e3d480
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Aug 4 00:18:05 2022 +0800

    Apply Utils.constructCostFunction (opensource4you#538)

commit b143c0e
Author: Kuan-Po Tseng <[email protected]>
Date:   Wed Aug 3 23:56:59 2022 +0800

    Remove limit in RecordHandler#get (opensource4you#542)

commit 29fbf4e
Author: Zheng-Xian Li <[email protected]>
Date:   Wed Aug 3 23:54:47 2022 +0800

    Balance Process Demo (opensource4you#534)

commit aa8af06
Author: Geordie <[email protected]>
Date:   Wed Aug 3 00:45:07 2022 +0800

    Add delete group api (opensource4you#509)

commit 3133d89
Author: Haser0305 <[email protected]>
Date:   Tue Aug 2 23:32:42 2022 +0800

    Add Jia-Sheng Chen (opensource4you#540)

commit 75fce1a
Author: Zheng-Xian Li <[email protected]>
Date:   Tue Aug 2 00:55:26 2022 +0800

    Construct `CostFunction` via Reflection (opensource4you#535)

    * construct CostFunction by reflection

    * simple

commit f52db19
Author: Chia-Ping Tsai <[email protected]>
Date:   Sun Jul 31 21:10:48 2022 +0800

    Refactor ReplicaManager metrics (opensource4you#532)

commit c9022f2
Author: Chia-Ping Tsai <[email protected]>
Date:   Sun Jul 31 19:11:06 2022 +0800

    Refactor network metrics (opensource4you#531)

commit 5ff8628
Author: Chia-Ping Tsai <[email protected]>
Date:   Sun Jul 31 16:44:50 2022 +0800

    Refactor producer metrics (opensource4you#530)

commit c68fbdd
Author: Geordie <[email protected]>
Date:   Sun Jul 31 02:15:02 2022 +0800

    Add delete topic api (opensource4you#507)

commit 814c5d8
Author: Chia-Ping Tsai <[email protected]>
Date:   Sat Jul 30 23:55:22 2022 +0800

    Fix testDeleteRecord (opensource4you#529)

commit be13aab
Author: Chia-Ping Tsai <[email protected]>
Date:   Sat Jul 30 04:49:28 2022 +0800

    Only take recent producer metrics (opensource4you#528)

commit a45388a
Author: Chia-Ping Tsai <[email protected]>
Date:   Sat Jul 30 02:21:08 2022 +0800

    Fix node metrics (opensource4you#527)

commit 381d913
Author: Chia-Ping Tsai <[email protected]>
Date:   Fri Jul 29 22:40:51 2022 +0800

    Refactor broker topic metrics (opensource4you#521)

commit c7fb4a9
Author: Chia-Ping Tsai <[email protected]>
Date:   Fri Jul 29 22:40:22 2022 +0800

    Remove CostUtils (opensource4you#522)

commit 5d29e0a
Author: Xiang-Jun Sun <[email protected]>
Date:   Fri Jul 29 15:08:50 2022 +0800

    remove PartitionScore (opensource4you#525)

commit bc502e4
Author: Chia-Ping Tsai <[email protected]>
Date:   Fri Jul 29 00:51:43 2022 +0800

    Refactor host metrics (opensource4you#520)

commit 554d14d
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Jul 28 23:50:54 2022 +0800

    Refactor MBeanClient (opensource4you#519)

commit cb94360
Author: Ching-Hong Fang <[email protected]>
Date:   Thu Jul 28 22:38:35 2022 +0800

    Use the same unit on bytes recording (opensource4you#511)

commit f09b48a
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Jul 28 22:02:55 2022 +0800

    Refactor MemoryCost (opensource4you#518)

commit 6332d0a
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Jul 28 21:05:26 2022 +0800

    Refactor CpuCost (opensource4you#517)

commit 615d1e4
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Jul 28 20:43:37 2022 +0800

    Fix testConsumerRebalanceListener (opensource4you#516)

commit 4e787f9
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Jul 28 20:41:42 2022 +0800

    Move purgatory metrics to separate file (opensource4you#515)

commit 9a7731e
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Jul 28 12:00:23 2022 +0800

    Remove ThreadPool (opensource4you#513)

commit 5dc5de3
Author: Chia-Ping Tsai <[email protected]>
Date:   Thu Jul 28 02:01:08 2022 +0800

    Refactor Performance tool (opensource4you#512)
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