设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Kafka之消费与激情(7)

发布时间:2021-05-29 18:39 所属栏目:118 来源:互联网
导读://afterthelongpoll,weshouldcheckwhetherthegroupneedstorebalance //priortoreturningdatasothatthegroupcanstabilizefaster if(coordinator.rejoinNeededOrPending()){ returnCollections.emptyMap(); } returnf

        // after the long poll, we should check whether the group needs to rebalance  

        // prior to returning data so that the group can stabilize faster  

        if (coordinator.rejoinNeededOrPending()) {  

            return Collections.emptyMap();  

        }  

        return fetcher.fetchedRecords();  

    }  

上述代码中加粗的位置,我们可以看出每次消费者客户端拉取数据时,通过poll方法,先调用fetcher中的fetchedRecords函数,如果获取不到数据,就会发起一个新的sendFetches请求。而在消费数据的时候,每个批次从Kafka Broker Server中拉取数据是有最大数据量限制,默认是500条,由属性(max.poll.records)控制,可以在客户端中设置该属性值来调整我们消费时每次拉取数据的量。

提示:这里需要注意的是,max.poll.records返回的是一个poll请求的数据总和,与多少个分区无关。因此,每次消费从所有分区中拉取Topic的数据的总条数不会超过max.poll.records所设置的值。

而在Fetcher的类中,在sendFetches方法中有限制拉取数据容量的限制,由属性(max.partition.fetch.bytes),默认1MB。可能会有这样一个场景,当满足max.partition.fetch.bytes限制条件,如果需要Fetch出10000条记录,每次默认500条,那么我们需要执行20次才能将这一次通过网络发起的请求全部Fetch完毕。

这里,可能有同学有疑问,我们不能将默认的max.poll.records属性值调到10000吗?可以调,但是还有个属性需要一起配合才可以,这个就是每次poll的超时时间(Duration.ofMillis(100)),这里需要根据你的实际每条数据的容量大小来确定设置超时时间,如果你将最大值调到10000,当你每条记录的容量很大时,超时时间还是100ms,那么可能拉取的数据少于10000条。

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读