A message pushing method and system based on multiple queues
By dynamically adjusting the number of consumers in the priority queue, the problem of server resource waste in message push services is solved, achieving more efficient resource utilization and message push stability.
Patent Information
- Application Number
- CN202411715693.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2044-11-27
AI Technical Summary
Existing push notification services struggle to fully utilize server resources when faced with an increase in user volume, leading to resource waste.
By using a multi-queue-based message push method, the number of consumers in the priority queue is dynamically adjusted, and the message push processing time and timeout latency information are monitored according to the actual situation. The number of consumers is automatically adjusted to optimize resource utilization.
This allows for more efficient use of server resources, reduces the risk of resource waste due to a fixed number of consumers, and improves the timeliness and stability of message push.
Smart Images

Figure CN119544781B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a message pushing method and system based on multiple queues. BACKGROUND
[0002] With the development of computer software technology and information technology, more and more enterprises use message pushing services to push various messages to corresponding users, such as pushing consumption, advertising or information messages. Different types of message users can accept different time delays, such as consumption account information, verification code and other information, the shorter the time delay is, the better, while the time delay of advertising and information messages can be longer.
[0003] At present, message pushing services push various messages through a fixed number of consumers. However, as the number of users continues to increase, the amount of upstream system messages continues to increase, and the server resources required by the message pushing service also increase, making it difficult to fully utilize server resources. SUMMARY
[0004] The present application provides a message pushing method and system based on multiple queues, which dynamically adjusts the number of consumer priority queues according to actual conditions, thereby more fully utilizing server resources. The technical solution is as follows.
[0005] In a first aspect, a message pushing method based on multiple queues is provided, the method comprising:
[0006] receiving a pushing request, the pushing request indicating pushing a message to a client;
[0007] adding a request timestamp to the message, adding the message to a target queue in multiple priority queues matched with the priority of the message based on the priority of the message, the request timestamp indicating a time point of receiving the pushing request;
[0008] consuming the message in the target queue by a consumer, and pushing the message to the client;
[0009] recording a processing completion timestamp of the message, the processing completion timestamp indicating a time point of completing the message pushing;
[0010] obtaining an actual pushing processing time of the message based on the request timestamp saved in the message and the message processing completion timestamp of the message, the actual pushing processing time being a time difference between the request timestamp and the message processing completion timestamp;
[0011] if the actual pushing processing time of the message is greater than a processing time threshold value corresponding to the target queue, recording a timeout time delay information of the target queue;
[0012] adjusting a number of consumers of the target queue based on a number of timeout latency information of the target queue recorded in a predetermined length of sliding time window.
[0013] In some embodiments, the adjusting the number of consumers of the target queue based on the number of timeout latency information of the target queue recorded in the predetermined length of sliding time window comprises:
[0014] if the number of timeout latency information of the target queue recorded in the predetermined length of sliding time window is greater than the number of pre-warning occurrences of the target queue, increasing the consumers of the target queue, and scheduling the added consumers to consume the messages in the target queue.
[0015] In some embodiments, the adjusting the number of consumers of the target queue based on the number of timeout latency information of the target queue recorded in the predetermined length of sliding time window comprises:
[0016] if the number of timeout latency information of the target queue recorded in the predetermined length of sliding time window is greater than the number of pre-warning occurrences of the target queue, and the current number of consumers of the target queue is less than a first consumer number threshold, increasing the consumers of the target queue, and scheduling the added consumers to consume the messages in the target queue.
[0017] In some embodiments, the adjusting the number of consumers of the target queue based on the number of timeout latency information of the target queue recorded in the predetermined length of sliding time window comprises:
[0018] if a duration that the target queue does not generate timeout latency information is greater than or equal to a duration threshold, and a number of unconsumed messages in the target queue is less than or equal to a message number threshold, decreasing the consumers of the target queue.
[0019] In some embodiments, the adjusting the number of consumers of the target queue based on the number of timeout latency information of the target queue recorded in the predetermined length of sliding time window comprises:
[0020] if a duration that the target queue does not generate timeout latency information is greater than or equal to a duration threshold, and a number of unconsumed messages in the target queue is less than or equal to a message number threshold, and the current number of consumers of the target queue is greater than a second consumer number threshold, decreasing the consumers of the target queue.
[0021] In some embodiments, the decreasing the consumers of the target queue comprises:
[0022] close the consumer of the target queue, or dispatch the consumer of the target queue to another target queue with higher priority than the target queue.
[0023] In a second aspect, a multi-queue-based message pushing system is provided, and the system comprises:
[0024] a message access service configured to receive a pushing request, the pushing request indicating a message to be pushed to a client; add a request timestamp to the message, add the message to a target queue in a plurality of priority queues based on a priority of the message, the request timestamp indicating a time point at which the pushing request is received;
[0025] a message consumer service configured to consume the message in the target queue by a consumer, and push the message to the client; record a processing completion timestamp of the message, the processing completion timestamp indicating a time point at which the message pushing is completed; obtain an actual pushing processing time of the message based on the request timestamp saved in the message and the message processing completion timestamp of the message, the actual pushing processing time being a time difference between the request timestamp and the message processing completion timestamp; if the actual pushing processing time of the message is greater than a processing time threshold value corresponding to the target queue, record a timeout delay information of the target queue, and upload the timeout delay information to a management configuration center;
[0026] the management configuration center is configured to adjust a number of consumers of the target queue based on a number of timeout delay information of the target queue recorded in a sliding time window with a predetermined length.
[0027] In some embodiments, the management configuration center is configured to increase the consumers of the target queue if the number of timeout delay information of the target queue recorded in the sliding time window with the predetermined length is greater than a number of early warning occurrences of the target queue, and dispatch the newly added consumers to consume the messages in the target queue.
[0028] In some embodiments, the management configuration center is configured to increase the consumers of the target queue if the number of timeout delay information of the target queue recorded in the sliding time window with the predetermined length is greater than the number of early warning occurrences of the target queue, and a current number of consumers of the target queue is less than a first consumer number threshold value, and dispatch the newly added consumers to consume the messages in the target queue.
[0029] In some embodiments, the management configuration center is configured to decrease the consumers of the target queue if a continuous length of time during which the target queue does not generate timeout delay information is greater than or equal to a length threshold value, and a number of unconsumed messages in the target queue is less than or equal to a message number threshold value.
[0030] In some embodiments, the management configuration center is configured to reduce the consumers of the target queue if the duration of the timeout delay information of the target queue is greater than or equal to a duration threshold, and the number of unconsumed messages in the target queue is less than or equal to a message number threshold, and the current number of consumers of the target queue is greater than a second consumer number threshold.
[0031] In some embodiments, the management configuration center is configured to close the consumers of the target queue, or schedule the consumers of the target queue to other target queues with higher priority than the target queue.
[0032] Therefore, the embodiments of the present application have the following beneficial effects:
[0033] The embodiments of the present application dynamically perceive the number of timeout delay information by monitoring the actual push processing time of the messages in the priority queue. The number of timeout delay information can represent the congestion situation of the priority queue, and therefore, the number of consumers of the priority queue is automatically adjusted based on the number of timeout delay information, so that the number of consumers of the priority queue is related to the congestion situation of the priority queue. When the priority queue is congested, more consumers are triggered to push the messages in the priority queue, and when the priority queue is idle, the consumers of the priority queue are reduced to save the server resources. Therefore, the embodiments of the present application can dynamically adjust the number of consumers according to the actual situation, reduce the risk of wasting server resources caused by processing messages by a fixed number of consumers, and therefore, the server resources are more fully utilized. BRIEF DESCRIPTION OF DRAWINGS
[0034] Figure 1 is a schematic diagram of a message access service provided by the embodiments of the present application;
[0035] Figure 2 is a schematic diagram of a message consumer service provided by the embodiments of the present application;
[0036] Figure 3 is a schematic diagram of a management configuration center scheduling consumers provided by the embodiments of the present application;
[0037] Figure 4 is a flowchart of a message push method based on multiple queues provided by the embodiments of the present application. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solutions and advantages of the present application more clear, the embodiments of the present application will be further described in detail below with reference to the drawings.
[0039] The embodiment of the application discloses a message pushing method and system based on multiple queues, which comprises the following steps: receiving a message pushing request from an upstream business system; adding a request timestamp in a message body, determining a priority of the message according to a type of the message and content of the message, and putting the message into a priority queue based on the priority of the message; processing the message by a consumer, and recording a processing completion timestamp of the message; obtaining an actual pushing processing time of the message based on the request timestamp and the processing completion timestamp of the message; judging whether the actual pushing processing time of the message exceeds a processing time threshold value; if the actual pushing processing time of the message exceeds the processing time threshold value, recording an overtime delay information; adjusting a number of consumers of a priority queue based on a number of overtime delay information of the priority queue recorded in a predetermined length sliding time window, so as to more fully utilize the resources of the server, and more stably and efficiently push the message.
[0040] The embodiment of the application provides a message pushing system based on multiple queues, which comprises a message access service, a management configuration center and a message consumer service.
[0041] The message access service is used for receiving a pushing request from an upstream business system and recording a request timestamp. The request timestamp indicates a time point at which the message access service receives the pushing request. The message access service determines a priority of the message based on content of the message and the type of the message through configuration. The message access service adds the request timestamp in the message body. Then, the message access service determines a target queue matched with the priority of the message from multiple queues based on the priority of the message and priorities of the multiple queues, and adds the message into the target queue. In some embodiments, a number of consumers corresponding to a priority queue is positively correlated with the priority of the priority queue. For example, if the priority of a priority queue is higher, the number of consumers corresponding to the priority queue is more, and the messages in the priority queue are processed by more consumers, so that the messages in the queue with higher priority are processed preferentially.
[0042] The message access service is also used for pulling priorities configured for various message types and various message contents from the management configuration center at a time, and placing a corresponding relationship between the configured message types, message contents and priorities in the memory. The message access service is as shown in FIG. 2. Figure 1
[0043] The message consumer service is used for pulling processing time thresholds configured for each priority queue from the management configuration center at a time, and updating the processing time thresholds in the memory. The consumers of each priority queue sequentially consume the messages in the corresponding priority queue, and push the messages to a client of a user. The consumer records a processing completion timestamp of the message after pushing the message. The processing completion timestamp indicates a time point at which the message is pushed.
[0044] The message consumer service obtains the actual push processing time of a message based on the request timestamp and the message processing completion timestamp stored in the message. The actual push processing time is the time difference between the request timestamp and the message processing completion timestamp. The actual push processing time can also be called the message push latency. For example, the message consumer service subtracts the request timestamp stored in the message body from the message processing completion timestamp to obtain the actual push processing time of the message. The message consumer service determines whether the actual push processing time of the message is greater than the processing time threshold configured for the priority queue. If the actual push processing time of the message is greater than the processing time threshold configured for the priority queue, it indicates that the message processing speed in the priority queue is too slow. Therefore, the consumer service records the timeout latency information and sends the timeout latency information to the management configuration center. If the actual push processing time of the message is less than or equal to the processing time threshold configured for the priority queue, no processing is performed.
[0045] The timeout information includes the priority queue name and the current occurrence time. The current occurrence time is the time when the message consumer service determines that the actual push processing time of the message is greater than the processing time threshold configured for the priority queue. By recording the priority queue name and the current occurrence time, it is equivalent to recording which queue experienced a timeout and when.
[0046] Message consumer services such as Figure 2 As shown, generally, queues with higher priority have more consumers.
[0047] The management configuration center is used to configure the processing time thresholds for each priority queue. These thresholds indicate the maximum time allowed for messages in a priority queue to be processed. Consumer services can retrieve and update these processing time thresholds from the management configuration center.
[0048] In addition, the management configuration center also configures the consumer number thresholds for each priority queue. These thresholds include a first consumer number threshold and a second consumer number threshold. The first consumer number threshold indicates the maximum number of consumers a priority queue can have; it can also be called the maximum number of consumers. The second consumer number threshold indicates the minimum number of consumers a priority queue can have; it can also be called the minimum number of consumers.
[0049] In addition, the management configuration center configures the number of times an alert can occur. It also monitors the current number of consumers in each priority queue. Furthermore, the management configuration center configures the priority queues corresponding to message types and message content for the message access service to pull and update.
[0050] For each priority queue configured, the management configuration center counts the number of timeout delay information received in a sliding time window by a time window sliding algorithm. If the number of timeout delay information received by the management configuration center for priority queue L1 is greater than the configured number of times T1 that a warning can occur for priority queue L1 in a predetermined length of sliding time window, it indicates that a message delay overlength warning has occurred for the priority queue, and the management configuration center can then initiate a new consumer to consume messages of the priority queue faster.
[0051] In some embodiments, if the number of timeout delay information received for priority queue L1 is greater than the configured number of times T1 that a warning can occur for priority queue L1 in a predetermined length of sliding window time, and the number of consumers of the current priority queue is less than the configured maximum number of consumers, the management configuration center calls a new consumer to consume messages of the priority queue. Considering that the number of all consumers is limited, if a consumer is added for a priority queue without limitation, it can occur that all available consumers are exhausted for a single priority queue, resulting in no available consumers to be called when congestion occurs in other priority queues. Therefore, by introducing the limitation that the number of consumers of the current priority queue is less than the configured maximum number of consumers when a new consumer is called, the risk of exhausting the available consumers is reduced.
[0052] In some embodiments, if the duration for which priority queue L1 does not generate timeout delay information (or the duration for which no message delay overlength warning occurs) is greater than or equal to a duration threshold, and the number of unconsumed messages in the priority queue L1 is less than or equal to a message number threshold, it indicates that the number of consumers of the priority queue can be reduced to save server resources, and the management configuration center reduces the consumers of the priority queue. The way to reduce the consumers of a priority queue includes closing the consumers of the queue or scheduling the consumers of the queue to consume other priority queues. For example, the management configuration center schedules the consumers of priority queue L1 to priority queue L2, and the priority of priority queue L2 is higher than the priority of priority queue L1. The management configuration center schedules the consumers as shown in Figure 3 .
[0053] In some embodiments, if the duration of the timeout delay information generated by the priority queue L1 (or the duration of the message delay overlength warning not occurring) is greater than or equal to the duration threshold, and the number of unprocessed messages in the priority queue is less than or equal to the message number threshold, and the current number of consumers of the priority queue is greater than the configured second consumer number threshold (the minimum consumer number), the management configuration center reduces the consumers of the priority queue. Considering that if the current number of consumers of the priority queue is less than the configured minimum consumer number, in the case of subsequently receiving the message corresponding to the priority queue, a new consumer usually needs to be started to process the message corresponding to the priority queue, resulting in greater delay in message processing. Therefore, by introducing the limitation condition that the current number of consumers of the priority queue is greater than the configured minimum consumer number when reducing the consumers of the priority queue, the delay caused by starting a new consumer is reduced.
[0054] The embodiment monitors the message pushing delay of the priority queue by the management configuration center, and dynamically perceives whether the message delay overlength warning occurs in the priority queue based on the number of timeout delay information. If the message delay overlength warning occurs in a priority queue (the number of timeout delay information is greater than the warning occurrence number of the priority queue), it indicates that congestion occurs in the queue. By automatically starting a new consumer to consume the messages in the priority queue, the messages in the priority queue are pushed faster, without the need for manual operation to adjust the number of consumers, thereby improving the timeliness of message pushing. If the message delay overlength warning does not occur for a long time (the duration of the timeout delay information not occurring is greater than or equal to the duration threshold) and the number of unprocessed messages in the priority queue is less than or equal to a certain number, the number of consumers of the priority queue can be automatically reduced to save server resources.
[0055] Please refer to the accompanying drawings Figure 4 , the accompanying Figure 4 is a flowchart of a message pushing method based on multiple queues provided by the embodiment of the present application, the accompanying Figure 4 The method shown in the figure is applied to a computer device, the computer device runs the message access service shown in the figure Figure 1 , the management configuration center shown in the figure Figure 3 and the message consumer service shown in the figure Figure 2 , and the computer device executes the method shown in the figure Figure 4 by the message access service, the management configuration center and the message consumer service. The method shown in the figure Figure 4 includes the following steps.
[0056] S410, receiving a pushing request, the pushing request indicating to push a message to a client.
[0057] S420, adding a request timestamp to the message, adding the message into a target queue in the plurality of priority queues that matches a priority of the message based on the priority of the message, the request timestamp indicating a time point at which the push request is received.
[0058] S430, consuming the message in the target queue by a consumer and pushing the message to the client.
[0059] S440, recording a processing completion timestamp of the message, the processing completion timestamp indicating a time point at which the message pushing is completed.
[0060] S450, obtaining an actual push processing time of the message based on the request timestamp saved in the message and the message processing completion timestamp of the message, the actual push processing time being a time difference between the request timestamp and the message processing completion timestamp.
[0061] S460, recording timeout delay information of the target queue if the actual push processing time of the message is greater than a processing time threshold corresponding to the target queue.
[0062] S470, adjusting a number of consumers of the target queue based on a number of the timeout delay information of the target queue recorded in a sliding time window of a predetermined length.
[0063] The embodiment can dynamically perceive the number of timeout delay information of the priority queue by monitoring the actual push processing time of the message in the priority queue. The number of timeout delay information can represent the congestion situation of the priority queue, and thus the number of consumers of the priority queue is automatically adjusted based on the number of timeout delay information, so that the number of consumers of the priority queue is related to the congestion situation of the priority queue. When the congestion occurs in the priority queue, more consumers can be triggered to push the message in the priority queue, and when the priority queue is idle, the consumers of the priority queue can be reduced to save the server resources. Therefore, the embodiment can dynamically adjust the number of consumers according to the actual situation, and reduce the risk of wasting the server resources caused by processing the message by the fixed number of consumers, so that the server resources can be more fully utilized.
[0064] Each of the embodiments in the specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other. Each of the embodiments mainly describes the difference from other embodiments.
[0065] A refers to B, which means that A is the same as B or a simple transformation of B.
[0066] The terms "first" and "second" and the like in the specification and claims of the embodiments of the present application are used to distinguish different objects, and are not used to describe a specific order of the objects, nor can they be understood as indicating or implying relative importance. For example, the first consumer quantity threshold and the second consumer quantity threshold are used to distinguish different consumer quantity thresholds, and are not used to describe a specific order of the consumer quantity thresholds, nor can they be understood as the first consumer quantity threshold being more important than the second consumer quantity threshold.
[0067] In the embodiments of the present application, unless otherwise specified, "at least one" means one or more, and "a plurality of" means two or more.
[0068] The above embodiments can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, the computer program instructions produce the processes or functions described in the embodiments of the present application in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another, for example, the computer instructions can be transferred from one website, computer, server or data center to another via wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) manner. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. integrated with one or more available media. The available media can be magnetic media (such as floppy disks, hard disks, magnetic tapes), optical media (such as DVDs), or semiconductor media (such as solid state disks (SSD)), etc.
[0069] The above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the foregoing embodiments of the present application have been described in detail, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for message pushing based on multiple queues, characterized in that, The method comprises: receiving a push request, the push request indicating to push a message to a client; adding a request timestamp to the message, adding the message to a target queue in a plurality of priority queues based on a priority of the message, the request timestamp indicating a time point of receiving the push request; consuming the message in the target queue by a consumer and pushing the message to the client; recording a processing completion timestamp of the message, the processing completion timestamp indicating a time point of completing the message pushing; obtaining an actual push processing time of the message based on the request timestamp saved in the message and the message processing completion timestamp of the message, the actual push processing time being a time difference between the request timestamp and the message processing completion timestamp; if the actual push processing time of the message is greater than a processing time threshold value corresponding to the target queue, recording timeout delay information of the target queue; adjusting a number of consumers of the target queue based on a number of the timeout delay information of the target queue recorded in a predetermined length sliding time window.
2. The method of claim 1, wherein, The adjusting a number of consumers of the target queue based on a number of the timeout delay information of the target queue recorded in a predetermined length sliding time window comprises: if the number of the timeout delay information of the target queue recorded in the predetermined length sliding time window is greater than a number of early warning occurrences of the target queue, increasing the consumers of the target queue and scheduling the added consumers to consume the messages in the target queue.
3. The method of claim 1, wherein, The adjusting a number of consumers of the target queue based on a number of the timeout delay information of the target queue recorded in a predetermined length sliding time window comprises: if the number of the timeout delay information of the target queue recorded in the predetermined length sliding time window is greater than a number of early warning occurrences of the target queue, and a current number of consumers of the target queue is less than a first consumer number threshold value, increasing the consumers of the target queue and scheduling the added consumers to consume the messages in the target queue.
4. The method of claim 1, wherein, The adjusting a number of consumers of the target queue based on a number of the timeout delay information of the target queue recorded in a predetermined length sliding time window comprises: if a duration that the target queue does not generate the timeout delay information is greater than or equal to a duration threshold value, and a number of unconsumed messages in the target queue is less than or equal to a message number threshold value, reducing the consumers of the target queue.
5. The method of claim 1, wherein, The adjusting a number of consumers of the target queue based on a number of the timeout delay information of the target queue recorded in a predetermined length sliding time window comprises: if a duration that the target queue does not generate the timeout delay information is greater than or equal to a duration threshold value, and a number of unconsumed messages in the target queue is less than or equal to a message number threshold value, and a current number of consumers of the target queue is greater than a second consumer number threshold value, reducing the consumers of the target queue.
6. The method according to claim 4 or 5, characterized in that, The reducing the consumers of the target queue comprises: close the consumer of the target queue, or dispatch the consumer of the target queue to another target queue with a higher priority than the target queue.
7. A multi-queue based message pushing system, characterized in that, The system comprises: a message access service configured to receive a push request, the push request indicating a message to be pushed to a client; add a request timestamp to the message, add the message to a target queue in a plurality of priority queues based on a priority of the message, the request timestamp indicating a time point at which the push request is received; a message consumer service configured to consume the message in the target queue by a consumer, and push the message to the client; record a processing completion timestamp of the message, the processing completion timestamp indicating a time point at which the message is pushed; obtain an actual push processing time of the message based on the request timestamp saved in the message and the message processing completion timestamp of the message, the actual push processing time being a time difference between the request timestamp and the message processing completion timestamp; if the actual push processing time of the message is greater than a processing time threshold corresponding to the target queue, record a timeout delay information of the target queue, and upload the timeout delay information to a management configuration center; the management configuration center is configured to adjust a number of consumers of the target queue based on a number of timeout delay information of the target queue recorded in a sliding time window with a predetermined length.
8. The system of claim 7, wherein, The management configuration center is configured to increase the consumers of the target queue if the number of timeout delay information of the target queue recorded in the sliding time window with the predetermined length is greater than a number of early warning occurrences of the target queue, and dispatch the added consumers to consume the messages in the target queue.
9. The system of claim 7, wherein, The management configuration center is configured to increase the consumers of the target queue if the number of timeout delay information of the target queue recorded in the sliding time window with the predetermined length is greater than the number of early warning occurrences of the target queue, and a current number of consumers of the target queue is less than a first consumer number threshold, and dispatch the added consumers to consume the messages in the target queue.
10. The system of claim 7, wherein, The management configuration center is configured to decrease the consumers of the target queue if a continuous length of the target queue without timeout delay information is greater than or equal to a length threshold, and a number of messages in the target queue without being consumed is less than or equal to a message number threshold.
Citation Information
Patent Citations
Message pushing method, device and system
CN109450805A
Inter-enterprise asynchronous message transmission method and system
CN111314476A