一种消息拉取方法、装置以及计算机存储介质Message pulling method, device and computer storage medium
技术领域Technical field
本申请实施例涉及数据应用技术领域,尤其涉及一种消息拉取方法、装置以及计算机存储介质。The embodiments of the present application relate to the field of data application technology, and in particular, to a method, device, and computer storage medium for pulling messages.
背景技术Background technique
Kafka作为一种高吞吐量的分布式发布订阅消息系统,每条发布到kafka集群的消息都有一个主题,该主题被称为Topic。具体地,针对同一Topic可以创建具有不同优先级的多个子主题,每个子主题配置一个消费组,不同的消费组按照默认或用户自定义配置的不同优先级等级对应的消息个数比例,可以计算出不同优先级的最大拉取量。Kafka is a high-throughput distributed publish-subscribe messaging system. Each message published to the Kafka cluster has a topic, which is called Topic. Specifically, multiple subtopics with different priorities can be created for the same topic, each subtopic is configured with a consumer group, and the proportion of the number of messages corresponding to different priority levels of different consumer groups can be calculated according to the default or user-defined configuration. The maximum pull amount of different priorities.
然而,考虑到多个子主题中可能存在某个或某几个子主题无消息堆积时,这时候消费者拉取的消息量不满足初始化时分配的最大拉取量。如果部分子主题存在消息堆积,但是仍以固定比例来拉取消息,将会使得消费者拉取拉取的消息量小于最大拉取量,从而对用户造成存在异常的假象;另外,当较低优先级出现消息堆积而较高优先级无消息时,若较低优先级仍然以低配额的比例拉取消息,则会导致消费者频繁拉取小批量的消息,从而使得磁盘IO负载上升,且降低了操作系统预读带来的性能优势,导致Kafka集群出现性能瓶颈。However, considering that there may be no message accumulation in one or several subtopics among multiple subtopics, the amount of messages pulled by consumers at this time does not meet the maximum pull amount allocated during initialization. If there are news accumulations in some subtopics, but the news is still pulled at a fixed ratio, the amount of news pulled by consumers will be less than the maximum amount, which will give users the illusion of abnormality; in addition, when it is lower When messages are piled up in priority and there is no message with higher priority, if the lower priority still pulls messages at a low quota ratio, it will cause consumers to frequently pull small batches of messages, which will increase the disk IO load, and The performance advantage brought by the pre-reading of the operating system is reduced, resulting in a performance bottleneck in the Kafka cluster.
发明内容Summary of the invention
本申请提供一种消息拉取方法、装置以及计算机存储介质,通过自适应动态配额方式,可以实时分配和更新各子主题的流控速率,且能够避免消费组频繁小批次拉取消息所导致的计算速率下降和Kafka集群性能瓶颈的问题。This application provides a method, device, and computer storage medium for pulling messages. Through an adaptive dynamic quota method, the flow control rate of each subtopic can be allocated and updated in real time, and it can avoid the frequent small batches of messages being pulled by consumer groups. The computing rate drops and the performance bottleneck of Kafka cluster.
本申请实施例的技术方案可以如下实现:The technical solutions of the embodiments of the present application can be implemented as follows:
第一方面,本申请实施例提供了一种消息拉取方法,该方法包括:In the first aspect, an embodiment of the present application provides a message pulling method, which includes:
确定待消费主题所包括的多个子主题以及各自分配的第一拉取比例;其中,不同的子主题具有不同的优先级参数;Determine the multiple sub-themes included in the theme to be consumed and the first pull ratio assigned to each; among them, different sub-themes have different priority parameters;
根据所述第一拉取比例,确定所述待消费主题所拉取消息的实际拉取量;According to the first pull ratio, determine the actual pull amount of messages pulled by the topic to be consumed;
若所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则对所述第一拉取比例进行调整,得到所述多个子主题各自分配的第二拉取比例;If the actual pull amount of the message pulled by the topic to be consumed is less than the preset rated pull amount, the first pull ratio is adjusted to obtain the second pull ratio assigned to each of the multiple subtopics ;
根据所述第二拉取比例,对所述待消费主题进行消息拉取。According to the second pulling ratio, message pulling is performed on the topic to be consumed.
第二方面,本申请实施例提供了一种消息拉取装置,该消息拉取装置包括确定单元、调整单元和拉取单元,其中,In a second aspect, an embodiment of the present application provides a message pulling device, the message pulling device includes a determining unit, an adjusting unit, and a pulling unit, wherein:
所述确定单元,配置为确定待消费主题所包括的多个子主题以及各自分配的第一拉取比例;其中,不同的子主题具有不同的优先级参数;The determining unit is configured to determine a plurality of sub-themes included in the theme to be consumed and a first pull ratio allocated to each; wherein, different sub-themes have different priority parameters;
所述确定单元,还配置为根据所述第一拉取比例,确定所述待消费主题所拉取消息的实际拉取量;The determining unit is further configured to determine the actual pull amount of messages pulled by the topic to be consumed according to the first pull ratio;
所述调整单元,配置为若所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则对所述第一拉取比例进行调整,得到所述多个子主题各自分配的第二拉取比例;The adjustment unit is configured to, if the actual pull amount of the message pulled by the topic to be consumed is less than the preset rated pull amount, adjust the first pull ratio to obtain each of the multiple subtopics The allocated second pull ratio;
所述拉取单元,配置为根据所述第二拉取比例,对所述待消费主题进行消息拉取。The pulling unit is configured to pull messages of the topic to be consumed according to the second pulling ratio.
第三方面,本申请实施例提供了一种消息拉取装置,该消息拉取装置包括存储器和处理器,其中,In a third aspect, an embodiment of the present application provides a message pulling device, the message pulling device includes a memory and a processor, wherein:
所述存储器,用于存储能够在所述处理器上运行的计算机程序;The memory is used to store a computer program that can run on the processor;
所述处理器,用于在运行所述计算机程序时,执行如第一方面所述的方法。The processor is configured to execute the method described in the first aspect when the computer program is running.
第四方面,本申请实施例提供了一种计算机存储介质,该计算机存储介质存储有计算机程序,所述计算机程序被至少一个处理器执行时实现如第一方面所述的方法。In a fourth aspect, an embodiment of the present application provides a computer storage medium that stores a computer program that implements the method described in the first aspect when the computer program is executed by at least one processor.
本申请实施例提供了一种消息拉取方法、装置以及计算机存储介质,通过确定待消费主题所包括的多个子主题以及各自分配的第一拉取比例;其中,不同的子主题具有不同的优先级参数;根据所述第一拉取比例,确定所述待消费主题所拉取消息的实际拉取量;若所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则对所述第一拉取比例进行调整,得到所述多个子主题各自分配的第二拉取比例;根据所述第二拉取比例,对所述待消费主题进行消息拉取。这样,通过自适应动态配额方式进行动态流控,当部分子主题没有消息堆积时,能够避免因消费组频繁小批次拉取消息所导致的计算速率下降和Kafka集群性能瓶颈的问题,实现了计算性能的优化;另外,在某一子主题突发大流量消息写入的情况下,还能够实时分配和更新其流控速率,从而实现了最优的消费性能。The embodiments of the present application provide a message pull method, device, and computer storage medium, which determine the multiple subtopics included in the topic to be consumed and the first pull ratio assigned to each; wherein, different subtopics have different priorities. Level parameter; according to the first pull ratio, determine the actual pull amount of messages pulled by the topic to be consumed; if the actual pull amount of messages pulled by the topic to be consumed is less than the preset rated pull Then, the first pull ratio is adjusted to obtain the second pull ratio assigned to each of the multiple subtopics; according to the second pull ratio, message pull is performed on the topic to be consumed. In this way, dynamic flow control is carried out through the adaptive dynamic quota method. When there is no message accumulation in some subtopics, it can avoid the problem of the decrease in the calculation rate and the performance bottleneck of the Kafka cluster caused by the frequent small batches of messages pulled by the consumer group. Optimization of computing performance; In addition, in the case of a subtopic burst of large-flow message writing, it can also allocate and update its flow control rate in real time, thereby achieving optimal consumption performance.
附图说明Description of the drawings
图1为相关技术方案提供的一种消息拉取系统的流程框图示意图;FIG. 1 is a schematic flowchart of a message pulling system provided by related technical solutions;
图2为相关技术方案提供的一种拉取消息应用的场景示意图;Fig. 2 is a schematic diagram of a scenario for pulling messages provided by related technical solutions;
图3为本申请实施例提供的一种消息拉取方法的流程示意图;FIG. 3 is a schematic flowchart of a method for pulling messages according to an embodiment of the application;
图4为本申请实施例提供的一种预设削减模式应用的场景示意图;FIG. 4 is a schematic diagram of a scenario in which a preset reduction mode is applied according to an embodiment of the application;
图5为本申请实施例提供的一种预设征集模式应用的场景示意图;FIG. 5 is a schematic diagram of an application scenario of a preset solicitation mode provided by an embodiment of the application;
图6为本申请实施例提供的一种消息拉取装置的组成结构示意图;FIG. 6 is a schematic diagram of the composition structure of a message pulling device provided by an embodiment of the application;
图7为本申请实施例提供的另一种消息拉取装置的组成结构示意图;FIG. 7 is a schematic diagram of the composition structure of another message pulling device provided by an embodiment of the application;
图8为本申请实施例提供的一种消息拉取装置的硬件结构示意图。FIG. 8 is a schematic diagram of the hardware structure of a message pulling device provided by an embodiment of the application.
具体实施方式Detailed ways
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清 楚、完整地描述。可以理解的是,此处所描述的具体实施例仅仅用于解释相关申请,而非对该申请的限定。另外还需要说明的是,为了便于描述,附图中仅示出了与有关申请相关的部分。The technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings in the embodiments of the present application. It is understandable that the specific embodiments described here are only used to explain the related application, but not to limit the application. In addition, it should be noted that, for ease of description, only the parts related to the relevant application are shown in the drawings.
消息中间件是一种广泛运用在分布式系统中的用于节点间通信的软件。在大规模高并发后台服务架构体系中,Kafka作为常用的消息中间件,应用非常广泛。Message middleware is a kind of software widely used in distributed systems for communication between nodes. In the large-scale high-concurrency back-end service architecture system, Kafka, as a commonly used message middleware, is widely used.
Kafka是由Linkedin公司开发并开源的消息中间件,是一种高吞吐量的分布式发布订阅消息系统,它可以处理消费者在网站中的所有动作流数据。其中,kafka开发的主要目标是构建一个用来处理海量日志、用户行为和网站运营统计等的数据处理框架,在结合了数据挖掘、行为分析、运营监控等需求的情况下,需要能够满足各种实时在线和批量离线处理应用场合对低延迟和批量吞吐性能的要求,并且可以通过集群来提供实时的消息。Kafka is a message middleware developed and open sourced by Linkedin. It is a high-throughput distributed publish-subscribe messaging system that can process all the action flow data of consumers on the website. Among them, the main goal of kafka development is to build a data processing framework for processing massive logs, user behavior and website operation statistics. In the case of combining data mining, behavior analysis, operation monitoring and other requirements, it needs to be able to meet various Real-time online and batch offline processing applications require low latency and batch throughput performance, and real-time messages can be provided through clusters.
Kafka集群包含一个或多个服务器,这种服务器被称为broker,每条发布到kafka集群的消息都有一个主题,该主题被称为topic,每个topic包含一个或多个子主题。参见图1,其示出了相关技术方案提供的一种消息拉取系统的流程框图实例;如图1所示,该消息拉取系统10包括有消息生产者101、Kafka集群102、客户端103和消费者104;其中,客户端103通常为第三方开发者提供的软件开发工具包(Software Development Kit,SDK),也就是说SDK为开发人员快速接入中间件所提供的适配客户端。这样,在消息生产者101产生消息(message)之后,可以同时配置有该消息的优先级参数;例如:message1{priority:2;data:A3615C}、message2{priority:5;data:B36D4}等;即在客户端103中封装有优先级消息逻辑,然后通过在Kafka集群102中对同一主题创建以不同优先级结尾的子主题(topic-1、topic-2、topic-3、topic-4和topic-5等)来模拟具有不同优先级参数的消息写入;在消息写入对应优先级的子主题后,再通过客户端103从Kafka集群102内不同的子主题拉取消息,比如拉取的消息为message1(priority:2;data:A3615C)和message2(priority:5;data:B36D4),最后将所拉取的消息发送给消费者104,由消费者104对所拉取的消息进行相关处理。A Kafka cluster contains one or more servers. This server is called a broker. Each message published to the Kafka cluster has a topic. The topic is called a topic. Each topic contains one or more subtopics. Refer to FIG. 1, which shows an example of a flow diagram of a message pulling system provided by related technical solutions; as shown in FIG. 1, the message pulling system 10 includes a message producer 101, a Kafka cluster 102, and a client 103 And the consumer 104; where the client 103 is usually a software development kit (SDK) provided by a third-party developer, that is, the SDK provides developers with quick access to the adapted client provided by the middleware. In this way, after the message producer 101 generates a message, the priority parameter of the message can be configured at the same time; for example: message1{priority:2; data:A3615C}, message2{priority:5; data:B36D4}, etc.; That is, the priority message logic is encapsulated in the client 103, and then subtopics (topic-1, topic-2, topic-3, topic-4 and topic -5, etc.) to simulate the writing of messages with different priority parameters; after the message is written to the subtopic of the corresponding priority, the client 103 is then used to pull messages from different subtopics in the Kafka cluster 102, such as the pull The messages are message1 (priority: 2; data: A3615C) and message 2 (priority: 5; data: B36D4). Finally, the pulled message is sent to the consumer 104, and the consumer 104 performs related processing on the pulled message .
具体地,每一个优先级参数对应的子主题配置一个消费组,不同的消费组按照默认或用户自定义配置的不同优先级参数对应的拉取比例,乘以所有优先级所拉取消息的额定拉取量,就可以计算出不同优先级所分配的基准配额,再通过所配套的客户端SDK汇总不同子主题所拉取的消息,返回给用户一个拉取的批次消息,该批次消息中包含了不同优先级参数对应的拉取消息量,以此实现Kafka对不同优先级所拉取消息的支持。Specifically, each subtopic corresponding to a priority parameter is configured with a consumer group, and different consumer groups are pulled according to the default or user-defined configuration of different priority parameters corresponding to the pull ratio, multiplied by the rating of the messages pulled by all priorities By the amount of pull, you can calculate the benchmark quotas allocated by different priorities, and then summarize the messages pulled by different subtopics through the supporting client SDK, and return to the user a batch of pulled messages, the batch of messages It contains the amount of pulled messages corresponding to different priority parameters, so as to realize Kafka's support for messages pulled by different priorities.
考虑对于多个优先级参数对应的子主题,特定时刻下可能存在某一个和某几个子主题无消息堆积,这时候消费者所拉取消息的实际拉取量不满足初始化时分配的额定拉取量。如图2所示,其示出了相关技术方案提供的一种拉取消息应用的场景示意图。在图2中,同一主题所包括的topic-1、topic-2、topic-3、topic-4和topic-5等五个子主题中,优先级参数包括有5个等级,优先级参数 等于5,表示优先级最高;优先级参数等于1,表示优先级最低;而且topic-1和topic-5中有消息堆积,但是topic-2、topic-3和topic-4无消息堆积;假定默认的额定拉取量为500,不同优先级参数对应的拉取比例(优先级从高到低)分别为:40%、30%、15%、10%、5%;具体地,topic-5的拉取配额为200,即优先级参数等于5的子主题每次可以拉取到200条消息;而topic-4的拉取配额为150,topic-3的拉取配额为75,topic-2的拉取配额为50,topic-1的拉取配额为25;也就是说,仅从topic-5和topic-1中可以拉取消息,而且实际拉取总量为225条消息。这样,基于图2所示的场景示例,在有子主题存在消息堆积的情况下,用户预期可以一次拉取到500条消息,但是由于不同优先级对应的拉取比例限制,使得用户实际上只拉取到了225条消息。如此,将会存在如下的问题:一方面,当部分子主题存在消息堆积,但是SDK所拉取消息的实际拉取总量小于用户设定的额定拉取量时,这时候会对用户造成存在异常的假象;另一方面,如果较低优先级出现消息堆积而较高优先级无消息(处于空闲态),那么较低优先级仍然以低配额的比例拉取消息,可能导致消费者频繁拉取小批量的消息;而频繁地小批量拉取消息会导致大量随机读,从而导致磁盘IO负载上升,同时降低操作系统预读带来的性能优势,进而使得Kafka集群出现性能瓶颈。Considering that for the subtopics corresponding to multiple priority parameters, there may be no message accumulation for one or several subtopics at a specific moment. At this time, the actual pull amount of messages pulled by consumers does not meet the rated pull allocated during initialization quantity. As shown in FIG. 2, it shows a schematic diagram of a scenario of a message pulling application provided by related technical solutions. In Figure 2, in the five subtopics of topic-1, topic-2, topic-3, topic-4 and topic-5 included in the same topic, the priority parameter includes 5 levels, and the priority parameter is equal to 5. It means the highest priority; the priority parameter is equal to 1, which means the lowest priority; and there is message accumulation in topic-1 and topic-5, but topic-2, topic-3 and topic-4 have no message accumulation; assuming the default rated pull The amount is 500, and the corresponding pull ratios for different priority parameters (from high to low) are: 40%, 30%, 15%, 10%, 5%; specifically, topic-5 pull quota It is 200, that is, the subtopic with priority parameter equal to 5 can pull 200 messages each time; and topic-4 has a pull quota of 150, topic-3 has a pull quota of 75, and topic-2 has a pull quota. It is 50, and the pull quota for topic-1 is 25; that is, only messages can be pulled from topic-5 and topic-1, and the actual pull total is 225 messages. In this way, based on the scenario example shown in Figure 2, when there are subtopics with message accumulation, the user is expected to be able to pull 500 messages at a time, but due to the pull ratio restrictions corresponding to different priorities, the user actually only 225 messages were pulled. In this way, there will be the following problems: On the one hand, when there is a message accumulation in some subtopics, but the actual pull amount of the messages pulled by the SDK is less than the rated pull amount set by the user, this will cause the user to exist. Abnormal illusion; on the other hand, if there is a accumulation of messages with a lower priority and no messages with a higher priority (in idle state), then the lower priority still pulls messages at a low quota ratio, which may cause consumers to pull frequently Fetch small batches of messages; and frequent small batches of messages will cause a large number of random reads, which will lead to an increase in disk IO load, and reduce the performance advantage brought by the operating system read-ahead, which will cause a performance bottleneck in the Kafka cluster.
基于此,本申请实施例提供了一种消息拉取方法,通过确定待消费主题所包括的多个子主题以及各自分配的第一拉取比例;其中,不同的子主题具有不同的优先级参数;根据所述第一拉取比例,确定所述待消费主题所拉取消息的实际拉取量;若所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则对所述第一拉取比例进行调整,得到所述多个子主题各自分配的第二拉取比例;根据所述第二拉取比例,对所述待消费主题进行消息拉取。这样,通过自适应动态配额方式进行动态流控,当部分子主题没有消息堆积时,能够避免因消费组频繁小批次拉取消息所导致的计算速率下降和Kafka集群性能瓶颈的问题,实现了计算性能的优化;另外,在某一子主题突发大流量消息写入的情况下,还能够实时分配和更新其流控速率,从而实现了最优的消费性能。Based on this, an embodiment of the present application provides a message pull method by determining multiple subtopics included in the topic to be consumed and a first pull ratio allocated to each; wherein, different subtopics have different priority parameters; According to the first pull ratio, determine the actual pull amount of messages pulled by the topic to be consumed; if the actual pull amount of messages pulled by the topic to be consumed is less than the preset rated pull amount, then The first pull ratio is adjusted to obtain the second pull ratio assigned to each of the multiple subtopics; and the message pull is performed on the topic to be consumed according to the second pull ratio. In this way, dynamic flow control is carried out through the adaptive dynamic quota method. When there is no message accumulation in some subtopics, it can avoid the problem of the decrease in the calculation rate and the performance bottleneck of the Kafka cluster caused by the frequent small batches of messages pulled by the consumer group. Optimization of computing performance; In addition, in the case of a subtopic burst of large-flow message writing, it can also allocate and update its flow control rate in real time, thereby achieving optimal consumption performance.
下面将结合附图对本申请各实施例进行详细描述。Hereinafter, each embodiment of the present application will be described in detail with reference to the accompanying drawings.
本申请的一实施例中,参见图3,其示出了本申请实施例提供的一种消息拉取方法的流程示意图。如图3所示,该方法可以包括:In an embodiment of the present application, refer to FIG. 3, which shows a schematic flowchart of a message pulling method provided in an embodiment of the present application. As shown in Figure 3, the method may include:
S301:确定待消费主题所包括的多个子主题以及各自分配的第一拉取比例;其中,不同的子主题具有不同的优先级参数;S301: Determine a plurality of sub-themes included in the theme to be consumed and their respective first pull ratios; wherein, different sub-themes have different priority parameters;
需要说明的是,该方法应用于消息拉取系统。在消息拉取系统中,SDK向kafka集群内的待消费主题拉取消息。其中,同一个待消费主题可以创建多个子主题,且这多个子主题具有不同的优先级参数。It should be noted that this method is applied to a message pull system. In the message pull system, the SDK pulls messages from topics to be consumed in the kafka cluster. Among them, the same topic to be consumed can create multiple subtopics, and these multiple subtopics have different priority parameters.
还需要说明的是,第一拉取比例为预先根据不同优先级参数所设定的默认拉取比例;这里,第一拉取比例表示各个子主题所预设的消息拉取数量相对整个待消费主题所预设的额定拉取量的占比。例如,假定多个子主题可以包括topic-5、topic-4、topic-3、topic-2和topic-1等五个子主题;而且优先级参数为 5、4、3、2、1,5对应的优先级最高,1对应的优先级最低,这时候可以设定第一拉取比例分别为40%、30%、15%、10%、5%。It should also be noted that the first pull ratio is the default pull ratio set in advance according to different priority parameters; here, the first pull ratio indicates that the preset number of messages to be pulled for each subtopic is relative to the total amount to be consumed. The proportion of the rated pull volume preset by the theme. For example, suppose that multiple subtopics can include five subtopics: topic-5, topic-4, topic-3, topic-2, and topic-1; and the priority parameters are 5, 4, 3, 2, 1, and 5. The priority is the highest, and 1 corresponds to the lowest priority. At this time, the first pull ratio can be set to 40%, 30%, 15%, 10%, and 5%.
另外,在这多个子主题中,可能部分的子主题内存储有待消费消息,而部分的子主题内没有存储待消费消息。对于每一个子主题内所存储的待消费消息,则是由消息生产者所生产的,然后按照优先级参数放入对应的子主题中。具体地,在一些实施例中,在S301之前,该方法还可以包括:In addition, among these multiple subtopics, it is possible that some subtopics store messages to be consumed, while some subtopics do not store messages to be consumed. For the messages to be consumed stored in each subtopic, they are produced by the message producer, and then put into the corresponding subtopic according to the priority parameter. Specifically, in some embodiments, before S301, the method may further include:
接收消息生产者所发送的待消费消息,所述待消费消息中包括消息内容和优先级参数;Receiving a message to be consumed sent by a message producer, where the message to be consumed includes message content and priority parameters;
将所接收的待消费消息保存至所述优先级参数对应的子主题中,得到每一子主题对应的消息堆积量。The received messages to be consumed are saved in the subtopics corresponding to the priority parameters, and the accumulation of messages corresponding to each subtopic is obtained.
也就是说,在消息生产者生产出待消费消息之后,同时还会配置该待消费消息对应的优先级参数;这样,在通过kafka集群接收消息生产者所发送的待消费消息后,可以根据优先级参数,将所接收的待消费消息保存至对应的子主题中,从而得到每一个子主题的消息堆积量。That is to say, after the message producer produces the message to be consumed, the priority parameter corresponding to the message to be consumed will also be configured; in this way, after receiving the message to be consumed sent by the message producer through the Kafka cluster, it can be based on the priority Level parameters, save the received messages to be consumed in the corresponding subtopics, so as to obtain the accumulation of messages for each subtopic.
其中,如果消息生产者所生产的某优先级参数的消息较多,那么该优先级参数对应的子主题中,消息堆积量就越大;如果消息生产者所生产的某优先级参数的消息较少甚至没有,那么该优先级参数对应的子主题中,消息堆积量就越小,甚至消息堆积量等于0。Among them, if there are more messages with a certain priority parameter produced by the message producer, then in the subtopic corresponding to the priority parameter, the amount of message accumulation will be greater; if the message producer with a certain priority parameter produces more messages If there is less or no, then the message accumulation amount in the subtopic corresponding to the priority parameter is smaller, and even the message accumulation amount is equal to 0.
S302:根据所述第一拉取比例,确定所述待消费主题所拉取消息的实际拉取量;S302: According to the first pull ratio, determine the actual pull amount of messages pulled by the topic to be consumed;
需要说明的是,在获取到第一拉取比例之后,可以根据第一拉取比例进行消息拉取,从而确定出待消费主题中每一子主题的实际拉取量,以确定出待消费主题所拉取消息的实际拉取量。具体地,在一些实施例中,对于S302来说,所述根据所述第一拉取比例,确定所述待消费主题所拉取消息的实际拉取量,可以包括:It should be noted that after the first pull ratio is obtained, the message can be pulled according to the first pull ratio, so as to determine the actual pull amount of each subtopic in the topic to be consumed, so as to determine the topic to be consumed The actual amount of messages pulled. Specifically, in some embodiments, for S302, the determining the actual pull amount of messages pulled by the topic to be consumed according to the first pull ratio may include:
根据所述第一拉取比例对每一子主题对应的消息堆积量进行消息拉取,获得每一子主题所拉取消息的实际拉取量;According to the first pull ratio, perform message pull on the message accumulation amount corresponding to each subtopic, and obtain the actual pull amount of messages pulled by each subtopic;
将所述每一子主题所拉取消息的实际拉取量进行累加,得到所述待消费主题所拉取消息的实际拉取量。The actual pull amount of messages pulled by each subtopic is accumulated to obtain the actual pull amount of messages pulled by the topic to be consumed.
也就是说,在获取到第一拉取比例之后,可以根据第一拉取比例对每一子主题对应的消息堆积量进行消息拉取,获得每一子主题所拉取消息的实际拉取量;然后将每一子主题所拉取消息的实际拉取量进行累加,从而得到该待消费主题所拉取消息的实际拉取量。That is to say, after the first pull ratio is obtained, the message accumulation amount corresponding to each subtopic can be pulled according to the first pull ratio, and the actual pull amount of the messages pulled by each subtopic can be obtained. ; Then the actual pull amount of messages pulled by each subtopic is accumulated to obtain the actual pull amount of messages pulled by the topic to be consumed.
S303:若所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则对所述第一拉取比例进行调整,得到所述多个子主题各自分配的第二拉取比例;S303: If the actual pull amount of the message pulled by the topic to be consumed is less than the preset rated pull amount, adjust the first pull ratio to obtain the second pull allocated by each of the multiple subtopics. Take the ratio
需要说明的是,当多个子主题中其中一个子主题对应的消息堆积量等于0,那么可以得到该子主题所拉取消息的实际拉取量为0;这时候,待消费主题所拉取消息的实际拉取量将小于预设的额定拉取量,也就是说,该方法还可以包 括:若其中一个子主题对应的消息堆积量等于0,则对第一拉取比例进行调整,以得到所述多个子主题各自分配的第二拉取比例。It should be noted that when the accumulation of messages corresponding to one of the multiple subtopics is equal to 0, then the actual pull volume of the messages pulled by the subtopic can be obtained as 0; at this time, the messages pulled by the topic to be consumed The actual pull amount of will be less than the preset rated pull amount, that is, the method may also include: if the message accumulation amount corresponding to one of the subtopics is equal to 0, then the first pull ratio is adjusted to obtain The second pull ratio assigned to each of the multiple subtopics.
进一步地,在一些实施例中,该方法还可以包括:Further, in some embodiments, the method may further include:
基于所述预设的额定拉取量以及所述第一拉取比例,确定所述多个子主题各自对应的预设配额;Determine the preset quota corresponding to each of the multiple subtopics based on the preset rated pull amount and the first pull ratio;
将所述多个子主题中每一子主题所拉取消息的实际拉取量与每一子主题对应的预设配额进行比较;Comparing the actual pull amount of messages pulled by each subtopic of the plurality of subtopics with the preset quota corresponding to each subtopic;
若所述多个子主题中存在实际拉取量小于预设配额的至少一个子主题,则确定所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量。If there is at least one subtopic whose actual pull amount is less than the preset quota among the multiple subtopics, it is determined that the actual pull amount of the message pulled by the topic to be consumed is less than the preset rated pull amount.
也就是说,根据预设的额定拉取量以及第一拉取比例,可以确定出这多个子主题各自对应的预设配额(也可以称为基站配额)。具体地,可以包括:针对所述多个子主题,分别将每一子主题对应的第一拉取比例与所述预设的额定拉取量进行相乘,得到每一子主题对应的预设配额,从而确定出所述多个子主题各自对应的预设配额。That is to say, according to the preset rated pull amount and the first pull ratio, the preset quota (also referred to as base station quota) corresponding to each of the multiple subtopics can be determined. Specifically, it may include: for the multiple subtopics, respectively multiplying the first pull ratio corresponding to each subtopic by the preset rated pull amount to obtain the preset quota corresponding to each subtopic , Thereby determining the preset quota corresponding to each of the multiple subtopics.
这里,每一子主题对应的预设配额表示每一子主题在进行消息拉取时的预设拉取消息个数。在计算出每一子主题对应的预设配额之后,可以将每一子主题所拉取消息的实际拉取量与每一子主题对应的预设配额进行比较;当多个子主题中存在实际拉取量小于预设配额的至少一个子主题,则确定待消费主题所拉取消息的实际拉取量小于预设的额定拉取量。Here, the preset quota corresponding to each subtopic represents the preset number of messages to be pulled when each subtopic is pulled. After calculating the preset quota corresponding to each subtopic, the actual pull amount of messages pulled by each subtopic can be compared with the preset quota corresponding to each subtopic; when there are actual pulls in multiple subtopics If the amount of at least one subtopic is less than the preset quota, it is determined that the actual amount of messages pulled by the topic to be consumed is less than the preset rated amount.
这样,当待消费主题所拉取消息的实际拉取量小于预设的额定拉取量时,表明了这时候需要对第一拉取比例进行动态调整,使得每一优先级参数对应的子主题所分配的拉取配额发生变化;根据变换后的拉取配额所对应的分配比例即为第二拉取比例,如此在下一次的消息拉取时,可以根据第二拉取比例进行消息拉取。In this way, when the actual pull amount of messages pulled by the topic to be consumed is less than the preset rated pull amount, it indicates that the first pull ratio needs to be dynamically adjusted at this time, so that each priority parameter corresponds to the subtopic The allocated pull quota is changed; the allocation ratio corresponding to the transformed pull quota is the second pull ratio, so in the next message pull, the message can be pulled according to the second pull ratio.
换句话说,这种自适应调整不同优先级参数所分配的拉取比例,可以称之为动态配额。具体地,通过动态调整不同优先级的拉取配额(或拉取比例),可以实现动态流控;即在给定的总流控速率下,各优先级的流控速率动态分配,比如当某一优先级队列不存在消息堆积或者称之为消息堆积量等于0时,其流控速率(即拉取配额)可以动态分配给其他优先级使用,即对拉取比例进行调整,从而可以实现总消费速率的最优。In other words, this adaptive adjustment of the pull ratio allocated by different priority parameters can be called a dynamic quota. Specifically, by dynamically adjusting the pull quotas (or pull ratios) of different priorities, dynamic flow control can be achieved; that is, under a given total flow control rate, the flow control rate of each priority is dynamically allocated, such as when a certain When there is no message accumulation in a priority queue, or when the message accumulation amount is equal to 0, its flow control rate (that is, the pull quota) can be dynamically allocated to other priorities, that is, the pull ratio can be adjusted to achieve the total Optimal consumption rate.
还需要说明的是,可以利用预设削减模式和/或预设征集模式来实现动态配额/动态流控。这里,预设削减模式可以看作是主动削减的,预设征集模式可以看作是被动征集的。It should also be noted that the preset reduction mode and/or the preset collection mode can be used to implement dynamic quota/dynamic flow control. Here, the preset reduction mode can be regarded as active reduction, and the preset collection mode can be regarded as passive collection.
可选地,在一些实施例中,对于S303来说,所述对所述第一拉取比例进行调整,可以包括:Optionally, in some embodiments, for S303, the adjusting the first pull ratio may include:
利用预设削减模式对所述多个子主题中待削减子主题对应的预设配额进行削减,并将得到的削减量分配给下一优先级参数对应的子主题,以实现对所述第一拉取比例的调整;其中,所述待削减子主题表示所述多个子主题中所存在的实际拉取量小于预设配额的子主题。The preset reduction mode is used to reduce the preset quota corresponding to the sub-topic to be reduced among the multiple sub-topics, and the obtained reduction amount is allocated to the sub-topic corresponding to the next priority parameter to achieve the first reduction. Proportion adjustment; wherein, the sub-topics to be reduced represent sub-topics of the multiple sub-topics whose actual pull amount is less than a preset quota.
可选地,在一些实施例中,对于S303来说,所述对所述第一拉取比例进行调整,可以包括:Optionally, in some embodiments, for S303, the adjusting the first pull ratio may include:
利用预设征集模式对所述多个子主题对应的预设配额进行征集,并将得到的征集量分配给待扩充子主题,以实现对所述第一拉取比例的调整;其中,所述待扩充子主题表示所述多个子主题中所存在的实际拉取量等于预设配额的子主题。Use the preset collection mode to collect the preset quotas corresponding to the multiple subtopics, and allocate the collected amount to the subtopics to be expanded, so as to realize the adjustment of the first pull ratio; wherein, the waiting Expanding a sub-theme represents a sub-theme whose actual pull amount is equal to a preset quota among the multiple sub-themes.
也就是说,在预设削减模式下,针对某一优先级参数对应的子主题所拉取消息的实际拉取量不足时,将主动释放自身的配额给其他优先级,以实现对第一拉取比例的调整;而在预设征集模式下,针对某一优先级参数对应的子主题所拉取消息的实际拉取量满足预设配额(benchMarkAllocation)时,如果这时候存在空闲配额,比如处于背压(BackPress)状态的优先级参数对应的子主题所主动削减的配额量,此时该优先级参数对应的子主题可以征集这部分配额,以实现对第一拉取比例的调整;其中,benchMarkAllocation表示根据默认或者用户自定义预先配置的不同优先级参数所分配的拉取比例,计算得到的基准配额;BackPress状态表示一种流量控制手段,当某一子主题所拉取消息的实际拉取量低于基准配额,这就表明了该子主题处于背压状态。That is to say, in the preset reduction mode, when the actual pull amount of the message pulled for the subtopic corresponding to a certain priority parameter is insufficient, it will actively release its own quota to other priorities to achieve the first pull. Adjust the proportion; and in the default solicitation mode, when the actual amount of messages pulled for a subtopic corresponding to a priority parameter meets the preset quota (benchMarkAllocation), if there is an idle quota at this time, such as in The priority parameter of the BackPress state corresponds to the amount of quota actively reduced by the sub-theme. At this time, the sub-theme corresponding to the priority parameter can collect this part of the quota to achieve the adjustment of the first pull ratio; among them, benchMarkAllocation represents the calculated benchmark quota based on the pull ratio allocated by default or user-defined pre-configured different priority parameters; BackPress state represents a flow control method, when the actual pull of the message pulled by a certain subtopic The amount is lower than the benchmark quota, which indicates that the sub-topic is under pressure.
S304:根据所述第二拉取比例,对所述待消费主题进行消息拉取。S304: According to the second pull ratio, pull messages for the topic to be consumed.
这样,经过对不同优先级参数对应的拉取比例进行调整后,可以得到第二拉取比例。这时候,如果用户触发SDK再次进行消息拉取,那么可以根据第二拉取比例对待消费主题进行消息拉取,从而再次得到待消费主题所拉取消息的实际拉取量。如此,在S304之后,该方法还可以包括:In this way, after adjusting the pull ratios corresponding to different priority parameters, the second pull ratio can be obtained. At this time, if the user triggers the SDK to pull messages again, they can pull messages for the topic to be consumed according to the second pull ratio, so as to obtain the actual pull amount of messages pulled by the topic to be consumed again. In this way, after S304, the method may further include:
若所得到的待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则继续对所述第二拉取比例进行调整,得到所述多个子主题各自分配的第三拉取比例;If the obtained actual pull amount of the message pulled by the topic to be consumed is less than the preset rated pull amount, continue to adjust the second pull ratio to obtain the third pull allocated by each of the multiple subtopics Take the ratio
根据所述第三拉取比例,对所述待消费主题进行消息拉取。According to the third pull ratio, message pull is performed on the topic to be consumed.
也就是说,只要所得到的待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则需要继续对当前的拉取比例进行调整,然后在下一次用户触发SDK进行消息拉取时,将会根据调整后的新拉取比例进行消息拉取;以实现对拉取比例的动态调整,从而也就实现了对不同优先级参数对应的多个子主题的动态配额。In other words, as long as the actual pull amount of messages pulled by the topic to be consumed is less than the preset rated pull amount, you need to continue to adjust the current pull ratio, and then the next time the user triggers the SDK to pull messages When fetching, the message will be fetched according to the adjusted new fetching ratio; in order to realize the dynamic adjustment of the fetching ratio, the dynamic quota for multiple subtopics corresponding to different priority parameters is also realized.
需要说明的是,本申请实施例的该消息拉取方法中,除了kafka之外,动态配额或者动态流控方式还可以应用到其他具有动态流控需求的中间件,从而获取最优的消费性能。It should be noted that in the message pulling method in the embodiment of the present application, in addition to kafka, dynamic quota or dynamic flow control methods can also be applied to other middleware with dynamic flow control requirements, so as to obtain optimal consumption performance. .
本实施例提供了一种消息拉取方法,通过确定待消费主题所包括的多个子主题以及各自分配的第一拉取比例;其中,不同的子主题具有不同的优先级参数;根据所述第一拉取比例,确定所述待消费主题所拉取消息的实际拉取量;若所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则对所述第一拉取比例进行调整,得到所述多个子主题各自分配的第二拉取比例;根据所述第二拉取比例,对所述待消费主题进行消息拉取。这样,通过自适应动态 配额方式进行动态流控,当部分子主题没有消息堆积时,能够避免因消费组频繁小批次拉取消息所导致的计算速率下降和Kafka集群性能瓶颈的问题,实现了计算性能的优化;另外,在某一子主题突发大流量消息写入的情况下,还能够实时分配和更新其流控速率,从而实现了最优的消费性能。This embodiment provides a method for pulling messages by determining multiple subtopics included in the topic to be consumed and a first pull ratio allocated to each; wherein, different subtopics have different priority parameters; A pull ratio determines the actual pull amount of the message pulled by the topic to be consumed; if the actual pull amount of the message pulled by the topic to be consumed is less than the preset rated pull amount, the second A pull ratio is adjusted to obtain a second pull ratio assigned to each of the multiple subtopics; according to the second pull ratio, message pull is performed on the topic to be consumed. In this way, dynamic flow control is carried out through the adaptive dynamic quota method. When there is no message accumulation in some subtopics, it can avoid the problem of the decrease in the calculation rate and the performance bottleneck of the Kafka cluster caused by the frequent small batches of messages pulled by the consumer group. Optimization of computing performance; In addition, in the case of a subtopic burst of large-flow message writing, it can also allocate and update its flow control rate in real time, thereby achieving optimal consumption performance.
本申请的另一实施例中,以预设削减模式为例,对于S303来说,所述对所述第一拉取比例进行调整,可以包括:In another embodiment of the present application, taking the preset reduction mode as an example, for S303, the adjusting the first pull ratio may include:
若所述多个子主题中其中一个子主题对应的实际拉取量小于预设配额,则将所述其中一个子主题作为待削减子主题,并对所述待削减子主题对应的预设配额进行削减,得到剩余预设配额;If the actual pull amount corresponding to one of the multiple subtopics is less than the preset quota, then the one of the subtopics is regarded as the subtopic to be reduced, and the preset quota corresponding to the subtopic to be reduced is performed Reduce to get the remaining preset quota;
当所述剩余预设配额不低于预设最低配额时,计算所述所述待削减子主题对应的预设配额与剩余预设配额之间的差值,得到可用配额;When the remaining preset quota is not lower than the preset minimum quota, calculating the difference between the preset quota corresponding to the subtopic to be reduced and the remaining preset quota to obtain the available quota;
顺序降低优先级参数,将降低后的优先级参数对应的子主题作为第一子主题;Decrease the priority parameters in order, and use the subtopic corresponding to the reduced priority parameter as the first subtopic;
判断所述第一子主题所对应的预设配额是否大于最大配额阈值且所述第一子主题是否处于全速处理状态;Determining whether the preset quota corresponding to the first sub-topic is greater than a maximum quota threshold and whether the first sub-topic is in a full-speed processing state;
当所述第一子主题对应的预设配额不大于最大配额阈值且所述第一子主题处于全速处理状态时,将所述可用配额分配给所述第一子主题,并更新所述第一子主题对应的预设配额;When the preset quota corresponding to the first sub-topic is not greater than the maximum quota threshold and the first sub-topic is in a full-speed processing state, the available quota is allocated to the first sub-topic, and the first sub-topic is updated. The preset quota corresponding to the subtopic;
当所述第一子主题对应的预设配额大于最大配额阈值且所述第一子主题处于非全速处理状态时,继续执行所述顺序降低优先级参数,将降低后的优先级参数对应的子主题作为第一子主题的步骤,直至将所述可用配额分配至最低优先级参数对应的子主题,以实现对所述第一拉取比例的调整。When the preset quota corresponding to the first sub-topic is greater than the maximum quota threshold and the first sub-topic is in a non-full-speed processing state, continue to execute the lower priority parameter in order, and change the child corresponding to the lower priority parameter The subject is used as the first sub-topic until the available quota is allocated to the sub-topic corresponding to the lowest priority parameter, so as to realize the adjustment of the first pull ratio.
需要说明的是,“顺序降低优先级参数”表示当前为优先级4对应的子主题,执行顺序降低优先级参数后,降低后的优先级参数对应的子主题为优先级3对应的子主题;再一次执行顺序降低优先级参数后,降低后的优先级参数对应的子主题为优先级2对应的子主题,依次类推,在所有优先级参数均处于非全速处理状态下,直至将可用配额分配至最低优先级参数对应的子主题。It should be noted that the "order lower priority parameter" indicates that the current subtopic corresponding to priority 4, after the execution order reduces the priority parameter, the subtopic corresponding to the reduced priority parameter is the subtopic corresponding to priority 3; After the priority parameter is reduced in the execution order again, the subtopic corresponding to the reduced priority parameter is the subtopic corresponding to priority 2, and so on, when all priority parameters are in the non-full-speed processing state, until the available quota is allocated To the subtopic corresponding to the lowest priority parameter.
还需要说明的是,最大配额阈值可以用highWaterMark限制表示,主要是为了避免动态配额导致预设的额定拉取量全部集中分配到特定优先级参数对应的子主题,这时候需要为每个优先级参数配置最大的拉取量限制。而全速处理状态可以用FullProgress状态表示,表示为当前子主题所动态配额后的实际拉取量大于或等于基准配额,也即表明了当前子主题在全速消费消息。It should also be noted that the maximum quota threshold can be expressed as a highWaterMark limit, which is mainly to avoid dynamic quotas causing all preset rated pulls to be centrally allocated to the subtopics corresponding to specific priority parameters. At this time, it is necessary to set each priority Parameter configuration maximum pull limit. The full-speed processing state can be represented by the FullProgress state, which means that the actual pull amount after the dynamic quota of the current subtopic is greater than or equal to the benchmark quota, which means that the current subtopic is consuming messages at full speed.
这样,预设削减模式而言,每次拉取消息时,针对实际拉取量不足预设分配量的优先级参数所对应的子主题,可以降低自身配额。这里,所降低的配额量可以根据实际情况进行设定,比如削减一半的配额量;然后将该子主题自身的配额与该子主题的剩余配额量进行差值计算,所得到的差值作为可用配额进行分配,同时仅向次一级优先级参数对应的子主题分配配额,如果次一级优先级参数对应的子主题自身的配额到达最大配额阈值(highWaterMark限制)时,那么多余的配额可以继续向下一级优先级参数对应的子主题进行分配。另外, 受配额的优先级参数需要处于全速处理(FullProgress)状态,如果所有优先级参数均不处于全速处理状态,那么可用配额最终会聚集到最低优先级参数所对应的子主题,同时最低优先级不做highWaterMark限制。In this way, in terms of the preset reduction mode, each time a message is pulled, its own quota can be reduced for the subtopics corresponding to the priority parameters whose actual pull amount is less than the preset allocation amount. Here, the reduced quota amount can be set according to the actual situation, such as cutting the quota amount by half; then the difference between the quota of the sub-topic itself and the remaining quota of the sub-topic is calculated, and the obtained difference is used as the available The quota is allocated, and quotas are allocated only to the subtopics corresponding to the second-level priority parameters. If the subtopics corresponding to the second-level priority parameters reach the maximum quota threshold (highWaterMark limit), the excess quotas can continue Assign the subtopics corresponding to the lower priority parameters. In addition, the priority parameters subject to quotas need to be in the full progress state. If all priority parameters are not in the full progress state, the available quotas will eventually be aggregated into the subtopics corresponding to the lowest priority parameters, and the lowest priority Do not do highWaterMark restrictions.
进一步地,针对待削减子主题的配额削减,并不会一直无限削减下去,当待削减子主题所对应的动态配额低于预设最低配额时,将会停止对待削减子主题的配额削减;在所有待削减子主题所对应的动态配额均低于预设最低配额时,将会停止对拉取比例的动态调整。因此,在一些实施例中,该方法还可以包括:Furthermore, the quota reduction for the sub-topic to be reduced will not continue to be reduced indefinitely. When the dynamic quota corresponding to the sub-topic to be reduced is lower than the preset minimum quota, the quota reduction for the sub-topic to be reduced will be stopped; When the dynamic quota corresponding to all the subtopics to be reduced is lower than the preset minimum quota, the dynamic adjustment of the pull ratio will be stopped. Therefore, in some embodiments, the method may further include:
每一次对所述待消费主题进行消息拉取后,利用所述第二拉取比例更新所述第一拉取比例;After each message pull on the topic to be consumed, update the first pull ratio by using the second pull ratio;
根据更新后的第一拉取比例对待消费主题进行消息拉取,得到所述待消费主题所拉取消息的更新后实际拉取量;Pull messages for the topic to be consumed according to the updated first pull ratio, and obtain the updated actual pull amount of the messages pulled by the topic to be consumed;
若所述待消费主题所拉取消息的更新后实际拉取量小于预设的额定拉取量,则继续对所述第一拉取比例进行调整,以得到所述第二拉取比例,返回所述利用所述第二拉取比例更新所述第一拉取比例的步骤;If the actual pull amount after the update of the message pulled by the topic to be consumed is less than the preset rated pull amount, continue to adjust the first pull ratio to obtain the second pull ratio, and return The step of using the second pulling ratio to update the first pulling ratio;
在对待消费主题进行多次消息拉取后,当所述待削减子主题所对应的动态配额均达到预设最低配额时,停止对所述第一拉取比例进行调整的步骤。After multiple message pulls are performed on the topic to be consumed, when the dynamic quotas corresponding to the subtopics to be reduced all reach the preset minimum quota, the step of adjusting the first pull ratio is stopped.
也就是说,在每一次对待消费主题进行消息拉取后,可以利用第二拉取比例更新第一拉取比例;如此在下一次通过触发客户端SDK来拉取消息时,可以利用更新后的第一拉取比例进行消息拉取,然后得到待消费主题所拉取消息的更新后实际拉取量;如果所得到的待消费主题所拉取消息的更新后实际拉取量小于预设的额定拉取量,那么需要继续对第一拉取比例进行调整。In other words, after each message is pulled for the topic to be consumed, the second pull ratio can be used to update the first pull ratio; in this way, the next time the client SDK is triggered to pull messages, the updated first pull ratio can be used. Pull the message with a pull ratio, and then obtain the updated actual pull amount of the message pulled by the topic to be consumed; if the obtained actual pull amount of the message pulled from the topic to be consumed is less than the preset rated pull If you take the amount, then you need to continue to adjust the first pull ratio.
如此,在经过多次消息拉取后,当待削减子主题所对应的动态配额均达到预设最低配额时,表明了待削减子主题所对应的动态配额均已经达到低水位限制,这时候需要停止对第一拉取比例进行调整,后续再次通过触发客户端SDK来拉取消息时,可以按照最新动态更新后的拉取比例进行消息拉取。还需要说明的是,预设最低配额主要是为了避免无消息堆积的子主题对应的配额主动削减为0,而设置的配额下限。这里,预设最低配额可以根据实际情况进行具体设定,通常可以将默认配置的预设配额(或者称之为基准配额)的十六分之一作为预设最低配额,但是并不作具体限定。In this way, after multiple message pulls, when the dynamic quotas corresponding to the subtopics to be reduced all reach the preset minimum quota, it indicates that the dynamic quotas corresponding to the subtopics to be reduced have all reached the low water limit. Stop adjusting the first pull ratio, and when you pull the message again by triggering the client SDK later, you can pull the message according to the pull ratio after the latest update. It should also be noted that the preset minimum quota is mainly to prevent the quota corresponding to the subtopics without message accumulation from being automatically reduced to 0, and the lower limit of the quota is set. Here, the preset minimum quota can be specifically set according to actual conditions. Generally, one-sixteenth of the preset quota configured by default (or referred to as a reference quota) can be used as the preset minimum quota, but it is not specifically limited.
参见图4,其示出了本申请实施例提供的一种预设削减模式的应用场景示意图。在图4中,除了Kafka集群102、客户端103和消费者104之外,消息拉取系统10还可以包括有内部状态维护器105;这里,内部状态维护器105可以是一个状态窗口(window)。具体地,同一主题所包括的topic-1、topic-2、topic-3、topic-4和topic-5等五个子主题中,优先级参数包括有5个等级,优先级参数等于5,表示优先级最高;优先级参数等于1,表示优先级最低;而且topic-1和topic-5中有消息堆积,但是topic-2、topic-3和topic-4无消息堆积;假定默认的额定拉取量为500,不同优先级参数对应的预设拉取比例(优先级从高到低)分别为:40%、30%、15%、10%、5%;具体地,topic-5的预设配 额为200,topic-4的预设配额为150,topic-3的预设配额为75,topic-2的预设配额为50,topic-1的预设配额为25;也就是说,仅可以从topic-5和topic-1中拉取消息;这时候利用预设削减模式,topic-2、topic-3、topic-4作为待削减子主题;在每一次拉取消息时,由于实际拉取量低于预设配额,那么将会针对其中一个待削减子主题主动削减一半配额,削减配额将依次分配给次优先级参数对应的子主题;如果次优先级参数也无消息堆积,将继续向下一级优先级参数分配,最终落到最低优先级,以实现拉取比例的调整;在经过多次拉取消息之后,topic-2、topic-3、topic-4这三个待削减子主题的动态配额被将至其默认配额的1/16后,针对topic-2、topic-3、topic-4的更新后配额分别为:3、4、9;而且topic-2、topic-3、topic-4所释放出的配额可以为topic-1和topic-5使用,即可以作为topic-1和topic-5的可征集配额;这里,topic-1和topic-5的可征集配额为259。Refer to FIG. 4, which shows a schematic diagram of an application scenario of a preset reduction mode provided by an embodiment of the present application. In FIG. 4, in addition to the Kafka cluster 102, the client 103, and the consumer 104, the message pulling system 10 may also include an internal state maintainer 105; here, the internal state maintainer 105 may be a state window (window) . Specifically, in the five subtopics of topic-1, topic-2, topic-3, topic-4, and topic-5 included in the same topic, the priority parameter includes 5 levels, and the priority parameter is equal to 5, indicating priority The priority is the highest; the priority parameter is equal to 1, which means the priority is the lowest; and there is a message accumulation in topic-1 and topic-5, but there is no message accumulation in topic-2, topic-3 and topic-4; assuming the default rated pull It is 500. The default pull ratios corresponding to different priority parameters (from high to low) are: 40%, 30%, 15%, 10%, 5%; specifically, the preset quota of topic-5 Is 200, the default quota for topic-4 is 150, the default quota for topic-3 is 75, the default quota for topic-2 is 50, and the default quota for topic-1 is 25; Pull messages from topic-5 and topic-1; at this time, use the preset reduction mode, topic-2, topic-3, and topic-4 as the subtopics to be reduced; each time a message is pulled, due to the actual pull amount If the quota is lower than the preset quota, half of the quota will be actively cut for one of the sub-topics to be reduced, and the reduced quota will be allocated to the sub-topics corresponding to the sub-priority parameter in turn; if the sub-priority parameter has no message accumulation, it will continue downward The first-level priority parameter allocation will eventually fall to the lowest priority to achieve the adjustment of the pull ratio; after multiple pull messages, topic-2, topic-3, and topic-4 are three subtopics to be reduced. After the dynamic quota is reduced to 1/16 of its default quota, the updated quotas for topic-2, topic-3, and topic-4 are: 3, 4, and 9; and topic-2, topic-3, and topic- 4 The released quota can be used for topic-1 and topic-5, that is, it can be used as the solicitable quota for topic-1 and topic-5; here, the solicitable quota for topic-1 and topic-5 is 259.
本申请的又一实施例中,以预设削减模式为例,对于S303来说,所述对所述第一拉取比例进行调整,可以包括:In another embodiment of the present application, taking the preset reduction mode as an example, for S303, the adjusting the first pull ratio may include:
若所述多个子主题中其中一个子主题对应的实际拉取量等于预设配额,则将所述其中一个子主题作为待扩充子主题,按照预设增加量增加所述待扩充子主题对应的预设配额;If the actual pull amount corresponding to one of the multiple subtopics is equal to the preset quota, then the one of the subtopics is regarded as the subtopic to be expanded, and the corresponding amount of the subtopic to be expanded is increased according to the preset increase amount. Preset quota;
针对所述预设增加量,将最低优先级对应的子主题作为第二子主题;Regarding the preset increase amount, the sub-topic corresponding to the lowest priority is taken as the second sub-topic;
判断所述第二子主题是否处于全速处理状态;Determine whether the second sub-topic is in a full-speed processing state;
当所述第二子主题处于全速处理状态时,从所述第二子主题进行配额征集;When the second sub-topic is in a full-speed processing state, perform quota collection from the second sub-topic;
若所征集的配额量小于所述预设增加量,计算所述预设增加量与所征集的配额量之间的差值;If the collected quota amount is less than the preset increase amount, calculate the difference between the preset increase amount and the collected quota amount;
针对所计算的差值,顺序升高优先级参数,将升高后的优先级参数对应的子主题作为第二子主题,继续执行所述判断所述第二子主题是否处于全速处理状态的步骤,直至所征集得到的配额量等于所述预设增加量,以实现对所述第一拉取比例的调整。For the calculated difference, the priority parameters are increased in order, the subtopic corresponding to the increased priority parameter is regarded as the second subtopic, and the step of determining whether the second subtopic is in a full-speed processing state is continued. , Until the solicited quota amount is equal to the preset increase amount, so as to realize the adjustment of the first pull ratio.
进一步地,在所述判断所述第二子主题是否处于全速处理状态之后,该方法还可以包括:Further, after determining whether the second sub-topic is in a full-speed processing state, the method may further include:
当所述第二子主题处于非全速处理状态时,顺序升高优先级参数,将升高后的优先级参数对应的子主题作为第二子主题,继续执行所述判断所述第二子主题是否处于全速处理状态的步骤。When the second sub-topic is in the non-full-speed processing state, the priority parameters are sequentially increased, the sub-topic corresponding to the increased priority parameter is taken as the second sub-topic, and the judgment of the second sub-topic is continued. Whether it is in the full-speed processing state.
需要说明的是,“顺序升高优先级参数”表示当前为优先级2对应的子主题,执行顺序升高优先级参数后,升高后的优先级参数对应的子主题为优先级3对应的子主题;再一次执行顺序升高优先级参数后,升高后的优先级参数对应的子主题为优先级4对应的子主题,依次类推,所征集得到的配额量等于所述预设增加量。It should be noted that the "increase priority parameter in order" means that it is currently the subtopic corresponding to priority 2. After the priority parameter is increased in the execution order, the subtopic corresponding to the increased priority parameter is the one corresponding to priority 3. Sub-topic; after the priority parameter is increased in the execution order again, the sub-topic corresponding to the increased priority parameter is the sub-topic corresponding to priority 4, and so on, the solicited quota amount is equal to the preset increase amount .
还需要说明的是,从第二子主题进行配额征集,首先需要计算第二子主题所能够征集的配额量,即因为其他优先级参数主动削减而加入到本优先级参数 的配额;可以通过第二子主题当前的动态配额减去预设配额,差值即为第二子主题所能够征集的配额量;然后将所能够征集的配额量与预设增加量进行比较;当所征集的配额量小于预设增加量时,计算预设增加量与所征集的配额量之间的差值,该差值递归从高一优先级参数对应的子主题进行征集;当所征集的配额量不小于预设增加量时,该预设增加量可以全部从该子主题进行征集;然后针对其他的待扩充子主题继续进行配额征集。It should also be noted that, to collect quotas from the second sub-topic, first calculate the amount of quotas that can be collected by the second sub-topic, that is, the quota added to the priority parameter due to the active reduction of other priority parameters; The current dynamic quota of the second subtopic minus the preset quota, the difference is the amount of quota that can be collected for the second subtopic; then the amount of quota that can be collected is compared with the preset increase; when the amount of quota collected is less than When the preset increase amount is calculated, the difference between the preset increase amount and the collected quota amount is calculated, and the difference is recursively collected from the subtopic corresponding to the higher priority parameter; when the collected quota amount is not less than the preset increase In the case of quota, the preset increase amount can be solicited from this sub-theme; then the quota solicitation is continued for other sub-themes to be expanded.
这样,对于特定优先级参数无消息堆积的情况下,而后因为消息生产所导致的消息堆积情况,那么之前被削减配额的优先级参数对应的子主题需要补充配额。具体地,可以为通过消费组本次从某优先级参数对应的子主题中所拉取消息的实际拉取量等于当前为其动态分配的预设配额,那么可以对该子主题的配额更新为其增加一倍的拉取配额,即预设增加量可以为该子主题当前的预设配额;而预设增加量(可以用A表示)需要从其他优先级参数对应的子主题征集,征集策略为优先从最低优先级参数对应的子主题征集;针对该最低优先级参数对应的子主题,需要计算该子主题的配额扩充量(即因为其他优先级参数主动削减而加入到本优先级参数的配额),如果当前的配额扩充量B低于预设增加量A,那么剩余部分(A-B)递归从高一优先级征集,直至达到所需的预设增加量。这里,被征集的高优先级参数对应的子主题必须处于Full Progress状态,可征集的配额量大小除了受当前优先级参数对应的highWaterMark限制,还受其他优先级参数对应的配额扩充量限制,总之,还需要保持动态配额的总量是一致的。In this way, when there is no message accumulation for a specific priority parameter, and then the message accumulation situation caused by message production, then the subtopic corresponding to the priority parameter of the previously reduced quota needs to be supplemented with quota. Specifically, it can be that the actual amount of messages pulled from the subtopic corresponding to a certain priority parameter by the consumer group this time is equal to the preset quota currently dynamically allocated for it, then the quota for the subtopic can be updated to It doubles the pull quota, that is, the preset increase amount can be the current preset quota of the subtopic; and the preset increase amount (which can be represented by A) needs to be collected from the subtopics corresponding to other priority parameters, and the solicitation strategy In order to collect priority from the subtopic corresponding to the lowest priority parameter; for the subtopic corresponding to the lowest priority parameter, it is necessary to calculate the quota expansion of the subtopic (that is, the amount of quota expansion added to this priority parameter due to the active reduction of other priority parameters) Quota), if the current quota expansion amount B is lower than the preset increase amount A, the remaining part (AB) is recursively collected from a higher priority until the required preset increase amount is reached. Here, the subtopics corresponding to the high priority parameters collected must be in the Full Progress state, and the amount of quotas that can be collected is not only limited by the highWaterMark corresponding to the current priority parameter, but also limited by the quota expansion corresponding to other priority parameters. , It is also necessary to keep the total amount of dynamic quotas consistent.
进一步地,针对待扩充子主题的配额扩充,并不会一直无限扩充下去,当待扩充子主题所对应的动态配额高于预设最高配额时,将会停止对待扩充子主题的配额扩充;在所有待削减子主题所对应的动态配额均高于预设最低配额时,将会停止对拉取比例的动态调整。因此,在一些实施例中,该方法还可以包括:Furthermore, the quota expansion for the sub-topic to be expanded will not continue to expand indefinitely. When the dynamic quota corresponding to the sub-topic to be expanded is higher than the preset maximum quota, the quota expansion of the sub-topic to be expanded will be stopped; When the dynamic quota corresponding to all the subtopics to be reduced is higher than the preset minimum quota, the dynamic adjustment of the pull ratio will be stopped. Therefore, in some embodiments, the method may further include:
每一次对所述待消费主题进行消息拉取后,利用所述第二拉取比例更新所述第一拉取比例;After each message pull on the topic to be consumed, update the first pull ratio by using the second pull ratio;
根据更新后的第一拉取比例对待消费主题进行消息拉取,得到所述待消费主题所拉取消息的更新后实际拉取量;Pull messages for the topic to be consumed according to the updated first pull ratio, and obtain the updated actual pull amount of the messages pulled by the topic to be consumed;
若所述待消费主题所拉取消息的更新后实际拉取量小于预设的额定拉取量,则继续对所述第一拉取比例进行调整,以得到所述第二拉取比例,返回所述利用所述第二拉取比例更新所述第一拉取比例的步骤;If the actual pull amount after the update of the message pulled by the topic to be consumed is less than the preset rated pull amount, continue to adjust the first pull ratio to obtain the second pull ratio, and return The step of using the second pulling ratio to update the first pulling ratio;
在对待消费主题进行多次消息拉取后,当所述待扩充子主题所对应的动态配额均达到预设最高配额时,停止对所述第一拉取比例进行调整的步骤。After multiple message pulls for the topic to be consumed, when the dynamic quotas corresponding to the subtopics to be expanded all reach the preset maximum quota, the step of adjusting the first pull ratio is stopped.
也就是说,在每一次对待消费主题进行消息拉取后,可以利用第二拉取比例更新第一拉取比例;如此在下一次通过触发客户端SDK来拉取消息时,可以利用更新后的第一拉取比例进行消息拉取,然后得到待消费主题所拉取消息的更新后实际拉取量;如果所得到的待消费主题所拉取消息的更新后实际拉取量小于预设的额定拉取量,那么需要继续对第一拉取比例进行调整。In other words, after each message is pulled for the topic to be consumed, the second pull ratio can be used to update the first pull ratio; in this way, the next time the client SDK is triggered to pull messages, the updated first pull ratio can be used. Pull the message with a pull ratio, and then obtain the updated actual pull amount of the message pulled by the topic to be consumed; if the obtained actual pull amount of the message pulled from the topic to be consumed is less than the preset rated pull If you take the amount, then you need to continue to adjust the first pull ratio.
如此,在经过多次消息拉取后,当待扩充子主题所对应的动态配额均达到预设最高配额时,表明了待扩充子主题所对应的动态配额均已经达到高水位限制,这时候需要停止对第一拉取比例进行调整,后续再次通过触发客户端SDK来拉取消息时,可以按照最新动态更新后的拉取比例进行消息拉取。还需要说明的是,预设最高配额主要是为了避免有消息堆积的子主题对应的配额被动征集后全部集中到特定优先级参数对应的子主题,而设置的配额上限。这里,预设最高配额可以根据实际情况进行具体设定,通常对于最低优先级参数而言,其预设最高配额可以为默认配置的预设配额(或者称之为基准配额)的一倍;而其他优先级参数,其预设最高配额可以为其自身基准配额的八倍,但是并不作具体限定。In this way, after multiple message pulls, when the dynamic quotas corresponding to the subtopics to be expanded all reach the preset maximum quota, it indicates that the dynamic quotas corresponding to the subtopics to be expanded have reached the high water limit. Stop adjusting the first pull ratio, and when you pull the message again by triggering the client SDK later, you can pull the message according to the pull ratio after the latest update. It should also be noted that the preset maximum quota is mainly used to prevent the passive collection of quotas corresponding to subtopics with accumulated messages and then concentrate all the quotas on the subtopics corresponding to specific priority parameters. Here, the preset maximum quota can be specifically set according to actual conditions. Generally, for the lowest priority parameter, the preset maximum quota can be twice the preset quota (or referred to as the benchmark quota) configured by default; and For other priority parameters, the preset maximum quota can be eight times of its own benchmark quota, but it is not specifically limited.
参见图5,其示出了本申请实施例提供的一种预设征集模式的应用场景示意图。在图5中,除了Kafka集群102、客户端103和消费者104之外,消息拉取系统10仍包括有内部状态维护器105。具体地,同一主题所包括的topic-1、topic-2、topic-3、topic-4和topic-5等五个子主题中,优先级参数包括有5个等级,优先级参数等于5,表示优先级最高;优先级参数等于1,表示优先级最低;而且topic-1和topic-5中有消息堆积,但是topic-2、topic-3和topic-4无消息堆积;假定默认的额定拉取量为500,不同优先级参数对应的预设拉取比例(优先级从高到低)分别为:40%、30%、15%、10%、5%;具体地,topic-5的预设配额为200,topic-4的预设配额为150,topic-3的预设配额为75,topic-2的预设配额为50,topic-1的预设配额为25;也就是说,仍然是仅可以从topic-5和topic-1中拉取消息;这时候利用预设征集模式,对于topic-1来说,其作为最低优先级参数,其预设最高配额可以为默认配置的预设配额的一倍,即可以增加的配额量为25,也就是说,topic-1更新后配额为50;这里,所增加的配额量可以从topic-2征集;由于topic-2、topic-3、topic-4等三个优先级参数所释放出的可征集配额为259;那么对于topic-5来说,其作为最高优先级参数,从该可征集配额中,可以获得能够增加的配额量为234,也就是说,topic-5更新后配额为434;这种情况下,再次通过触发客户端SDK来拉取消息时,待消费主题所拉取消息的实际拉取量为484。Refer to FIG. 5, which shows a schematic diagram of an application scenario of a preset solicitation mode provided by an embodiment of the present application. In FIG. 5, in addition to the Kafka cluster 102, the client 103, and the consumer 104, the message pulling system 10 still includes an internal state maintainer 105. Specifically, in the five subtopics of topic-1, topic-2, topic-3, topic-4, and topic-5 included in the same topic, the priority parameter includes 5 levels, and the priority parameter is equal to 5, indicating priority The priority is the highest; the priority parameter is equal to 1, which means the priority is the lowest; and there is a message accumulation in topic-1 and topic-5, but there is no message accumulation in topic-2, topic-3 and topic-4; assuming the default rated pull It is 500. The default pull ratios corresponding to different priority parameters (from high to low) are: 40%, 30%, 15%, 10%, 5%; specifically, the preset quota of topic-5 Is 200, the default quota for topic-4 is 150, the default quota for topic-3 is 75, the default quota for topic-2 is 50, and the default quota for topic-1 is 25; that is, it is still only Messages can be pulled from topic-5 and topic-1; at this time, the preset collection mode is used. For topic-1, it is used as the lowest priority parameter, and the preset maximum quota can be the preset quota configured by default Doubled, the quota that can be increased is 25, that is, the quota after topic-1 is updated is 50; here, the increased quota can be collected from topic-2; due to topic-2, topic-3, topic- 4 etc. The available quota released by the three priority parameters is 259; then for topic-5, it is the highest priority parameter. From the available quota, the amount of quota that can be increased is 234. In other words, the quota after topic-5 is updated is 434; in this case, when the client SDK is triggered again to pull messages, the actual pull amount of messages pulled by the topic to be consumed is 484.
也就是说,基于图5所示的场景示例,topic-1和topic-5作为待扩充子主题,可以征集从topic-2、topic-3、topic-4等3个优先级参数所释放出来的配额,然后根据高优先级参数对应高配额的拉取消息占比以及高水位限制,从而保证高优先级参数可以拥有更多的计算资源来处理消息。That is to say, based on the scenario example shown in Figure 5, topic-1 and topic-5 are subtopics to be expanded, which can be released from the three priority parameters of topic-2, topic-3, and topic-4. Quota, and then according to the high-priority parameter corresponding to the proportion of the high-quota pull message and the high water mark limit, so as to ensure that the high-priority parameter can have more computing resources to process the message.
在本申请实施例中,通过预设削减模式和预设征集模式等两个策略来实现动态配额和动态流控,可以避免固定比例拉取消息时所存在的因当部分子主题没有消息堆积时而消费组频繁小批次拉取消息所导致的计算速率下降和Kafka集群性能瓶颈的问题,实现了计算性能的最优;并且依赖动态配额实现的动态流控,在某一子主题突发大流量消息写入的情况下,还能够实时分配和更新其流控速率,以实现最优的消费性能。也就是说,本申请实施例的消息拉取方法的实现方式中存在有一个状态窗口(Window),用于收集元数据、保存默认配 额、当前配额、配额高水位、配额低水位、各优先级的处理状态等;而Window会被具体的实现策略(比如负载均衡(LoadBalance)策略)调用以实现配额比例的分配和征集,各个优先级参数对应的子主题每次拉取消息的实际拉取量可以作为元数据写入Window,并且Window会实时更新各优先级参数的处理状态,然后由Load Balance在给定时间间隔内调用以触发动态配额和动态流控,而且动态配额会计算出发生配额变化的优先级参数并通过反射更新Kafka集群内消费者每次拉取消息的实际拉取量,动态流控则是通过计算动态配额后各优先级参数相对于默认的预设配额的比例,从而得出各优先级参数当前应分配的流控速率,且保持动态配额的总量是一致的。In the embodiment of this application, dynamic quotas and dynamic flow control are implemented through two strategies, such as a preset reduction mode and a preset collection mode, which can avoid the problem of pulling messages in a fixed proportion when there is no accumulation of messages in some subtopics. The consumption group frequently pulls messages in small batches, resulting in the decrease of computing rate and the performance bottleneck of the Kafka cluster, which achieves the optimal computing performance; and relying on dynamic flow control implemented by dynamic quotas, bursts of large traffic in a certain subtopic In the case of message writing, the flow control rate can also be allocated and updated in real time to achieve optimal consumption performance. That is to say, there is a status window (Window) in the implementation of the message pull method in the embodiment of the present application, which is used to collect metadata, save the default quota, the current quota, the quota high water level, the quota low water level, and each priority. Processing status, etc.; Window will be called by specific implementation strategies (such as LoadBalance) to realize the allocation and collection of quota ratios, and the actual pull amount of each message pulled by the subtopics corresponding to each priority parameter It can be written to Window as metadata, and Window will update the processing status of each priority parameter in real time, and then called by Load Balance within a given time interval to trigger dynamic quota and dynamic flow control, and dynamic quota will calculate the quota change The priority parameter is updated by reflection to update the actual pull amount of each message pulled by consumers in the Kafka cluster. Dynamic flow control is calculated by calculating the ratio of each priority parameter to the default preset quota after the dynamic quota. The current flow control rate that each priority parameter should be allocated, and keep the total amount of dynamic quotas consistent.
本实施例提供了一种消息拉取方法,通过上述实施例对前述实施例的具体实现进行详细阐述,从中可以看出,通过预设削减模式和预设征集模式等两个策略来实现动态配额和动态流控,当部分子主题没有消息堆积时,能够避免因消费组频繁小批次拉取消息所导致的计算速率下降和Kafka集群性能瓶颈的问题,实现了计算性能的优化;另外,在某一子主题突发大流量消息写入的情况下,还能够实时分配和更新其流控速率,从而实现了最优的消费性能。This embodiment provides a message pull method. The specific implementation of the foregoing embodiment is described in detail through the foregoing embodiment. It can be seen from the above that the dynamic quota is realized through two strategies, namely, a preset reduction mode and a preset collection mode. And dynamic flow control, when there is no accumulation of messages in some subtopics, it can avoid the decrease of the calculation rate and the performance bottleneck of the Kafka cluster caused by the frequent small batches of messages pulled by the consumer group, and the optimization of the calculation performance is realized; in addition, in When a certain subtopic is written in bursts of high-traffic messages, it can also allocate and update its flow control rate in real time, thereby achieving optimal consumption performance.
基于前述实施例相同的发明构思,参见图6,其示出了本申请实施例提供的一种消息拉取装置的组成结构示意图。如图6所示,该消息拉取装置60可以包括确定单元601、调整单元602和拉取单元603;其中,Based on the same inventive concept as the foregoing embodiment, refer to FIG. 6, which shows a schematic diagram of the composition structure of a message pulling device provided in an embodiment of the present application. As shown in FIG. 6, the message pulling device 60 may include a determining unit 601, an adjusting unit 602, and a pulling unit 603; among them,
确定单元601,配置为确定待消费主题所包括的多个子主题以及各自分配的第一拉取比例;其中,不同的子主题具有不同的优先级参数;The determining unit 601 is configured to determine a plurality of subtopics included in the topic to be consumed and the first pull ratio allocated to each; wherein, different subtopics have different priority parameters;
确定单元601,还配置为根据所述第一拉取比例,确定所述待消费主题所拉取消息的实际拉取量;The determining unit 601 is further configured to determine the actual pull amount of the message pulled by the topic to be consumed according to the first pull ratio;
调整单元602,配置为若所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则对所述第一拉取比例进行调整,得到所述多个子主题各自分配的第二拉取比例;The adjusting unit 602 is configured to, if the actual pull amount of the message pulled by the topic to be consumed is less than the preset rated pull amount, adjust the first pull ratio to obtain the respective distribution of the multiple subtopics Second pull ratio;
拉取单元603,配置为根据所述第二拉取比例,对所述待消费主题进行消息拉取。The pulling unit 603 is configured to pull messages of the topic to be consumed according to the second pulling ratio.
在上述方案中,参见图7,该消息拉取装置60还可以包括接收单元604和保存单元605;其中,In the above solution, referring to FIG. 7, the message pulling device 60 may further include a receiving unit 604 and a storing unit 605; wherein,
接受单元604,配置为接收消息生产者所发送的待消费消息,所述待消费消息中包括消息内容和优先级参数;The receiving unit 604 is configured to receive a message to be consumed sent by a message producer, where the message to be consumed includes message content and priority parameters;
保存单元605,配置为将所接收的待消费消息保存至所述优先级参数对应的子主题中,得到每一子主题对应的消息堆积量。The saving unit 605 is configured to save the received messages to be consumed in the subtopics corresponding to the priority parameters to obtain the message accumulation amount corresponding to each subtopic.
在上述方案中,参见图7,该消息拉取装置60还可以包括计算单元606;其中,In the above solution, referring to FIG. 7, the message pulling device 60 may further include a calculation unit 606; wherein,
拉取单元603,还配置为根据所述第一拉取比例对每一子主题对应的消息堆积量进行消息拉取,获得每一子主题所拉取消息的实际拉取量;The pulling unit 603 is further configured to pull the message accumulation amount corresponding to each subtopic according to the first pull ratio, and obtain the actual pull amount of the messages pulled by each subtopic;
计算单元606,配置为将所述每一子主题所拉取消息的实际拉取量进行累加,得到所述待消费主题所拉取消息的实际拉取量。The calculation unit 606 is configured to accumulate the actual pull amount of messages pulled by each subtopic to obtain the actual pull amount of messages pulled by the topic to be consumed.
在上述方案中,确定单元601,还配置为若所述多个子主题中其中一个子主题对应的消息堆积量等于0,则得到所述其中一个子主题所拉取消息的实际拉取量为0;In the above solution, the determining unit 601 is further configured to obtain that the actual pull amount of messages pulled by one of the subtopics is 0 if the message accumulation amount corresponding to one of the multiple subtopics is equal to 0. ;
相应的,调整单元602,还配置为若其中一个子主题对应的消息堆积量等于0,则对所述第一拉取比例进行调整,以得到所述多个子主题各自分配的第二拉取比例。Correspondingly, the adjustment unit 602 is further configured to adjust the first pull ratio if the message accumulation amount corresponding to one of the subtopics is equal to 0, so as to obtain the second pull ratio assigned to each of the multiple subtopics .
在上述方案中,参见图7,该消息拉取装置60还可以包括比较单元607;其中,In the above solution, referring to FIG. 7, the message pulling device 60 may further include a comparing unit 607; wherein,
确定单元601,还配置为基于所述预设的额定拉取量以及所述第一拉取比例,确定所述多个子主题各自对应的预设配额;The determining unit 601 is further configured to determine the preset quota corresponding to each of the multiple subtopics based on the preset rated pull amount and the first pull ratio;
比较单元607,配置为将所述多个子主题中每一子主题所拉取消息的实际拉取量与每一子主题对应的预设配额进行比较;以及若所述多个子主题中存在实际拉取量小于预设配额的至少一个子主题,则确定所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量。The comparing unit 607 is configured to compare the actual pull amount of messages pulled by each subtopic of the plurality of subtopics with the preset quota corresponding to each subtopic; and if there are actual pulls in the plurality of subtopics; At least one subtopic whose amount is less than the preset quota, it is determined that the actual amount of messages pulled by the topic to be consumed is less than the preset rated amount of pulling.
在上述方案中,调整单元602,还配置为利用预设削减模式对所述多个子主题中待削减子主题对应的预设配额进行削减,并将得到的削减量分配给下一优先级参数对应的子主题,以实现对所述第一拉取比例的调整;其中,所述待削减子主题表示多个子主题中所存在的实际拉取量小于预设配额的子主题。In the above solution, the adjustment unit 602 is further configured to use a preset reduction mode to reduce the preset quota corresponding to the subtopic to be reduced among the plurality of subtopics, and allocate the obtained reduction amount to the next priority parameter corresponding The sub-themes of to achieve the adjustment of the first pull ratio; wherein, the sub-topics to be reduced refer to sub-topics of multiple sub-topics whose actual pull amount is less than a preset quota.
在上述方案中,比较单元607,还配置为若所述多个子主题中其中一个子主题对应的实际拉取量小于预设配额,则将所述其中一个子主题作为待削减子主题,并对所述待削减子主题对应的预设配额进行削减,得到剩余预设配额;以及当所述剩余预设配额不低于预设最低配额时,计算所述所述待削减子主题对应的预设配额与剩余预设配额之间的差值,得到可用配额;In the above solution, the comparison unit 607 is further configured to, if the actual pull amount corresponding to one of the multiple subtopics is less than the preset quota, use the one of the subtopics as the subtopic to be reduced, and compare The preset quota corresponding to the sub-topic to be reduced is reduced to obtain the remaining preset quota; and when the remaining preset quota is not lower than the preset minimum quota, the preset corresponding to the sub-topic to be reduced is calculated The difference between the quota and the remaining preset quota is the available quota;
调整单元602,具体配置为顺序降低优先级参数,将降低后的优先级参数对应的子主题作为第一子主题;以及判断所述第一子主题所对应的预设配额是否大于最大配额阈值且所述第一子主题是否处于全速处理状态;以及当所述第一子主题对应的预设配额不大于最大配额阈值且所述第一子主题处于全速处理状态时,将所述可用配额分配给所述第一子主题,并更新所述第一子主题对应的预设配额;以及当所述第一子主题对应的预设配额大于最大配额阈值且所述第一子主题处于非全速处理状态时,继续执行所述顺序降低优先级参数,将降低后的优先级参数对应的子主题作为第一子主题的步骤,直至将所述可用配额分配至最低优先级参数对应的子主题,以实现对所述第一拉取比例的调整。The adjustment unit 602 is specifically configured to sequentially reduce the priority parameters, and use the subtopic corresponding to the reduced priority parameter as the first subtopic; and determine whether the preset quota corresponding to the first subtopic is greater than the maximum quota threshold and Whether the first sub-topic is in the full-speed processing state; and when the preset quota corresponding to the first sub-topic is not greater than the maximum quota threshold and the first sub-topic is in the full-speed processing state, allocating the available quota to The first sub-topic, and update the preset quota corresponding to the first sub-topic; and when the preset quota corresponding to the first sub-topic is greater than the maximum quota threshold and the first sub-topic is in a non-full-speed processing state , Continue to execute the step of lowering the priority parameters in order, and using the subtopic corresponding to the reduced priority parameter as the first subtopic, until the available quota is allocated to the subtopic corresponding to the lowest priority parameter to achieve Adjustment of the first pull ratio.
在上述方案中,调整单元602,还配置为利用预设征集模式对所述多个子主题对应的预设配额进行征集,并将得到的征集量分配给待扩充子主题,以实现对所述第一拉取比例的调整;其中,所述待扩充子主题表示多个子主题中所存在的实际拉取量等于预设配额的子主题。In the above solution, the adjustment unit 602 is further configured to collect preset quotas corresponding to the multiple subtopics by using a preset collection mode, and allocate the collected amount to the subtopics to be expanded, so as to realize the An adjustment of the pull ratio; wherein, the sub-topic to be expanded represents a sub-topic whose actual pull amount is equal to a preset quota among multiple sub-topics.
在上述方案中,比较单元607,还配置为若所述多个子主题中其中一个子主题对应的实际拉取量等于预设配额,则将所述其中一个子主题作为待扩充子主题,按照预设增加量增加所述待扩充子主题对应的预设配额;In the above solution, the comparing unit 607 is further configured to, if the actual pull amount corresponding to one of the multiple subtopics is equal to the preset quota, use the one of the subtopics as the subtopic to be expanded, according to the preset quota. Set the increase amount to increase the preset quota corresponding to the subtopic to be expanded;
调整单元602,具体配置为针对所述预设增加量,将最低优先级对应的子主题作为第二子主题;以及判断所述第二子主题是否处于全速处理状态;以及当所述第二子主题处于全速处理状态时,从所述第二子主题进行配额征集;以及若所征集的配额量小于所述预设增加量,计算所述预设增加量与所征集的配额量之间的差值;以及针对所计算的差值,顺序升高优先级参数,将升高后的优先级参数对应的子主题作为第二子主题,继续执行所述判断所述第二子主题是否处于全速处理状态的步骤,直至所征集得到的配额量等于所述预设增加量,以实现对所述第一拉取比例的调整。The adjustment unit 602 is specifically configured to use the sub-topic corresponding to the lowest priority as the second sub-topic for the preset increase amount; and determine whether the second sub-topic is in a full-speed processing state; and when the second sub-topic When the subject is in a full-speed processing state, collect quotas from the second subtopic; and if the amount of quota collected is less than the preset increase amount, calculate the difference between the preset increase amount and the collected quota amount Value; and for the calculated difference, the priority parameter is increased in order, the subtopic corresponding to the increased priority parameter is taken as the second subtopic, and the judgment is continued to determine whether the second subtopic is in full-speed processing In the state step, until the solicited quota amount is equal to the preset increase amount, so as to realize the adjustment of the first pull ratio.
在上述方案中,调整单元602,还配置为当所述第二子主题处于非全速处理状态时,顺序升高优先级参数,将升高后的优先级参数对应的子主题作为第二子主题,继续执行所述判断所述第二子主题是否处于全速处理状态的步骤。In the above solution, the adjustment unit 602 is further configured to increase the priority parameters in order when the second sub-topic is in the non-full-speed processing state, and use the sub-topic corresponding to the increased priority parameter as the second sub-topic , Continue to execute the step of determining whether the second sub-topic is in a full-speed processing state.
可以理解地,在本实施例中,“单元”可以是部分电路、部分处理器、部分程序或软件等等,当然也可以是模块,还可以是非模块化的。而且在本实施例中的各组成部分可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。It can be understood that, in this embodiment, a "unit" may be a part of a circuit, a part of a processor, a part of a program or software, etc., of course, it may also be a module, or it may also be non-modular. Moreover, the various components in this embodiment may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit. The above-mentioned integrated unit can be realized in the form of hardware or software function module.
所述集成的单元如果以软件功能模块的形式实现并非作为独立的产品进行销售或使用时,可以存储在一个计算机可读取存储介质中,基于这样的理解,本实施例的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或processor(处理器)执行本实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。If the integrated unit is implemented in the form of a software function module and is not sold or used as an independent product, it can be stored in a computer readable storage medium. Based on this understanding, the technical solution of this embodiment is essentially or It is said that the part that contributes to the existing technology or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can It is a personal computer, a server, or a network device, etc.) or a processor (processor) that executes all or part of the steps of the method described in this embodiment. The aforementioned storage media include: U disk, mobile hard disk, read only memory (Read Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program codes.
因此,本实施例提供了一种计算机存储介质,该计算机存储介质存储有消息拉取程序,所述消息拉取程序被至少一个处理器执行时实现前述实施例中任一项所述的方法。Therefore, this embodiment provides a computer storage medium that stores a message pull program that implements the method described in any one of the foregoing embodiments when the message pull program is executed by at least one processor.
基于上述消息拉取装置60的组成以及计算机存储介质,参见图8,其示出了本申请实施例提供的消息拉取装置60的具体硬件结构示例,可以包括:通信接口801、存储器802和处理器803;各个组件通过总线系统804耦合在一起。可理解,总线系统804用于实现这些组件之间的连接通信。总线系统804除包括数据总线之外,还包括电源总线、控制总线和状态信号总线。但是为了清楚说明起见,在图8中将各种总线都标为总线系统804。其中,通信接口801,用于在与其他外部网元之间进行收发信息过程中,信号的接收和发送;Based on the composition of the message pulling device 60 and the computer storage medium described above, see FIG. 8, which shows an example of a specific hardware structure of the message pulling device 60 provided in an embodiment of the present application, which may include: a communication interface 801, a memory 802, and processing 803; The various components are coupled together through the bus system 804. It can be understood that the bus system 804 is used to implement connection and communication between these components. In addition to the data bus, the bus system 804 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clear description, various buses are marked as the bus system 804 in FIG. 8. Among them, the communication interface 801 is used for receiving and sending signals in the process of sending and receiving information with other external network elements;
存储器802,用于存储能够在处理器803上运行的计算机程序;The memory 802 is configured to store a computer program that can run on the processor 803;
处理器803,用于在运行所述计算机程序时,执行:The processor 803 is configured to execute: when the computer program is running:
确定待消费主题所包括的多个子主题以及各自分配的第一拉取比例;其中,不同的子主题具有不同的优先级参数;Determine the multiple sub-themes included in the theme to be consumed and the first pull ratio assigned to each; among them, different sub-themes have different priority parameters;
根据所述第一拉取比例,确定所述待消费主题所拉取消息的实际拉取量;According to the first pull ratio, determine the actual pull amount of messages pulled by the topic to be consumed;
若所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则对所述第一拉取比例进行调整,得到所述多个子主题各自分配的第二拉取比例;If the actual pull amount of the message pulled by the topic to be consumed is less than the preset rated pull amount, the first pull ratio is adjusted to obtain the second pull ratio assigned to each of the multiple subtopics ;
根据所述第二拉取比例,对所述待消费主题进行消息拉取。According to the second pulling ratio, message pulling is performed on the topic to be consumed.
可以理解,本申请实施例中的存储器802可以是易失性存储器或非易失性存储器,或可包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(Read-Only Memory,ROM)、可编程只读存储器(Programmable ROM,PROM)、可擦除可编程只读存储器(Erasable PROM,EPROM)、电可擦除可编程只读存储器(Electrically EPROM,EEPROM)或闪存。易失性存储器可以是随机存取存储器(Random Access Memory,RAM),其用作外部高速缓存。通过示例性但不是限制性说明,许多形式的RAM可用,例如静态随机存取存储器(Static RAM,SRAM)、动态随机存取存储器(Dynamic RAM,DRAM)、同步动态随机存取存储器(Synchronous DRAM,SDRAM)、双倍数据速率同步动态随机存取存储器(Double DataRate SDRAM,DDRSDRAM)、增强型同步动态随机存取存储器(Enhanced SDRAM,ESDRAM)、同步链动态随机存取存储器(Synchronous link DRAM,SLDRAM)和直接内存总线随机存取存储器(Direct Rambus RAM,DRRAM)。本申请描述的系统和方法的存储器802旨在包括但不限于这些和任意其它适合类型的存储器。It can be understood that the memory 802 in the embodiment of the present application may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memory. Among them, the non-volatile memory can be read-only memory (Read-Only Memory, ROM), programmable read-only memory (Programmable ROM, PROM), erasable programmable read-only memory (Erasable PROM, EPROM), and electrically available Erase programmable read-only memory (Electrically EPROM, EEPROM) or flash memory. The volatile memory may be a random access memory (Random Access Memory, RAM), which is used as an external cache. By way of exemplary but not restrictive description, many forms of RAM are available, such as static random access memory (Static RAM, SRAM), dynamic random access memory (Dynamic RAM, DRAM), synchronous dynamic random access memory (Synchronous DRAM, SDRAM), Double Data Rate Synchronous Dynamic Random Access Memory (Double Data Rate SDRAM, DDRSDRAM), Enhanced Synchronous Dynamic Random Access Memory (Enhanced SDRAM, ESDRAM), Synchronous Link Dynamic Random Access Memory (Synchronous Link DRAM, SLDRAM) And Direct Rambus RAM (DRRAM). The memory 802 of the system and method described in this application is intended to include, but is not limited to, these and any other suitable types of memory.
而处理器803可能是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器803中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器803可以是通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field Programmable GateArray,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器802,处理器803读取存储器802中的信息,结合其硬件完成上述方法的步骤。The processor 803 may be an integrated circuit chip with signal processing capability. In the implementation process, the steps of the foregoing method can be completed by an integrated logic circuit of hardware in the processor 803 or instructions in the form of software. The aforementioned processor 803 may be a general-purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other Programming logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps, and logical block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor or the like. The steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed and completed by a hardware decoding processor, or executed and completed by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the field, such as random access memory, flash memory, read-only memory, programmable read-only memory, or electrically erasable programmable memory, registers. The storage medium is located in the memory 802, and the processor 803 reads the information in the memory 802, and completes the steps of the foregoing method in combination with its hardware.
可以理解的是,本申请描述的这些实施例可以用硬件、软件、固件、中间件、微码或其组合来实现。对于硬件实现,处理单元可以实现在一个或多个专用集成电路(Application Specific Integrated Circuits,ASIC)、数字信号处理器(Digital Signal Processing,DSP)、数字信号处理设备(DSP Device,DSPD)、可编程逻辑设备(Programmable Logic Device,PLD)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)、通用处理器、控制器、微控制器、微处理器、用于执行本申请所述功能的其它电子单元或其组合中。It can be understood that the embodiments described in this application can be implemented by hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit can be implemented in one or more application specific integrated circuits (ASIC), digital signal processor (Digital Signal Processing, DSP), digital signal processing equipment (DSP Device, DSPD), programmable Logic device (Programmable Logic Device, PLD), Field-Programmable Gate Array (Field-Programmable Gate Array, FPGA), general-purpose processors, controllers, microcontrollers, microprocessors, and others for performing the functions described in this application Electronic unit or its combination.
对于软件实现,可通过执行本申请所述功能的模块(例如过程、函数等) 来实现本申请所描述的技术。软件代码可存储在存储器中并通过处理器执行。存储器可以在处理器中或在处理器外部实现。For software implementation, the technology described in this application can be implemented through modules (for example, procedures, functions, etc.) that perform the functions described in this application. The software codes can be stored in the memory and executed by the processor. The memory can be implemented in the processor or external to the processor.
可选地,作为另一个实施例,处理器803还配置为在运行所述计算机程序时,执行前述实施例中任一项所述的方法的步骤。Optionally, as another embodiment, the processor 803 is further configured to execute the steps of the method described in any one of the foregoing embodiments when the computer program is running.
需要说明的是,在本申请中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。It should be noted that in this application, the terms "including", "including" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements , And also include other elements not explicitly listed, or elements inherent to the process, method, article, or device. If there are no more restrictions, the element defined by the sentence "including a..." does not exclude the existence of other identical elements in the process, method, article, or device that includes the element.
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。The serial numbers of the foregoing embodiments of the present application are for description only, and do not represent the superiority or inferiority of the embodiments.
本申请所提供的几个方法实施例中所揭露的方法,在不冲突的情况下可以任意组合,得到新的方法实施例。The methods disclosed in the several method embodiments provided in this application can be combined arbitrarily without conflict to obtain new method embodiments.
本申请所提供的几个产品实施例中所揭露的特征,在不冲突的情况下可以任意组合,得到新的产品实施例。The features disclosed in the several product embodiments provided in this application can be combined arbitrarily without conflict to obtain new product embodiments.
本申请所提供的几个方法或设备实施例中所揭露的特征,在不冲突的情况下可以任意组合,得到新的方法实施例或设备实施例。The features disclosed in the several method or device embodiments provided in this application can be combined arbitrarily without conflict to obtain a new method embodiment or device embodiment.
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。The above are only specific implementations of this application, but the protection scope of this application is not limited to this. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in this application. Should be covered within the scope of protection of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.
工业实用性Industrial applicability
本申请实施例中,通过通过确定待消费主题所包括的多个子主题以及各自分配的第一拉取比例;其中,不同的子主题具有不同的优先级参数;根据所述第一拉取比例,确定所述待消费主题所拉取消息的实际拉取量;若所述待消费主题所拉取消息的实际拉取量小于预设的额定拉取量,则对所述第一拉取比例进行调整,得到所述多个子主题各自分配的第二拉取比例;根据所述第二拉取比例,对所述待消费主题进行消息拉取。这样,通过自适应动态配额方式进行动态流控,当部分子主题没有消息堆积时,能够避免因消费组频繁小批次拉取消息所导致的计算速率下降和Kafka集群性能瓶颈的问题,实现了计算性能的优化;另外,在某一子主题突发大流量消息写入的情况下,还能够实时分配和更新其流控速率,从而实现了最优的消费性能。In the embodiment of the present application, by determining the multiple subtopics included in the theme to be consumed and the first pull ratio assigned to each; wherein, different subtopics have different priority parameters; according to the first pull ratio, Determine the actual pull amount of messages pulled by the topic to be consumed; if the actual pull amount of messages pulled by the topic to be consumed is less than the preset rated pull amount, perform the first pull ratio Adjust to obtain a second pull ratio allocated to each of the multiple subtopics; and pull messages for the topic to be consumed according to the second pull ratio. In this way, dynamic flow control is carried out through the adaptive dynamic quota method. When there is no message accumulation in some subtopics, it can avoid the problem of the decrease in the calculation rate and the performance bottleneck of the Kafka cluster caused by the frequent small batches of messages pulled by the consumer group. Optimization of computing performance; In addition, in the case of a subtopic burst of large-flow message writing, it can also allocate and update its flow control rate in real time, thereby achieving optimal consumption performance.