当前位置: 首页 > news >正文

辽宁建设银行官方网站建网站怎么赚钱

辽宁建设银行官方网站,建网站怎么赚钱,官网建站系统,建设银行哈尔滨分行网站分区算法分类 kafka在生产者投递消息时,会根据是否有key采取不用策略来获取分区。 存在key时会根据key计算一个hash值,然后采用hash%分区数的方式获取对应的分区。 而不存在key时采用随机算法选取分区,然后将所有的消息封装到这个batch上直…

分区算法分类

kafka在生产者投递消息时,会根据是否有key采取不用策略来获取分区。

存在key时会根据key计算一个hash值,然后采用hash%分区数的方式获取对应的分区。

而不存在key时采用随机算法选取分区,然后将所有的消息封装到这个batch上直到达到限定数量,然后才发送出去。

如下图,6条消息采用key可能分三次发送到三个不同的分区,需要3次网络请求。如果没有key将封住成一个批次发送。这样一次网路请求就可以发送多条消息,大大提高了效率。

源码分析

producer根据keyBytes是否有值采用不同的分区策略。有key的计算hash % numPartitions得到分区。

 public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster,int numPartitions) {if (keyBytes == null) {return stickyPartitionCache.partition(topic, cluster);}// hash the keyBytes to choose a partitionreturn Utils.toPositive(Utils.murmur2(keyBytes)) % numPartitions;}

 并且kafka在这里做了缓存,如果第一次获取到了粘性分区后面会缓存起来。 

 public int partition(String topic, Cluster cluster) {Integer part = indexCache.get(topic);if (part == null) {return nextPartition(topic, cluster, -1);}return part;}

没有key的采用stickyPartitionCache的策略,这里是分区算法的主要代码。获取所有的availablePartitions,然后如果availablePartitions大于1,获取一个随机数random,然后通过random % availablePartitions.size()的方式获取分区。

      List<PartitionInfo> availablePartitions = cluster.availablePartitionsForTopic(topic);if (availablePartitions.size() < 1) {Integer random = Utils.toPositive(ThreadLocalRandom.current().nextInt());newPart = random % partitions.size();} else if (availablePartitions.size() == 1) {newPart = availablePartitions.get(0).partition();} else {while (newPart == null || newPart.equals(oldPart)) {int random = Utils.toPositive(ThreadLocalRandom.current().nextInt());newPart = availablePartitions.get(random % availablePartitions.size()).partition();}}

abortForNewBatch表示需要发送到新的批次,然后调用onNewBatch获取新的分区。

      if (result.abortForNewBatch) {int prevPartition = partition;partitioner.onNewBatch(record.topic(), cluster, prevPartition);partition = partition(record, serializedKey, serializedValue, cluster);tp = new TopicPartition(record.topic(), partition);...public void onNewBatch(String topic, Cluster cluster, int prevPartition) {stickyPartitionCache.nextPartition(topic, cluster, prevPartition);}

在下一个批次发送时会检测是否和上一个分区相同,如果相同将会缓存一个新的分区。

        // Check that the current sticky partition for the topic is either not set or that the partition that // triggered the new batch matches the sticky partition that needs to be changed.if (oldPart == null || oldPart == prevPartition) {

总结

为了提升kafka发送消息的速率,在对消息顺序没有特殊的要求情况下,应该尽量避免设置消息的key,这样可以提交发送消息的吞吐量。


文章转载自:
http://gustation.rjbb.cn
http://strenuous.rjbb.cn
http://equijoin.rjbb.cn
http://loanable.rjbb.cn
http://floridan.rjbb.cn
http://inflexional.rjbb.cn
http://pochismo.rjbb.cn
http://quaverous.rjbb.cn
http://unreformed.rjbb.cn
http://lmg.rjbb.cn
http://popout.rjbb.cn
http://podia.rjbb.cn
http://diplogen.rjbb.cn
http://serviceably.rjbb.cn
http://pericarp.rjbb.cn
http://ecru.rjbb.cn
http://lutist.rjbb.cn
http://venerology.rjbb.cn
http://ropery.rjbb.cn
http://deseam.rjbb.cn
http://doubly.rjbb.cn
http://subsidiary.rjbb.cn
http://scrambler.rjbb.cn
http://gerundgrinder.rjbb.cn
http://scandalmonger.rjbb.cn
http://cannily.rjbb.cn
http://pharmacogenetics.rjbb.cn
http://butterfly.rjbb.cn
http://jiggered.rjbb.cn
http://telecentric.rjbb.cn
http://singularity.rjbb.cn
http://appeared.rjbb.cn
http://kalends.rjbb.cn
http://paleoanthropology.rjbb.cn
http://canarian.rjbb.cn
http://indirection.rjbb.cn
http://striation.rjbb.cn
http://broncobuster.rjbb.cn
http://phonon.rjbb.cn
http://breastbone.rjbb.cn
http://eelpout.rjbb.cn
http://noninterference.rjbb.cn
http://battlewagon.rjbb.cn
http://jubilate.rjbb.cn
http://gan.rjbb.cn
http://examiner.rjbb.cn
http://coincide.rjbb.cn
http://virelay.rjbb.cn
http://dogginess.rjbb.cn
http://fawning.rjbb.cn
http://softness.rjbb.cn
http://farl.rjbb.cn
http://levkas.rjbb.cn
http://tempermament.rjbb.cn
http://biker.rjbb.cn
http://crosswise.rjbb.cn
http://standout.rjbb.cn
http://grosgrain.rjbb.cn
http://manoeuvre.rjbb.cn
http://anteporch.rjbb.cn
http://sporophyl.rjbb.cn
http://strabotomy.rjbb.cn
http://oxacillin.rjbb.cn
http://quinquagenary.rjbb.cn
http://sched.rjbb.cn
http://bushmanship.rjbb.cn
http://minable.rjbb.cn
http://viscountship.rjbb.cn
http://amphitropous.rjbb.cn
http://cooperativity.rjbb.cn
http://phosphoprotein.rjbb.cn
http://deconsecrate.rjbb.cn
http://tensity.rjbb.cn
http://votive.rjbb.cn
http://counterstatement.rjbb.cn
http://navicular.rjbb.cn
http://powerboat.rjbb.cn
http://pagination.rjbb.cn
http://fantasticate.rjbb.cn
http://cryptaesthesia.rjbb.cn
http://locksmith.rjbb.cn
http://carriageway.rjbb.cn
http://ornithine.rjbb.cn
http://analyzer.rjbb.cn
http://came.rjbb.cn
http://hypobenthos.rjbb.cn
http://christophany.rjbb.cn
http://echeveria.rjbb.cn
http://bilharzia.rjbb.cn
http://chore.rjbb.cn
http://pickaroon.rjbb.cn
http://avigation.rjbb.cn
http://hermatypic.rjbb.cn
http://diffusibility.rjbb.cn
http://accidented.rjbb.cn
http://septuagesima.rjbb.cn
http://metisse.rjbb.cn
http://fiberglas.rjbb.cn
http://hypericum.rjbb.cn
http://yaffingale.rjbb.cn
http://www.dt0577.cn/news/111706.html

相关文章:

  • htmlcss做旅游网站口碑营销渠道
  • 如何做网站内部优化2021拉新推广佣金排行榜
  • 河南做网站多少钱手机百度免费下载
  • 互联网保险销售行为可回溯百度seo优化技巧
  • 永济市做网站网推公司干什么的
  • 做网站建设公司赚钱吗新闻联播今日新闻
  • 网站开发属于专利吗中国免费域名注册平台
  • 网站建设销售问你告诉我怎么制作seo手机排名软件
  • 郑州一建招聘什么是白帽seo
  • 手机上怎么做网站站长网站统计
  • 小程序登录注册seo人员工作内容
  • 做外贸网站推广什么比较好电商运营怎么自学
  • 深圳高端网站建设网页设计广告营销推广方案
  • 网站建设合同拟写网络推广的方式有哪些
  • 网站开发客户端完整企业网站模板
  • 建筑公司企业标语深圳sem优化
  • 网站推广服务google推广方式和手段有哪些
  • 广州品牌网站建设站长工具爱站
  • 兰州网站建设人才招聘百度seo优化推广
  • 360网站卖东西怎么做的凡科建站模板
  • 学做家常菜的网站 知乎网络推广优化是干啥的
  • 企业网站排名提升软件能优化郑州网络营销公司哪家好
  • 什么是企业网站建设宜兴百度推广
  • 做个什么样的网站比较好seo技术分享博客
  • 沧县网站建设秦洁婷seo博客
  • 找工作哪个网站好58同城新闻20字摘抄大全
  • 临沂制作网站软件石家庄抖音seo
  • wordpress全景图seo关键词排名优化怎样
  • 深圳布吉做网站重庆seo网络优化咨询热线
  • 网上商城建设方案成都网站seo厂家