Zookeeper学习8_关于ZookeeperConsumerConnector#rebalance
来源:互联网 发布:betterzip mac免费版 编辑:程序博客网 时间:2024/05/23 19:10
consumer的负载均衡,每一个partition只会同时被consumer group里面的一台机器消费,称为owner,owner分配的逻辑,
1. For each topic T that Ci subscribes to
2. let PT be all partitions producing topic T
3. let CG be all consumers in the same group as Ci that consume topic T
4. sort PT (so partitions on the same broker are clustered together)
5. sort CG
6. let i be the index position of Ci in CG and let N = size(PT)/size(CG)
7. assign partitions from i*N to (i+1)*N - 1 to consumer Ci // i*N to i*N+N-1
8. remove current entries owned by Ci from the partition owner registry
9. add newly assigned partitions to the partition owner registry
(we may need to re-try this until the original partition owner releases its ownership)
具体实现在ZookeeperConsumerConnector#rebalance,
最后当然也是存储在ZK上了,
1. For each topic T that Ci subscribes to
2. let PT be all partitions producing topic T
3. let CG be all consumers in the same group as Ci that consume topic T
4. sort PT (so partitions on the same broker are clustered together)
5. sort CG
6. let i be the index position of Ci in CG and let N = size(PT)/size(CG)
7. assign partitions from i*N to (i+1)*N - 1 to consumer Ci // i*N to i*N+N-1
8. remove current entries owned by Ci from the partition owner registry
9. add newly assigned partitions to the partition owner registry
(we may need to re-try this until the original partition owner releases its ownership)
具体实现在ZookeeperConsumerConnector#rebalance,
for (consumerThreadId <- consumerThreadIdSet) { val myConsumerPosition = curConsumers.indexOf(consumerThreadId) assert(myConsumerPosition >= 0) val startPart = nPartsPerConsumer*myConsumerPosition + myConsumerPosition.min(nConsumersWithExtraPart) val nParts = nPartsPerConsumer + (if (myConsumerPosition + 1 > nConsumersWithExtraPart) 0 else 1) /** * Range-partition the sorted partitions to consumers for better locality. * The first few consumers pick up an extra partition, if any. */ if (nParts <= 0) warn("No broker partitions consumed by consumer thread " + consumerThreadId + " for topic " + topic) else { for (i <- startPart until startPart + nParts) { val partition = curPartitions(i) info(consumerThreadId + " attempting to claim partition " + partition) // 每个partition只会由一条thread消费,不会有并发的问题 addPartitionTopicInfo(currentTopicRegistry, topicDirs, partition, topic, consumerThreadId) // record the partition ownership decision partitionOwnershipDecision += ((topic, partition) -> consumerThreadId) } } }
最后当然也是存储在ZK上了,
/consumers/[group_id]/owners/[topic]/[broker_id-partition_id] --> consumer_node_id (ephemeral node)
资料节选自:http://www.sjsjw.com/104/000355MYM018196/
在使用过程中,遇到了一个错误,如标红的地方所示,故查找一下原因。
0 0
- Zookeeper学习8_关于ZookeeperConsumerConnector#rebalance
- 关于zookeeper的一些学习
- 学习ASM技术--条带化原理和rebalance
- kafka ZookeeperConsumerConnector 异常排查
- ZooKeeper学习之关于Servers和Watches
- ZooKeeper学习之关于Servers和Sessions
- 学习笔记_关于字符串
- Zookeeper学习1_分布式服务框架 Zookeeper -- 管理分布式环境中的数据
- 关于Zookeeper
- dubbo+zookeeper使用^_^
- 浅谈zk(8).zookeeper环境搭建_集群版
- zookeeper学习
- ZooKeeper学习
- zookeeper学习
- zookeeper学习
- zookeeper 学习
- zookeeper学习
- Zookeeper学习
- XMPPFramework初始化、登录、注册详解(附代码)
- Android Storage 路径测试
- Android Studio 如何设置编码方式——诺诺"涂鸦"记忆
- MindMapper 与MindManager之间的区别
- Android使用AsyncHttpClient给APP更新版本并安装
- Zookeeper学习8_关于ZookeeperConsumerConnector#rebalance
- c++ 基本数据类型总结
- html/css书写注意事项
- simrank
- 代码原理 webkit WebKit-利用百度siteapp开发网站App-(IOS和Android版本)
- 修改innodb_buffer_pool_size参数
- session过期,解决登录页面在子页面中打开
- hao
- iOS的socket开发基础