kafka限制数据迁移期间的带宽使用

限制数据迁移期间的带宽使用

Kafka允许您对复制流量应用限制,设置用于将副本从一台机器移动到另一台机器的带宽的上限。这在重新平衡群集,引导新代理或添加或删除代理时非常有用,因为它限制了这些数据密集型操作对用户的影响。

有两个接口可用于接合油门。最简单,最安全的是在调用kafka-reassign-partitions.sh时应用节流,但kafka-configs.sh也可用于直接查看和更改节流值。

因此,例如,如果您要执行重新平衡,使用以下命令,它将以不超过50MB / s的速度移动分区。

1

$ bin/kafka-reassign-partitions.sh --zookeeper myhost:2181--execute --reassignment-json-file bigger-cluster.json —throttle 50000000

执行此脚本时,您将看到油门参与:

1

2

The throttle limit was set to 50000000 B/s

Successfully started reassignment of partitions.

如果您希望更改限制,在重新平衡期间,比如增加吞吐量以便更快地完成,您可以通过重新运行执行命令传递相同的重新分配-json文件来执行此操作:

1

2

3

$ bin/kafka-reassign-partitions.sh --zookeeper localhost:2181  --execute --reassignment-json-file bigger-cluster.json --throttle 700000000

  There is an existing assignment running.

  The throttle limit was set to 700000000 B/s

重新平衡完成后,管理员可以使用--verify选项检查重新平衡的状态。如果重新平衡已完成,则将通过--verify命令删除限制。通过使用--verify选项运行命令,管理员必须在重新平衡完成后及时删除限制。如果不这样做,可能会导致定期复制流量受到限制。

执行--verify选项并重新分配完成后,脚本将确认已删除限制:

1

2

3

4

> bin/kafka-reassign-partitions.sh --zookeeper localhost:2181  --verify --reassignment-json-file bigger-cluster.json

Status of partition reassignment:

Reassignment of partition [my-topic,1] completed successfully

Reassignment of partition [mytopic,0] completed successfully

Throttle was removed.

管理员还可以使用kafka-configs.sh验证分配的配置。有两对油门配置用于管理节流过程。油门值本身。这是在代理级别使用动态属性配置的:

1

2

leader.replication.throttled.rate

  follower.replication.throttled.rate

还有一组枚举的限制副本:

1

2

leader.replication.throttled.replicas

  follower.replication.throttled.replicas

每个主题配置哪些。所有四个配置值都由kafka-reassign-partitions.sh自动分配(下面讨论)。

要查看油门限制配置:

1

2

3

> bin/kafka-configs.sh --describe --zookeeper localhost:2181 --entity-type brokers

Configs for brokers '2' are leader.replication.throttled.rate=700000000,follower.replication.throttled.rate=700000000

Configs for brokers '1' are leader.replication.throttled.rate=700000000,follower.replication.throttled.rate=700000000

这显示了应用于复制协议的前导端和跟随端的节流。默认情况下,为双方分配相同的限制吞吐量值。

要查看受限制的副本列表:

1

2

3

> bin/kafka-configs.sh --describe --zookeeper localhost:2181 --entity-type topics

Configs for topic 'my-topic' are leader.replication.throttled.replicas=1:102,0:101,

    follower.replication.throttled.replicas=1:101,0:102

这里我们看到领导者限制被应用于代理102上的分区1和代理101上的分区0。同样,跟随者限制被应用于代理101上的分区1和代理102上的分区0。

默认情况下,kafka-reassign-partitions.sh会将领导者限制应用于重新平衡之前存在的所有副本,其中任何一个可能是领导者。它将跟随者油门应用于所有移动目的地。因此,如果在代理101,102上存在具有副本的分区,被重新分配给102,103,则该分区的领导者节流将应用于101,102并且跟随者节流将仅应用于103。

如果需要,您还可以使用kafka-configs.sh上的--alter开关手动更改油门配置。

二,安全使用限制复制

使用限制复制时应该小心。特别是:

(1)节流阀拆卸:

一旦重新分配完成(通过运行kafka-reassign-partitions -verify),应及时删除油门。

(2)确保进展:

如果将节流阀设置得太低,则与传入的写入速率相比,复制可能无法进行。这发生在:

max(BytesInPerSec) > throttle

其中BytesInPerSec是监视生成器到每个代理的写吞吐量的度量标准。

管理员可以使用度量标准监控重新平衡期间复制是否正在进行中:

kafka.server:type=FetcherLagMetrics,name=ConsumerLag,clientId=([-.\w]+),topic=([-.\w]+),partition=([0-9]+)

复制期间滞后应不断减少。如果度量标准没有降低,则管理员应该如上所述增加节流量。

三,设定配额

配额覆盖和默认值可以在(用户,客户端ID),用户或客户端ID水平中所述被配置在这里。默认情况下,客户端会收到无限制的配额 可以为每个(用户,客户端ID),用户或客户端ID组设置自定义配额。

为(user = user1,client-id = clientA)配置自定义配额:

1

2

> bin/kafka-configs.sh  --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type users --entity-name user1 --entity-type clients --entity-name clientA

Updated config for entity: user-principal 'user1', client-id 'clientA'.

为user = user1配置自定义配额:

1

2

> bin/kafka-configs.sh  --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type users --entity-name user1

Updated config for entity: user-principal 'user1'.

为client-id = clientA配置自定义配额:

1

2

> bin/kafka-configs.sh  --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type clients --entity-name clientA

Updated config for entity: client-id 'clientA'.

可以通过指定--entity-default选项而不是--entity-name为每个(用户,客户端ID),用户或客户端ID组设置默认配额。

为user = userA配置默认客户端ID配额:

1

2

> bin/kafka-configs.sh  --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type users --entity-name user1 --entity-type clients --entity-default

Updated config for entity: user-principal 'user1', default client-id.

配置用户的默认配额:

1

2

> bin/kafka-configs.sh  --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type users --entity-default

Updated config for entity: default user-principal.

配置client-id的默认配额:

1

2

> bin/kafka-configs.sh  --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type clients --entity-default

Updated config for entity: default client-id.

以下是如何描述给定(用户,客户端ID)的配额:

1

2

> bin/kafka-configs.sh  --zookeeper localhost:2181 --describe --entity-type users --entity-name user1 --entity-type clients --entity-name clientA

Configs for user-principal 'user1', client-id 'clientA' are producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200

描述给定用户的配额:

1

2

> bin/kafka-configs.sh  --zookeeper localhost:2181 --describe --entity-type users --entity-name user1

Configs for user-principal 'user1' are producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200

Describe quota for a given client-id:

1

2

> bin/kafka-configs.sh  --zookeeper localhost:2181 --describe --entity-type clients --entity-name clientA

Configs for client-id 'clientA' are producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200

如果未指定实体名称,则描述指定类型的所有实体。例如,描述所有用户:

1

2

3

> bin/kafka-configs.sh  --zookeeper localhost:2181 --describe --entity-type users

Configs for user-principal 'user1' are producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200

Configs for default user-principal are producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200

类似地(用户,客户端):

1

2

3

> bin/kafka-configs.sh  --zookeeper localhost:2181 --describe --entity-type users --entity-type clients

Configs for user-principal 'user1', default client-id are producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200

Configs for user-principal 'user1', client-id 'clientA' are producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200

通过在代理上设置这些配置,可以设置适用于所有客户端ID的默认配额。仅当在Zookeeper中未配置配额覆盖或默认值时,才应用这些属性。默认情况下,每个client-id都会收到无限制的配额。以下设置将每个生产者和使用者客户端ID的默认配额设置为10MB /秒。

1

2

quota.producer.default=10485760

quota.consumer.default=10485760

请注意,这些属性已被弃用,可能会在将来的版本中删除。使用kafka-configs.sh配置的默认值优先于这些属性。

猜你喜欢

转载自blog.csdn.net/a53878617/article/details/84953382