Message processing method, device and system

By introducing a shared thread pool and a local cache layer, message queue resources are reused and message consumption efficiency is improved, which solves the problem of excessive resource consumption in the existing technology and improves the stability and efficiency of the message processing system.

CN114490112BActive Publication Date: 2024-09-20ALIBABA (CHINA) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111564807.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-20
Publication Date
2024-09-20
Estimated Expiration
2041-12-20

AI Technical Summary

Technical Problem

In the existing technology, each message queue is assigned a separate thread for message consumption, which leads to excessive computer resource consumption and makes it difficult to realize resource reuse.

Method used

Introduce multiple shared thread pools so that the message queue shares the thread pool resources in the thread pool, obtains messages from the storage node through the first thread pool and caches them in the local cache area, and uses the second thread pool to schedule messages to the cache queue according to the consumption speed of the cache queue. Message consumers realize thread resource reuse and improve message acquisition efficiency.

Benefits of technology

It reduces resource consumption when processing large-scale message queues, improves message consumption efficiency, and avoids resource waste and system stability effects caused by frequent access to storage nodes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114490112B
    Figure CN114490112B
Patent Text Reader

Abstract

The embodiments of the present application provide a message processing method, device and system. In the embodiments of the present application, multiple shared thread pools are introduced in the message consumption node, so that the message queues share the thread pool resources in the thread pool, and the threads in the thread pool are reused for the message queues without creating a separate thread for each message queue, which helps to reduce the resource consumption when processing large-scale message queues.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a message processing method, device and system. Background Art

[0002] Message Queue (MQ) is a middleware based on the first-in-first-out (FIFO) queue model. After the message is sent, it can be returned immediately, and the message system ensures the reliable delivery of the message. The message producer only needs to publish the message to MQ without worrying about who will get the message and how to get the message; the message consumer only needs to get the message from MQ without worrying about who published it and how to publish it.

[0003] For a message consumer, one message consumer needs to consume tens of thousands of MQs. In the prior art, it is often necessary to allocate a thread for each MQ to consume messages, and it is necessary to create and start a large number of consumption threads at the same time, consuming a large amount of computer resources. Summary of the invention

[0004] Multiple aspects of the present application provide a message processing method, device and system to achieve resource reuse and reduce computer resource consumption.

[0005] The present application provides a message processing method, including:

[0006] Obtaining messages from a storage node using a first thread pool according to a storage capacity of at least one cache queue in a local cache area;

[0007] Cache the acquired message to the cache queue corresponding to the local cache area;

[0008] According to the consumption speed carried by the at least one cache queue, using the second thread pool to obtain the target message that the message consumer needs to consume from the local cache area;

[0009] The target message is provided to a message consumer, so that the message consumer consumes the target message.

[0010] The embodiment of the present application also provides a message processing system, including: a storage node and a message consumption node;

[0011] The storage node is provided with at least one consumption queue; the consumption queue is used to store messages;

[0012] The message consumption node includes: a data pulling layer, a local cache layer, a message control layer and a message consumer; the local cache layer is provided with at least one cache queue;

[0013] The data pulling layer maintains a first thread pool, which is used to obtain messages from the at least one message queue using the first thread pool according to the storage capacity of the at least one cache queue; and cache the obtained messages to the at least one cache queue;

[0014] The consumption control layer maintains a second thread pool, which is used to obtain the target message that the message consumer needs to consume from the at least one cache queue using the second thread pool according to the consumption speed carried by the at least one cache queue; and dispatch the target message to the message consumer;

[0015] The message consumer is used to consume the target message.

[0016] The embodiment of the present application further provides a computing device, comprising: a memory and a processor; wherein the memory is used to store a computer program;

[0017] The processor is coupled to the memory and is configured to execute the computer program to perform the steps in the above message processing method.

[0018] In an embodiment of the present application, multiple shared thread pools are introduced in the message consumption node, so that the message queues share the thread pool resources in the thread pool, and the threads in the thread pool are reused for the message queues without creating a separate thread for each message queue, which helps to reduce resource consumption when processing large-scale message queues.

[0019] On the other hand, the message processing system provided by the embodiment of the present application sets a local cache layer at the message consumption node, which can realize the isolation of pulling messages from the storage node and message consumption. In this way, when the message consumption fails, the message can be rescheduled to the local cache layer to wait for consumption. When the next consumption occurs, the message can be directly obtained from the local cache layer without accessing the storage node, which helps to improve the efficiency of message acquisition and thus improve the efficiency of message consumption. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0021] Figure 1 A schematic diagram of the structure of a message processing system provided in an embodiment of the present application;

[0022] Figure 2 A schematic diagram of a thread pool provided in an embodiment of the present application;

[0023] Figure 3 and Figure 4 A schematic diagram of the structure of another message processing system provided in an embodiment of the present application;

[0024] Figure 5 A schematic diagram of time slicing of consumption speed provided in an embodiment of the present application;

[0025] Figure 6 A flowchart of a message processing method provided in an embodiment of the present application;

[0026] Figure 7 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.

[0028] In the prior art, it is often necessary to allocate a separate thread for each MQ to consume messages, and a large number of consumer threads need to be created and started at the same time, consuming a large amount of computer resources. In order to save computer resources, in some embodiments of the present application, multiple shared thread pools are introduced in the message consumption node, so that the message queues share the thread pool resources in the thread pool, and the threads in the thread pool are reused for the message queues without creating a separate thread for each message queue, which helps to reduce resource consumption when processing large-scale message queues.

[0029] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.

[0030] It should be noted that the same reference numerals denote the same objects in the following drawings and embodiments, and therefore, once an object is defined in one drawing or embodiment, it does not need to be further discussed in the subsequent drawings and embodiments.

[0031] Figure 1 This is a schematic diagram of the structure of the message processing system provided in the embodiment of the present application. Figure 1 As shown, the message processing system includes: a storage node 10 and a message consumption node 20.

[0032] In this embodiment, the storage node 10 refers to a service or physical device with a data storage function. The number of storage nodes 10 can be 1 or more. Multiple refers to 2 or more. Multiple storage nodes 10 can be deployed in different containers or virtual machines (VMs). Multiple storage nodes 10 can be deployed on the same physical machine or on different physical machines.

[0033] The message consumption node 20 refers to a software module, application, service or physical device with a message consumption function. The number of message consumption nodes 20 can be 1 or more. Multiple means 2 or more. Multiple message consumption nodes 20 can be deployed in different containers or virtual machines (VMs). Multiple message consumption nodes 20 can be deployed on the same physical machine or on different physical machines.

[0034] In the embodiments of the present application, the specific implementation form of the physical machine is not limited. The physical machine can be a single server device or a cloud server array. In addition, the physical machine can also refer to other computing devices with corresponding computing capabilities, such as computers and other terminal devices.

[0035] In an embodiment of the present application, the storage node 10 is provided with at least one message queue. In an embodiment of the present application, the number of message queues stored in the storage node 10 is not limited, and the message processing method provided in the embodiment of the present application can be adapted to any number of message queues, and is particularly suitable for multiple message queues. Multiple refers to 2 or more. In an embodiment of the present application, the specific number of message queues is not limited. For high concurrent requests, the message queues can be tens of thousands or even more. The message queue is used to store messages. The message processing system provided in the embodiment of the present application can be adapted to any application scenario requiring message processing. For example, it can be applied to a cloud communication service system, an order scheduling system, an online shopping system, and the like. For a cloud communication service system, the message generated by a message producer in a certain link is a text message, etc. For a cloud communication service system, multiple message queues can be created for each communication service supply platform. Accordingly, the storage node 10 is provided with multiple message queues. Accordingly, the message queue is used to store text messages. The message consumption node 20 is used to consume text messages, for example, to send text messages to corresponding users, and the like.

[0036] The message queue can be a queue model middleware based on first-in-first-out, which is used for message interaction between systems and can be persistently stored. Each message in the message queue has its unique offset in the message queue, indicating its current position in the message queue. The messages can be stored in order and continuously in the storage node 10 according to the offset, and the message consumption node 20 can obtain messages from the message queue in order according to the offset for consumption, thereby realizing a first-in-first-out message queue model.

[0037] In the embodiment of the present application, in order to realize resource reuse and save resource consumption of the message processing system, a thread pool can be maintained for the data pulling layer 21 of the message consumption node 20. The thread pool is a form of multi-threaded processing. During the processing, tasks are added to the queue and then automatically started after the thread is created. The thread pool has the advantages of convenient thread management and reduced memory consumption.

[0038] like Figure 2 As shown, the thread pool may include: a thread pool manager (Thread Pool Manager), a worker thread (Work Thread) and a task queue (Work Queue). Among them, the thread pool manager is used to create and manage the thread pool. The worker thread is a thread in the thread pool, which may include: a core thread and a non-core thread. The core thread will not be destroyed even when it is idle without executing any task. A non-core thread refers to a thread that is destroyed when the idle time reaches the set retention time threshold. The thread pool has parameters such as the maximum number of threads (maximum Pool Size), the number of core threads (core PoolSize) and the retention time (keep Alive Time). The maximum Pool Size refers to the maximum number of threads that can be accommodated in the thread pool; the core Pool Size is the number of core threads in the thread pool. The keep Alive Time is the longest time that a non-core thread in the thread pool can be retained when it is idle.

[0039] The task queue is a waiting queue used to store unprocessed tasks. The thread pool can process tasks in the task queue according to the FIFIO (first in, first out) principle.

[0040] Since the core queue maintained by the thread pool will not be destroyed when idle, when concurrent messages need to be processed, the thread pool does not need to create and start a large number of threads, which helps reduce resource consumption. In addition, large-scale message queues can reuse threads in the thread pool to achieve thread resource reuse, which helps further reduce resource consumption.

[0041] In the embodiment of the present application, the local cache layer 22 is provided with at least one cache queue. To facilitate message management, the cache queue of the local cache layer 22 corresponds to the message queue in the storage node 10. For example, one cache queue may correspond to one message queue, etc. There may also be multiple cache queues.

[0042] For a cache queue, there is a cache capacity, that is, the maximum number of messages that a cache queue can cache. The cache capacity of a cache queue is limited. Therefore, when the data pulling layer 21 pulls messages from the storage node 10, it needs to consider the storage capacity of the cache queue in the local cache layer 22, otherwise there will be a risk of message overflow. Therefore, the data pulling layer 21 can use the first thread pool to obtain messages from the storage node 10 according to the storage capacity of at least one cache queue in the local cache layer 22; and provide the obtained messages to the local cache layer 22. The local cache layer 22 caches the obtained messages in the corresponding cache queue.

[0043] In the embodiment of the present application, a task distribution thread can be started for the message pull layer 21, such as Figure 3 The message pull layer 21 can use the task distribution thread to generate a message pull task according to the storage capacity of at least one cache queue of the local cache layer 22; and provide the message pull task to the thread pool of the message pull layer 21.

[0044] Optionally, the task distribution thread may determine the number of messages that each cache queue can still accommodate based on the cache capacity and cache depth of each cache queue; and generate a message pull task corresponding to the cache queue based on the number of messages that each cache queue can still accommodate. Among them, the cache capacity of a cache queue refers to the maximum depth that the queue can store, that is, the maximum number of messages that can be accommodated. The cache depth of a cache queue refers to the depth of messages currently stored in the cache queue, which can reflect the number of messages currently stored. The message pull task may include a cache queue identifier and the number of messages that need to be pulled from the message queue corresponding to the cache queue. Among them, the number of messages that need to be pulled from the message queue corresponding to the cache queue is less than or equal to the number of messages that the cache queue can still accommodate.

[0045] For the message pulling layer 21, the thread pool of the layer can be used to execute the message pulling task to obtain the messages required for the message pulling task from the corresponding message queue of the storage node 10. Specifically, the message pulling layer 21 can use the thread pool to determine the message queue corresponding to the message task and the number of messages M to be pulled. M is a positive integer and is less than or equal to the number of messages that the cache queue can still accommodate. Further, the message pulling layer 21 can use the thread pool to pull M messages from the message queue corresponding to the storage node 10 as the messages required for the message pulling task.

[0046] Specifically, when the message pull layer 21 uses the thread pool to execute the message pull task, it can determine whether the core thread is in an idle state; if there is a core thread in an idle state, the idle core thread is used to execute the message pull task. If the core threads are all in a non-idle state, it can be determined whether the task queue has space to store the message pull task; if the judgment result is yes, the message pull task can be saved in the task queue. If the judgment result is that the task queue is full, it can be determined whether the number of threads currently used by the thread pool has reached the maximum number of threads of the thread pool. If not, a non-core thread can be created to execute the message pull task. If the number of threads currently used by the thread pool has reached the maximum number of threads of the thread pool, a rejection strategy is executed, etc.

[0047] In this embodiment, the message pull layer 21 can pull a certain amount of messages from the corresponding message queue of the storage node on demand according to the storage capacity of at least one cache queue in the local cache layer 22, which can avoid the overflow of the cache queue due to excessive number of pulled messages. The thread pool of the message pull layer 21 is used to execute the message pull task, and the message pull tasks corresponding to at least one message queue can share the thread pool to achieve thread resource reuse in the thread pool, which helps to reduce resource consumption when pulling messages.

[0048] The local cache layer 22 can cache the messages pulled by the message pull layer 21 to the corresponding cache queue. The message control layer 23 can control the consumption speed to achieve load balancing of at least one message queue. Specifically, the message control layer 23 can also maintain a thread pool. In the embodiment of the present application, for the convenience of description and distinction, the thread pool maintained by the above-mentioned data pull layer is defined as the first thread pool; the thread pool maintained by the message control layer 23 is defined as the second thread pool.

[0049] In this embodiment, the message control layer 23 can use the second thread pool to obtain the target message that the message consumer needs to consume from the local cache layer 22 according to the consumption speed carried by at least one cache queue, and dispatch the target message to the message consumer 24. The message consumer 24 can consume the target message.

[0050] In the embodiment of the present application, the consumption speed carried by the cache queue refers to the speed at which the messages in the cache queue are consumed, which can be measured by the query rate per second (qps). For example, if the consumption speed carried by the cache queue is 1000qps, it means that the consumption speed of the messages in the cache queue is 1000qps, that is, 1000 messages are consumed per second.

[0051] In this embodiment, according to the consumption speed carried by at least one cache queue, the target message is obtained from the cache queue on demand, so that the consumption speed of the cache queue can be controlled to achieve current limiting control.

[0052] Alternatively, if Figure 3 and Figure 4 As shown, the message control layer 23 can start the task scheduling thread, that is, Figure 3The cache task scheduler shown. The task scheduling thread generates multiple message scheduling tasks according to the consumption speed carried by at least one cache queue. Among them, the consumption task includes the number of messages to be obtained and the identifier of the cache queue. The identifier of the cache queue is used to identify which cache queue to obtain the message from. Further, the message control layer 23 can provide multiple consumption tasks to the message control layer 23. The message control layer 23 can use the second thread pool to periodically execute the consumption tasks corresponding to each cache queue according to the execution cycle corresponding to the message scheduling task; and in the process of executing the consumption task, obtain the message that needs to be scheduled by the message scheduling task executed in the current cycle from the cache queue as the target message.

[0053] Furthermore, the message control layer 23 may provide the target message to the message consumer. When the message control layer 23 schedules the target message to the message consumer 24, the target message may be randomly assigned to any message consumer; or a message consumer may be selected using a set scheduling method. For example, a hash ring algorithm may be used to determine the message consumer corresponding to the target message; and the target message may be provided to the determined message consumer 24.

[0054] The hash ring algorithm can be understood as follows: first, the value space of the Hash function is organized into a ring; then, the Hash function is used to hash the message consumer to obtain the position of the message consumer on the ring; and the Hash function is used to hash the target message to obtain the position of the target message on the ring; then, starting from the position of the target message on the ring, the first message consumer traversed is determined to be the message consumer corresponding to the target message.

[0055] Furthermore, the message control layer 23 may provide the target message to the determined message consumer 24. The message consumer 24 may consume the target message.

[0056] In the embodiment of the present application, the specific implementation method of the message consumer 24 consuming the target message is not limited. Figure 1 , Figure 3 and Figure 4 As shown, the message consumer 24 can maintain a thread pool. For ease of description and distinction, the thread pool maintained by the message consumer 24 is defined as the third thread pool. The third thread pool is used to process message consumption tasks. A message consumption task refers to a task that consumes a message.

[0057] In the embodiment of the present application, the message consumer 24 may utilize the third thread pool to process message consumption tasks to consume the target message.

[0058] In an embodiment of the present application, multiple shared thread pools are introduced in the message consumption node, so that the message queues share the thread pool resources in the thread pool, and the threads in the thread pool are reused for the message queues without creating a separate thread for each message queue, which helps to reduce resource consumption when processing large-scale message queues.

[0059] On the other hand, the message processing system provided by the embodiment of the present application sets a local cache layer at the message consumption node, which can realize the isolation of pulling messages from the storage node and message consumption. In this way, when the message consumption fails, the message can be rescheduled to the local cache layer to wait for consumption. When the next consumption occurs, the message can be directly obtained from the local cache layer without accessing the storage node, which helps to improve the efficiency of message acquisition and thus improve the efficiency of message consumption.

[0060] In the embodiments of the present application, Figure 4 As shown, considering that frequently obtaining messages from a message queue or a cache queue will generate a large number of input / output (I / O) operations, which has a certain impact on the stability of the message processing system, therefore, in an embodiment of the present application, any message queue can be split into multiple message sub-queues, and the message sub-queues jointly bear the consumption speed of the message queue. Correspondingly, any cache queue in the local cache layer 22 is also split into multiple cache sub-queues. The message sub-queues correspond to the cache sub-queues one by one.

[0061] Furthermore, different types of messages have different consumption priorities, and the higher the timeliness requirement, the higher the consumption priority of the message. For example, the timeliness requirement of instant messaging messages is higher than that of emails, so the consumption priority of instant messaging messages is higher than that of emails. In order to distinguish the consumption priorities of messages, in an embodiment of the present application, each message subqueue can store messages with the same consumption priority; of course, each cache subqueue also stores messages with the same consumption priority.

[0062] In the embodiment of the present application, in order to achieve load balancing of message consumption of the cache queue, multiple cache sub-queues can be divided into multiple sub-queue groups; each sub-queue group contains cache sub-queues of all consumption priorities. For example, if the consumption priority is divided into three priorities: high, medium and low, each sub-queue group contains three cache sub-queues with consumption priorities of high, medium and low. Figure 4 As shown, the message processing system may further include: a registration center node 30. The registration center node 30 refers to a software function module, service or physical device for managing message queues and cache queues. The registration center node 30 and the message consumption node 20 may be deployed on the same physical machine or on different physical machines.

[0063] In an embodiment of the present application, when dividing a cache queue into message sub-queues, for any cache queue, the registration center node 30 may divide the cache queue into multiple cache sub-queues according to the consumption speed carried by the cache queue, the consumption speed carried by the preset sub-queue group, and the number of message priorities. Among them, the number of cache sub-queues corresponding to the cache queue is determined by the consumption speed carried by the cache queue, the consumption speed carried by the preset sub-queue group, and the number of message priorities. For example, if the consumption speed carried by the cache queue is 1000pqs, the consumption speed carried by the preset sub-queue group is 50qps, and the consumption priority is three priorities of high, medium and low, then the number of sub-queue groups required is 20; since each sub-queue group contains cache sub-queues of three priorities of high, medium and low, the number of cache sub-queues can be 20*3=60.

[0064] In an embodiment of the present application, the subqueue group is the smallest consumption speed allocation unit, and the cache subqueues in the subqueue group share the consumption speed. Based on the above-mentioned cache subqueues, the message pull layer 21 can start the task distribution thread and generate multiple message pull tasks according to the storage capacity of multiple cache subqueues corresponding to at least one cache queue. Specifically, for any cache subqueue, the number of messages that the cache subqueue can still accommodate can be determined based on the cache capacity and cache depth of the cache subqueue; and based on the number of messages that each cache subqueue can still accommodate, a message pull task corresponding to the cache subqueue is generated. The message pull task may include the number of messages to be pulled M and the identifier of the message subqueue. Wherein, M is a positive integer and is less than or equal to the number of messages that the cache subqueue can still accommodate. The identifier of the message subqueue is used to identify which message subqueue in the storage node 10 to pull the message from.

[0065] Further, the task distribution thread may provide multiple message pull tasks to the first thread pool of the message pull layer 21. The message pull layer 21 may use the first thread pool to execute multiple message pull tasks; and in the process of executing the message pull tasks, obtain the messages required by the multiple message pull tasks respectively from the corresponding message subqueues of the storage node. Optionally, the message pull layer 21 may periodically use the first thread pool to execute message pull tasks according to the set pull cycle, so as to obtain the messages required by the message pull tasks executed in the current pull cycle from the corresponding message subqueues of the storage node. Among them, the corresponding message subqueue of the storage node is the message subqueue corresponding to the message subqueue identifier carried by the message pull task executed in the current cycle.

[0066] Furthermore, the message pulling layer 21 may provide the message pulled in the current cycle to the local cache layer 22. The local cache layer 22 may store the message in the cache subqueue corresponding to the message subqueue.

[0067] In actual use, there may be a situation where the message pulling layer cannot pull messages. For example, the message producer has no new messages, or all messages in the message subqueue are pulled, etc. Based on this, for any cache subqueue, if the number of consecutive messages required for the message pulling task corresponding to the cache subqueue is not obtained from the storage node 10 reaches the set threshold, the frequency of the first thread pool executing the message pulling task corresponding to the cache subqueue can be reduced. In this way, the frequency of invalid message pulling can be reduced, which helps to reduce resource consumption when pulling messages.

[0068] In the embodiment of the present application, the specific value of the consecutive times threshold is not limited. Preferably, the consecutive times threshold is an integer greater than 2, such as 3 times, 5 times, etc. Of course, in the embodiment of the present application, the specific implementation method of reducing the frequency of the first thread pool executing the message pull task corresponding to the cache subqueue is not limited. For example, according to the set gradient, each time the message required by the message pull task corresponding to the cache subqueue is not pulled, the frequency of executing the message pull task corresponding to the cache subqueue can be reduced by the set gradient in sequence. For another example, the frequency of executing the message pull task corresponding to the cache subqueue can be reduced to the set frequency, and so on.

[0069] In the embodiment of the present application, in order to ensure that messages are pulled in order according to the first-in-first-out principle, the message consumption node 20 can maintain a pull offset for each cache subqueue, indicating the maximum offset of the message that the cache subqueue has pulled from the storage node 10. Figure 3 As shown, a consumption progress management layer 25 can be set in the message consumption node 20, and the consumption progress management layer 25 can maintain the pull offset. Accordingly, for any cache sub-queue, when the message pulled from the storage node is cached in the cache sub-queue, the consumption progress management layer 25 can update the local pull offset according to the offset of the pulled message.

[0070] Based on the sub-queue groups corresponding to the above-mentioned cache queues, the message control layer 23 can use the second thread pool to obtain the target messages required by the message consumers from the local cache layer 22 according to the consumption speed carried by each sub-queue group. Specifically, the message control layer 23 can start a task distribution thread. The task distribution thread can generate multiple message scheduling tasks according to the consumption speeds carried by multiple sub-queue groups corresponding to each cache queue. Specifically, for any sub-queue group, according to the consumption speed of any sub-queue group, determine the number of messages N that need to be consumed by the sub-queue group at that time; N is a positive integer; and generate the message scheduling task corresponding to the sub-queue group according to the number of messages N that need to be consumed by the sub-queue group at that time. Among them, the message scheduling task may include the number of messages N that need to be consumed at that time and the identifier of the sub-queue group. Among them, the identifier of the sub-queue group is used to identify which sub-queue group to obtain the message from.

[0071] In the embodiment of the present application, when determining the number of messages N that need to be consumed by the subqueue group at a time according to the consumption speed of the subqueue group, the number of messages corresponding to the consumption speed of the subqueue group can be directly determined as the number of messages that need to be consumed by the subqueue group at a time. For example, if the consumption speed of the subqueue group is 50qps, the number of messages N that need to be consumed by the subqueue at a time is determined to be 50.

[0072] Since there are many cache sub-queue groups waiting for messages, and the cache sub-queue groups share the second thread pool, in order to ensure the consumption speed of each cache sub-queue group, when determining the number of messages N that need to be consumed by the sub-queue group this time according to the consumption speed of the sub-queue group, the consumption speed of any sub-queue group can be time-sliced ​​to obtain the number of messages that need to be consumed in each time slice; the number of messages that need to be consumed in each time slice is determined to be the number of messages that need to be consumed in the current time N. For example, Figure 5 As shown in the figure, if the consumption speed of the subqueue group is 50qps, then 0.2s can be used as a time slice to time slice the consumption speed of the subqueue group. Under this premise, the consumption task of the subqueue group per second is divided into 5 subtasks, and a subtask is executed every 0.2s, consuming 10 messages each time. That is, the number of messages that need to be consumed in each time slice is 10. In this way, the consumption speed of the subqueue group is controlled, and the message consumption speed per unit time can be guaranteed to be relatively stable, which helps to improve the consumption stability of the message processing system.

[0073] After generating the message scheduling tasks for each sub-queue group, the task distribution thread in the message control layer 23 can provide the message scheduling tasks to the second thread pool in the message control layer 23. Further, the message control layer 23 can use the second thread pool to periodically execute the message scheduling tasks corresponding to each sub-queue group according to the execution cycle corresponding to the message scheduling tasks; and in the process of executing the message scheduling tasks corresponding to each sub-queue group, obtain the messages required for the message scheduling tasks executed in the current cycle from the sub-queue group corresponding to the local cache layer 22 as the above-mentioned target messages. Among them, the execution cycle of the message scheduling task can be determined by the consumption speed of the sub-queue group. Each execution cycle obtains the number of messages corresponding to the message speed of the current execution cycle from the sub-queue group to achieve consumption speed control, which has a flow control effect.

[0074] In the embodiment of the present application, for the embodiment of directly determining the number of messages corresponding to the consumption speed of the sub-queue group, the execution cycle of the message control layer 23 to execute the message scheduling task is the time unit corresponding to the consumption speed. For example, if the consumption speed of the sub-queue group is 50qps, the execution cycle of the message control layer 23 to execute the message scheduling task is 1 second.

[0075] For the above-mentioned embodiment of time slicing the consumption speed of the sub-queue group, the execution cycle of the message control layer 23 executing the message scheduling task is one time slice. Accordingly, the message control layer 23 can use the second thread pool to periodically execute the message scheduling task corresponding to the sub-queue group with the time slice as the execution cycle. Since each time slice in the unit time shares the consumption speed, it is possible to control the consumption speed of the entire sub-queue group and stabilize the consumption speed of each time slice in the unit time, thereby ensuring that the message consumption speed in the unit time is relatively stable, which helps to improve the consumption stability of the message processing system.

[0076] In some embodiments, the cache subqueues in the subqueue group have consumption priorities. For the subqueue group whose cache subqueues have consumption priorities, N messages can be obtained from the subqueue group corresponding to the message scheduling task in descending order of the consumption priorities of the cache subqueues in the subqueue group as target messages of the subqueue group corresponding to the message scheduling task.

[0077] After the message control layer 23 obtains the target message matching the message speed from the local cache layer 22 according to the consumption speed of the subqueue group, the target message may be provided to the message consumer 24. The message consumer 24 may consume the target message.

[0078] In the embodiment of the present application, the specific implementation method of providing the target message to the message consumer 24 is not limited. In some embodiments, when the message control layer 23 dispatches the target message of each queue group to the message consumer 24, the target message of each sub-queue group may be randomly assigned to any message consumer; or the registration center node 30 may select the message consumer by using a set scheduling method. For example, Figure 4 As shown, the registration center node 30 may use a hash ring algorithm to determine the message consumers corresponding to the multiple sub-queue groups respectively; and provide the target message provided by each sub-queue group to the message consumer 24 corresponding to the sub-queue group.

[0079] The hash ring algorithm can be understood as follows: first, the value space of the Hash function is organized into a ring; then, each message consumer is hashed using the Hash function to obtain the positions of multiple message consumers on the ring; and each subqueue group is hashed using the Hash function to obtain the position of the subqueue group on the ring; then, starting from the position of the subqueue group on the ring, the first message consumer traversed is determined to be the message consumer corresponding to the subqueue group.

[0080] Furthermore, the message control layer 23 may provide the target message provided by each sub-queue group to the message consumer 24 corresponding to the sub-queue group. The message consumer corresponding to each sub-queue group consumes the target message provided by the sub-queue group.

[0081] In the embodiment of the present application, the specific implementation method of the message consumer 24 consuming the message is not limited. Figure 1 As shown, the message consumer 24 can maintain a thread pool. For ease of description and distinction, the thread pool maintained by the message consumer 24 is defined as the third thread pool. The third thread pool is used to process message consumption tasks. A message consumption task refers to a task that consumes a message.

[0082] In an embodiment of the present application, the message consumer 24 may utilize the third thread pool to process message consumption tasks to consume target messages. Specifically, the message consumer 24 may start a task dispatching thread. The task dispatching thread may generate a message consumption task. Optionally, the task dispatching thread may generate a message consumption task according to the execution cycle of the above-mentioned message scheduling task. A message consumption task executes a message obtained by a message scheduling task. Further, the task dispatching thread may provide the message consumption task to the third thread pool. Figure 3 As shown, the third thread pool can take out the message consumption task from the task queue as needed; and process the message consumption task to consume the target message corresponding to the message consumption task.

[0083] Optionally, in some embodiments, the third thread pool can be used to remotely call other processing units to process message consumption tasks; and when the message consumption task is completed, that is, when the target message corresponding to the message consumption task is consumed, a confirmation (ACK) message is issued.

[0084] In the embodiment of the present application, in order to ensure that messages are consumed in an orderly manner according to the first-in-first-out principle, the message consumption node 20 may also maintain a consumption offset for each cache subqueue, and the consumption offset may represent the maximum offset of messages in each cache subqueue that have been successfully consumed by the message consumer 24. The message offset may be maintained in the message progress management layer 25.

[0085] The message progress management layer 25 can monitor the consumption status of the target message by the message consumer; if the consumption status of the target message by the message consumer is successful, the local consumption offset corresponding to the cache subqueue where the target message is located can be updated according to the offset of the target message. Optionally, the message progress management layer 25 can also maintain a temporary list, and after the target message is consumed successfully, the offset of the target message can be stored in the temporary list; and the temporary list can be queried regularly. If an offset equal to the local consumption offset + 1 is found in the temporary list, the local consumption offset corresponding to the cache subqueue where the target message is located is increased by 1.

[0086] For the above-mentioned pull offset and message consumption offset maintained by the message consumption node 20, the above-mentioned pull offset and message consumption offset can be regularly persisted to the storage node 10 to prevent the pull offset and message consumption offset from being lost.

[0087] When the message progress management layer 25 detects that the consumption status of the target message by the message consumer is consumption failure, the target message can be rescheduled to the cache subqueue corresponding to the local cache layer 22. The cache subqueue corresponding to the local cache layer 22 refers to the cache subqueue where the target message is located. In this way, the target message can wait to be consumed again in the cache subqueue without having to go to the storage node 10 to pull the target message again, which can improve the message acquisition efficiency when the message is consumed again, thereby improving the message consumption efficiency.

[0088] In addition to the message processing system provided in the above embodiment, the embodiment of the present application also provides a message processing method. The message processing method provided in the embodiment of the present application is exemplarily described below.

[0089] Figure 6 The following is a flow chart of a message processing method provided in an embodiment of the present application. Figure 6 As shown, the message processing method includes:

[0090] 601. According to the storage capacity of at least one cache queue in the local cache area, use a first thread pool to obtain a message from a storage node.

[0091] 602. Cache the acquired message into a cache queue corresponding to the local cache area.

[0092] 603. According to the consumption speed carried by at least one cache queue, use the second thread pool to obtain the target message that the message consumer needs to consume from the local cache area.

[0093] 604. Provide the target message to the message consumer so that the message consumer consumes the target message.

[0094] In an embodiment of the present application, in an embodiment of the present application, a storage node is provided with at least one message queue. Generally, the number of message queues is multiple. Each message in the message queue has its unique offset in the message queue, indicating its current position in the message queue. Messages can be stored in the message queue in an orderly and continuous manner according to the offset, and messages can be obtained from the message queue in an orderly manner according to the offset for consumption, thereby realizing a first-in-first-out message queue model.

[0095] In an embodiment of the present application, the local cache area is provided with at least one cache queue. To facilitate message management, the cache queue of the local cache area corresponds to the message queue in the storage node. For example, one cache queue may correspond to one message queue, etc.

[0096] For a cache queue, there is a cache capacity, that is, the maximum number of messages that a cache queue can cache. The cache capacity of a cache queue is limited. Therefore, when a storage node pulls a message, it is necessary to consider the storage capacity of the cache queue in the local storage area, otherwise there will be a risk of message overflow. Therefore, in step 601, the first thread pool can be used to obtain messages from the storage node based on the storage capacity of at least one cache queue in the local cache area; and in step 602, the obtained message is cached to the cache queue corresponding to the local cache area.

[0097] In an embodiment of the present application, a message pulling task may be generated according to the storage capacity of at least one cache queue of a local cache area; and the message pulling task may be provided to a thread pool of a message pulling layer.

[0098] Optionally, the number of messages that each cache queue can still accommodate can be determined based on the cache capacity and cache depth of each cache queue; and based on the number of messages that each cache queue can still accommodate, a message pull task corresponding to the cache queue is generated. Among them, the description of the cache capacity and cache depth can be found in the relevant content of the above-mentioned system embodiment, which will not be repeated here. The message pull task may include a cache queue identifier and the number of messages to be pulled from the message queue corresponding to the cache queue. Among them, the number of messages to be pulled from the message queue corresponding to the cache queue is less than or equal to the number of messages that the cache queue can still accommodate.

[0099] Further, the first thread pool can be used to execute the message pulling task to obtain the messages required for the message pulling task from the corresponding message queue of the storage node. Specifically, the first thread pool can be used to determine the message queue corresponding to the message task and the number of messages M to be pulled. M is a positive integer and is less than or equal to the number of messages that the cache queue can still accommodate. Further, the first thread pool can be used to pull M messages from the message queue corresponding to the storage node as the messages required for the message pulling task. For the specific implementation method of executing the message pulling task using the first thread pool, please refer to the relevant content of the above-mentioned system embodiment, which will not be repeated here.

[0100] In this embodiment, according to the storage capacity of at least one cache queue in the local cache layer, a certain amount of messages are pulled from the corresponding message queue of the storage node on demand, which can avoid the overflow of the cache queue due to excessive number of pulled messages. The message pulling task is executed by using a thread pool, and the message pulling tasks corresponding to at least one message queue can share the thread pool to realize thread resource reuse in the thread pool, which helps to reduce resource consumption when pulling messages.

[0101] Furthermore, the consumption speed of the cache queue can be controlled to achieve load balancing of at least one message queue. Accordingly, in step 603, the second thread pool can be used to obtain the target message that the message consumer needs to consume from the local cache area according to the consumption speed carried by at least one cache queue; and in step 604, the target message is provided to the message consumer. The message consumer can consume the target message.

[0102] In this embodiment, according to the consumption speed carried by at least one cache queue, the target message is obtained from the cache queue on demand, so that the consumption speed of the cache queue can be controlled to achieve current limiting control.

[0103] Optionally, multiple message scheduling tasks can be generated according to the consumption speed carried by at least one cache queue. The consumption task includes the number of messages to be obtained and the identifier of the cache queue. The identifier of the cache queue is used to identify which cache queue to obtain the message from. Furthermore, the second thread pool can be used to periodically execute the consumption task corresponding to each cache queue according to the execution cycle corresponding to the message scheduling task; and in the process of executing the consumption task, the message that needs to be scheduled by the message scheduling task executed in the current cycle is obtained from the cache queue as the target message.

[0104] Furthermore, the target message may be provided to a message consumer. Optionally, the target message may be randomly assigned to any message consumer; or a message consumer may be selected using a set scheduling method. For example, a hash ring algorithm may be used to determine the message consumer corresponding to the target message; and the target message may be provided to the determined message consumer, and so on.

[0105] Further, the target message may be provided to the determined message consumer. The message consumer may consume the target message. Optionally, a third thread pool may be used to process the message consumption task to consume the target message.

[0106] In an embodiment of the present application, multiple shared thread pools are introduced in the message consumption node, so that the message queues share the thread pool resources in the thread pool, and the threads in the thread pool are reused for the message queues without creating a separate thread for each message queue, which helps to reduce resource consumption when processing large-scale message queues.

[0107] On the other hand, the message processing system provided by the embodiment of the present application sets a local cache layer at the message consumption node, which can realize the isolation of pulling messages from the storage node and message consumption. In this way, when the message consumption fails, the message can be rescheduled to the local cache layer to wait for consumption. When the next consumption occurs, the message can be directly obtained from the local cache layer without accessing the storage node, which helps to improve the efficiency of message acquisition and thus improve the efficiency of message consumption.

[0108] In the embodiment of the present application, considering that frequently obtaining messages from a message queue or a cache queue will generate a large number of input / output (I / O) operations, which has a certain impact on the stability of the message processing system, therefore, in the embodiment of the present application, for any cache queue, the cache queue can be divided into multiple cache sub-queues according to the consumption speed carried by the cache queue, the consumption speed carried by the preset sub-queue group, and the number of message priorities. Among them, the number of cache sub-queues corresponding to the cache queue is determined by the consumption speed carried by the cache queue, the consumption speed carried by the preset sub-queue group, and the number of message priorities.

[0109] In an embodiment of the present application, the subqueue group is the smallest consumption speed allocation unit, and the cache subqueues in the subqueue group share the consumption speed. Based on the above-mentioned cache subqueues, multiple message pull tasks can be generated according to the storage capacity of multiple cache subqueues corresponding to at least one cache queue. Specifically, for any cache subqueue, the number of messages that the cache subqueue can still accommodate can be determined based on the cache capacity and cache depth of the cache subqueue; and based on the number of messages that each cache subqueue can still accommodate, a message pull task corresponding to the cache subqueue is generated. The message pull task may include the number of messages M to be pulled and the identifier of the message subqueue. Wherein, M is a positive integer and is less than or equal to the number of messages that the cache subqueue can still accommodate. The identifier of the message subqueue is used to identify which message subqueue in the storage node to pull the message from.

[0110] Furthermore, multiple message pull tasks can be provided to the first thread pool; and the first thread pool is used to execute multiple message pull tasks; and in the process of executing the message pull tasks, the messages required by the multiple message pull tasks are obtained from the corresponding message subqueues of the storage node. Optionally, according to the set pull cycle, the first thread pool can be used periodically to execute the message pull tasks to obtain the messages required by the message pull tasks executed in the current pull cycle from the corresponding message subqueues of the storage node. Among them, the corresponding message subqueue of the storage node is the message subqueue corresponding to the message subqueue identifier carried by the message pull tasks executed in the current cycle.

[0111] Furthermore, the message pulled in the current cycle can be provided to the local cache layer area. The local cache area can store the message in the cache subqueue corresponding to the message subqueue.

[0112] In actual use, there may be a situation where the message pulling layer cannot pull messages. For example, the message producer has no new messages, or all messages in the message subqueue have been pulled, etc. Based on this, for any cache subqueue, if the number of consecutive messages required for the message pulling task corresponding to the cache subqueue is not obtained from the storage node reaches the set threshold, the frequency of the first thread pool executing the message pulling task corresponding to the cache subqueue can be reduced. In this way, the frequency of invalid message pulling can be reduced, which helps to reduce resource consumption when pulling messages.

[0113] In the embodiment of the present application, in order to ensure that messages are pulled in order according to the first-in-first-out principle, a pull offset may be maintained for each cache subqueue, indicating the maximum offset of the message that the cache subqueue has pulled from the storage node. Accordingly, for any cache subqueue, when the message pulled from the storage node is cached to the cache subqueue, the local pull offset may be updated according to the offset of the pulled message.

[0114] Based on the sub-queue groups corresponding to the above-mentioned cache queues, the second thread pool can be used to obtain the target messages required by the message consumer from the local cache area according to the consumption speed carried by each sub-queue group. Optionally, multiple message scheduling tasks can be generated according to the consumption speeds carried by multiple sub-queue groups corresponding to at least one cache queue. Specifically, for any sub-queue group, according to the consumption speed of any sub-queue group, the number of messages N that need to be consumed by the sub-queue group at that time is determined; N is a positive integer; and according to the number of messages N that need to be consumed by the sub-queue group at that time, the message scheduling task corresponding to the sub-queue group is generated. Among them, the message scheduling task may include the number of messages N that need to be consumed at that time and the identifier of the sub-queue group. Among them, the identifier of the sub-queue group is used to identify which sub-queue group to obtain the message from.

[0115] In an embodiment of the present application, when determining the number N of messages that need to be consumed by the sub-queue group at a time based on the consumption speed of the sub-queue group, the number of messages corresponding to the consumption speed of the sub-queue group can be directly determined as the number of messages that need to be consumed by the sub-queue group at a time.

[0116] Since there are many cache sub-queue groups waiting for messages, and the cache sub-queue groups share the second thread pool, in order to ensure the consumption speed of each cache sub-queue group, when the number of messages N that need to be consumed by the sub-queue group is determined according to the consumption speed of the sub-queue group, the consumption speed of any sub-queue group can be time-sliced ​​to obtain the number of messages that need to be consumed in each time slice; the number of messages that need to be consumed in each time slice is determined to be the number of messages that need to be consumed in the current time N. In this way, the consumption speed of the sub-queue group is controlled, and the message consumption speed within a unit time can be guaranteed to be relatively stable, which helps to improve the consumption stability of the message processing system.

[0117] Furthermore, the second thread pool can be used to periodically execute the message scheduling task corresponding to each sub-queue group according to the execution cycle corresponding to the message scheduling task; and in the process of executing the message scheduling task corresponding to each sub-queue group, the message required for the message scheduling task executed in the current cycle is obtained from the sub-queue group corresponding to the local cache area as the above-mentioned target message. Among them, the execution cycle of the message scheduling task can be determined by the consumption speed of the sub-queue group, and each execution cycle obtains the number of messages corresponding to the message speed of the current execution cycle from the sub-queue group to realize consumption speed control, which has a flow control effect.

[0118] In the embodiment of the present application, for the embodiment of directly determining the number of messages corresponding to the consumption speed of the sub-queue group, the execution cycle of the message scheduling task is the time unit corresponding to the consumption speed.

[0119] For the above-mentioned embodiment of time slicing the consumption speed of the sub-queue group, the execution cycle of executing the message scheduling task is one time slice. Accordingly, the second thread pool can be used to periodically execute the message scheduling task corresponding to the sub-queue group with the time slice as the execution cycle. Since each time slice in the unit time shares the consumption speed, the consumption speed of the entire sub-queue group can be controlled, and the consumption speed of each time slice in the unit time can be stabilized, thereby ensuring that the message consumption speed in the unit time is relatively stable, which helps to improve the consumption stability of the message processing system.

[0120] In some embodiments, the cache subqueues in the subqueue group have consumption priorities. For the subqueue group whose cache subqueues have consumption priorities, N messages can be obtained from the subqueue group corresponding to the message scheduling task in descending order of the consumption priorities of the cache subqueues in the subqueue group as target messages of the subqueue group corresponding to the message scheduling task.

[0121] After obtaining the target message matching the message speed from the local cache area, the target message can be provided to the message consumer, and the message consumer can consume the target message.

[0122] In the embodiments of the present application, the specific implementation method of providing the target message to the message consumer is not limited. In some embodiments, the target message of each sub-queue group can be randomly assigned to any message consumer; or the message consumer can be selected by a set scheduling method. For example, a hash ring algorithm can be used to determine the message consumers corresponding to multiple sub-queue groups; and the target message provided by each sub-queue group is provided to the message consumer corresponding to the sub-queue group.

[0123] Further, the target message provided by each sub-queue group can be provided to the message consumer corresponding to the sub-queue group. The message consumer corresponding to each sub-queue group consumes the target message provided by the sub-queue group. For the specific implementation method of message consumer consuming messages, please refer to the relevant content of the above system embodiment, which will not be repeated here.

[0124] In an embodiment of the present application, in order to ensure that messages are consumed in order according to the first-in-first-out principle, a consumption offset can also be maintained for each cache sub-queue, and the consumption offset can represent the maximum offset of messages in each cache sub-queue that have been successfully consumed by the message consumer.

[0125] Accordingly, the consumption status of the target message by the message consumer can be monitored; if the consumption status of the target message by the message consumer is successful, the local consumption offset corresponding to the cache subqueue where the target message is located can be updated according to the offset of the target message. Optionally, a temporary list can also be maintained, and after the target message is consumed successfully, the offset of the target message can be stored in the temporary list; and the temporary list can be queried regularly. If an offset equal to the local consumption offset + 1 is found in the temporary list, the local consumption offset corresponding to the cache subqueue where the target message is located is increased by 1.

[0126] For the maintained pull offset and message consumption offset, the pull offset and message consumption offset can be persisted to the storage node regularly to prevent the pull offset and message consumption offset from being lost.

[0127] If it is detected that the consumption status of the target message by the message consumer is consumption failure, the target message can be rescheduled to the cache subqueue corresponding to the local cache area. The cache subqueue corresponding to the local cache area refers to the cache subqueue where the target message is located. In this way, the target message can wait to be consumed again in the cache subqueue without having to go to the storage node to pull the target message again, which can improve the message acquisition efficiency when consuming the message again, thereby improving the message consumption efficiency.

[0128] It should be noted that the execution subject of each step of the method provided in the above embodiment can be the same device, or the method can be executed by different devices. For example, the execution subject of steps 601 and 602 can be device A; for another example, the execution subject of step 601 can be device A, and the execution subject of step 602 can be device B; and so on.

[0129] In addition, in some of the processes described in the above embodiments and the accompanying drawings, multiple operations appearing in a specific order are included, but it should be clearly understood that these operations may not be executed in the order in which they appear in this document or may be executed in parallel, and the sequence numbers of the operations, such as 603, 604, etc., are only used to distinguish between different operations, and the sequence numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed in sequence or in parallel.

[0130] Accordingly, an embodiment of the present application also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed by one or more processors, the one or more processors are caused to execute the steps in the above-mentioned message processing method.

[0131] The embodiment of the present application also provides a computer program product, which includes: a computer program. When the computer program is executed by a processor, the processor executes the steps in the above-mentioned message processing method. In the embodiment of the present application, the implementation form of the computer program product is not limited. In some embodiments, the computer program product can be implemented as a message queue middleware, a plug-in, etc.

[0132] Figure 7 This is a schematic diagram of the structure of a computing device provided in an embodiment of the present application. Figure 7 As shown, the computing device includes: a memory 70a and a processor 70b. The memory 70a is used to store computer programs.

[0133] The processor 70b is coupled to the memory 70a, and is used to execute a computer program for: obtaining messages from a storage node using a first thread pool according to the storage capacity of at least one cache queue in a local cache area; caching the obtained messages into a cache queue corresponding to the local cache area; obtaining target messages that a message consumer needs to consume from the local cache area using a second thread pool according to a consumption speed carried by at least one cache queue; and providing the target messages to message consumers so that the message consumers can consume the target messages.

[0134] Wherein, at least one message queue in the storage node corresponds to at least one cache queue. Accordingly, when the processor 70b uses the first thread pool to obtain a message from the remote storage node, it is specifically used to: generate a message pull task according to the storage capacity of at least one cache queue in the local cache area; and use the first thread pool to execute the message pull task to obtain the message required by the message pull task from the corresponding message queue of the storage node.

[0135] Furthermore, when generating a message pull task, the processor 70b is specifically used to: determine the number of messages that can be accommodated in each cache queue according to the cache capacity and cache depth of each cache queue; and generate a message pull task corresponding to the cache queue according to the number of messages that can be accommodated in each cache queue.

[0136] Optionally, when the processor 70b uses the first thread pool to execute the message pulling task, it is specifically used to: use the first thread pool to determine the message queue corresponding to the message pulling task and the number of messages M to be pulled; M is a positive integer; pull M messages from the message queue corresponding to the remote storage node as the messages required for the message pulling task.

[0137] In some embodiments, the processor 70b is also used to: for any cache queue, divide any cache queue into multiple cache sub-queues according to the consumption speed carried by any cache queue, the consumption speed carried by a preset sub-queue group, and the number of consumption priorities; the same cache sub-queue is used to cache messages with the same consumption priority; and divide the multiple cache sub-queues into multiple sub-queue groups according to the consumption priorities corresponding to the multiple cache sub-queue groups; wherein each sub-queue group contains cache sub-queues of all consumption priorities.

[0138] The multiple message subqueues in the storage node correspond to the multiple cache subqueues. Accordingly, when the processor 70b uses the first thread pool to obtain messages from the storage node, it is specifically used to: generate multiple message pull tasks according to the storage capacity of the multiple cache subqueues corresponding to the at least one cache queue; use the first thread pool to execute the multiple message pull tasks to obtain the messages required by the multiple message pull tasks from the corresponding message subqueues of the storage node.

[0139] Optionally, processor 70b is also used to: for any cache sub-queue, if the consecutive number of messages required for the message pulling task corresponding to any cache sub-queue not being obtained from the remote storage node reaches a set threshold, reduce the frequency of the first thread pool executing the message pulling task corresponding to any cache sub-queue.

[0140] Optionally, the processor 70b is also used to: for any cache sub-queue, when obtaining the message required by the message pulling task corresponding to any cache sub-queue from the remote storage node, update the local pull offset according to the offset of the message required by the message pulling task corresponding to any cache sub-queue. In some embodiments, when the processor 70b uses the second thread pool to obtain the target message that the message consumer needs to consume from the local cache area, it is specifically used to: generate multiple message scheduling tasks according to the consumption speed carried by the sub-queue groups corresponding to at least one cache queue; use the second thread pool to periodically execute the message scheduling task corresponding to each sub-queue group according to the execution cycle corresponding to the message scheduling task; and in the process of executing the message scheduling task corresponding to each sub-queue group, obtain the message required for the message scheduling task executed in the current cycle from the sub-queue group corresponding to the local buffer as the target message.

[0141] Further, when the processor 70b generates multiple message scheduling tasks, it is specifically used to: for any sub-queue group, determine the number of messages N that need to be consumed by any sub-queue group at that time according to the consumption speed of any sub-queue group; N is a positive integer; and generate a message scheduling task corresponding to any sub-queue group according to the number of messages N that need to be consumed by any sub-queue group at that time.

[0142] Optionally, when determining the number of messages N that need to be consumed by any sub-queue group at the time, the processor 70b is specifically used to: time slice the consumption speed of any sub-queue group to obtain the number of messages that need to be consumed in each time slice; determine the number of messages that need to be consumed in each time slice as the number of messages N that need to be consumed currently.

[0143] Correspondingly, when executing the consumption task corresponding to each sub-queue group, the processor 70b is specifically configured to: utilize the second thread pool to periodically execute the consumption task corresponding to any sub-queue group with time slicing as the execution cycle.

[0144] Optionally, when the processor 70b obtains messages required by multiple message scheduling tasks from the cache sub-queue group corresponding to the local cache area, it is specifically used to: for the sub-queue group corresponding to any message scheduling task, obtain N messages from the sub-queue group corresponding to any message scheduling task in order of consumption priority of the cache sub-queues in the sub-queue group from high to low, as target messages of the sub-queue group corresponding to any message scheduling task.

[0145] In other embodiments, when providing the target message to the message consumer, the processor 70b is specifically used to: use a hash ring algorithm to determine the message consumers corresponding to multiple sub-queue groups; provide the target message provided by each sub-queue group to the message consumer corresponding to the sub-queue group, so that the message consumer corresponding to each sub-queue group consumes the target message provided by the sub-queue group.

[0146] In some other embodiments, the processor 70b is also used to: monitor the consumption status of the target message by the message consumer; if the consumption status of the target message by the message consumer is successful, update the local consumption offset according to the offset of the target message; accordingly, if the consumption status of the target message by the message consumer is failed, reschedule the target message to the cache sub-queue corresponding to the local cache area.

[0147] In some optional embodiments, such as Figure 7 As shown, the computing device may also include: a communication component 70c, a power supply component 70d and other components. Figure 7 The components are shown schematically only and do not necessarily include Figure 7 The components shown do not necessarily mean that the computing device can only include Figure 7 Components shown.

[0148] The computing device provided in this embodiment can be implemented as a message consumption node, introducing multiple shared thread pools, so that message queues share thread pool resources in the thread pool, and realize the reuse of threads in the thread pool for message queues without creating a separate thread for each message queue, which helps to reduce resource consumption when processing large-scale message queues.

[0149] On the other hand, the computing device sets up a local cache area to isolate the pulling of messages from the storage node from the message consumption. In this way, when the message consumption fails, the message can be rescheduled to the local cache layer to wait for consumption. When it is consumed next time, the message can be obtained directly from the local cache layer without accessing the storage node again, which helps to improve the efficiency of message acquisition and thus improve the efficiency of message consumption.

[0150] In an embodiment of the present application, the memory is used to store a computer program and can be configured to store various other data to support operations on the device where it is located. Among them, the processor can execute the computer program stored in the memory to implement the corresponding control logic. The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0151] In the embodiment of the present application, the processor can be any hardware processing device that can execute the logic of the above method. Optionally, the processor can be a central processing unit (CPU), a graphics processing unit (GPU) or a microcontroller unit (MCU); it can also be a field programmable gate array (FPGA), a programmable array logic device (PAL), a general array logic device (GAL), a complex programmable logic device (CPLD) and other programmable devices; or an advanced reduced instruction set (RISC) processor (Advanced RISC Machines, ARM) or a system on chip (System on Chip, SOC), etc., but not limited to this.

[0152] In an embodiment of the present application, the communication component is configured to facilitate wired or wireless communication between the device in which it is located and other devices. The device in which the communication component is located can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, 4G, 5G or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component can also be implemented based on near field communication (NFC) technology, radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology or other technologies.

[0153] In an embodiment of the present application, a power supply component is configured to provide power to various components of the device in which it is located. The power supply component may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device in which the power supply component is located.

[0154] It should be noted that the descriptions such as “first” and “second” in this article are used to distinguish different messages, devices, modules, etc., and do not represent the order of precedence, nor do they limit “first” and “second” to different types.

[0155] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0156] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0157] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0158] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0159] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0160] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0161] The storage medium of a computer is a readable storage medium, which may also be referred to as a readable medium. The readable storage medium includes permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. The information can be computer-readable instructions, data structures, modules of programs or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0162] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0163] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims

1. A message processing method, characterized in that: include: Obtaining messages from a storage node using a first thread pool according to a storage capacity of at least one cache queue in a local cache area; Cache the acquired message to the cache queue corresponding to the local cache area; According to the consumption speed carried by the at least one cache queue, using the second thread pool to obtain the target message that the message consumer needs to consume from the local cache area; Providing the target message to a message consumer so that the message consumer consumes the target message; For any cache queue in the at least one cache queue, the any cache queue is divided into at least one cache sub-queue according to the consumption speed carried by the any cache queue, the consumption speed carried by the preset sub-queue group, and the number of consumption priorities; the same cache sub-queue is used to cache messages with the same consumption priority; According to the consumption priority corresponding to the at least one cache sub-queue group, the at least one cache sub-queue is divided into at least one sub-queue group; wherein each sub-queue group contains cache sub-queues of all consumption priorities.

2. The method according to claim 1, characterized in that At least one message subqueue in the storage node corresponds to the at least one cache subqueue; The method of obtaining a message from a storage node by using a first thread pool according to the storage capacity of at least one cache queue in the local cache area includes: generating at least one message pulling task according to the storage capacity of at least one cache sub-queue respectively corresponding to the at least one cache queue; The at least one message pulling task is executed by using the first thread pool to obtain messages respectively required by the at least one message pulling task from the corresponding message subqueue of the storage node.

3. The method according to claim 2, characterized in that Also includes: For any cache sub-queue, if the consecutive number of times that the message required for the message pulling task corresponding to any cache sub-queue is not obtained from the storage node reaches a set threshold, the frequency of the first thread pool executing the message pulling task corresponding to any cache sub-queue is reduced.

4. The method according to claim 1, characterized in that: The method of obtaining a target message that a message consumer needs to consume from the local cache area by using a second thread pool according to a consumption speed carried by the at least one cache queue includes: Generate multiple message scheduling tasks according to the consumption speeds carried by the sub-queue groups respectively corresponding to the at least one cache queue; Using the second thread pool to periodically execute the message scheduling task corresponding to each sub-queue group according to the execution cycle corresponding to the message scheduling task; In the process of executing the message scheduling task corresponding to each sub-queue group, the message required for the message scheduling task executed in the current period is obtained from the sub-queue group corresponding to the local cache area as the target message.

5. The method according to claim 4, characterized in that The generating a plurality of message scheduling tasks according to the consumption speeds carried by the sub-queue groups respectively corresponding to the at least one cache queue includes: For any sub-queue group, according to the consumption speed of any sub-queue group, determine the number of messages N that need to be consumed by any sub-queue group at that time; N is a positive integer; According to the number N of messages that need to be consumed by any sub-queue group at that time, a message scheduling task corresponding to any sub-queue group is generated.

6. The method according to claim 5, characterized in that The determining, for any sub-queue group, according to the consumption speed of any sub-queue group, the number of messages N that need to be consumed by any sub-queue group at that time includes: Perform time slicing on the consumption speed of any sub-queue group to obtain the number of messages that need to be consumed in each time slice; Determine the number of messages that need to be consumed in each time slice as the number of messages N that need to be consumed currently.

7. The method according to claim 6, characterized in that The using the second thread pool to periodically execute the consumption task corresponding to each sub-queue group according to the execution cycle corresponding to the consumption task includes: The second thread pool is used to periodically execute the consumption task corresponding to any sub-queue group using the time slice as the execution cycle.

8. The method according to claim 5, characterized in that The acquiring the messages required by the plurality of message scheduling tasks from the cache sub-queue group corresponding to the local cache area includes: For the subqueue group corresponding to any message scheduling task, N messages are obtained from the subqueue group corresponding to any message scheduling task in descending order of the consumption priority of the cache subqueues in the subqueue group as the target messages of the subqueue group corresponding to any message scheduling task.

9. The method according to any one of claims 1 to 8, characterized in that: Providing the target message to a message consumer so that the message consumer consumes the target message includes: Using a hash ring algorithm to determine a message consumer corresponding to the at least one subqueue group; The target message provided by each sub-queue group is provided to a message consumer corresponding to the sub-queue group, so that the message consumer corresponding to each sub-queue group consumes the target message provided by the sub-queue group.

10. The method according to any one of claims 1 to 8, characterized in that: Also includes: Monitoring the consumption status of the target message by the message consumer; If the consumption status of the target message by the message consumer is successful, the local consumption offset is updated according to the offset of the target message.

11. The method according to claim 10, characterized in that Also includes: If the consumption status of the target message by the message consumer is consumption failure, the target message is rescheduled to the cache subqueue corresponding to the local cache area.

12. A message processing system, characterized in that: include: Storage nodes and message consumption nodes; The storage node is provided with at least one consumption queue; The consumer queue is used to store messages; The message consumption node includes: a data pulling layer, a local cache layer, a message control layer and a message consumer; the local cache layer is provided with at least one cache queue, and for any cache queue in the at least one cache queue, the any cache queue is divided into at least one cache sub-queue according to the consumption speed carried by the any cache queue, the consumption speed carried by the preset sub-queue group and the number of consumption priorities; the same cache sub-queue is used to cache messages with the same consumption priority; according to the consumption priority corresponding to the at least one cache sub-queue group, the at least one cache sub-queue is divided into at least one sub-queue group; wherein each sub-queue group contains cache sub-queues of all consumption priorities; The data pulling layer maintains a first thread pool, which is used to obtain messages from the at least one message queue using the first thread pool according to the storage capacity of the at least one cache queue; and cache the obtained messages to the at least one cache queue; The message control layer maintains a second thread pool, which is used to obtain the target message that the message consumer needs to consume from the at least one cache queue using the second thread pool according to the consumption speed carried by the at least one cache queue; and dispatch the target message to the message consumer; The message consumer is used to consume the target message.

13. A computing device, characterized in that: include: A memory and a processor; wherein the memory is used to store a computer program; The processor is coupled to the memory and configured to execute the computer program to perform the steps of the method according to any one of claims 1 to 11.