A method, storage medium and device for controlling the speed of message transmission
By employing a hierarchical processing and unified control message sending strategy, the problem of uneven processing capabilities among nodes in a distributed system is solved, achieving efficient message sending and resource utilization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-24
- Publication Date
- 2026-03-27
AI Technical Summary
In a distributed messaging system, the uneven processing capabilities among nodes cause the message sending speed to be lower than the receiver's maximum processing capacity, resulting in resource waste and message backlog.
A tiered processing strategy is adopted, prioritizing messages based on their timeliness and business attributes. In a distributed environment, a third-party caching database is used to uniformly control the message sending speed, ensuring that high-priority messages are sent first, while low-priority messages wait when necessary.
This approach ensures message timeliness and resource utilization without affecting overall sending speed, thus avoiding resource waste between nodes.
Abstract
Description
Technical Field
[0001] This invention relates to the field of network message transmission technology, and specifically to a method, storage medium, and device for controlling message sending speed. Background Technology
[0002] When platforms send messages, they can be categorized into message receivers and message senders based on the direction of message transmission. Since the message receiver's capacity to receive and process messages is limited, if the message sender's message transmission rate exceeds the receiver's processing rate, some messages sent by the sender will accumulate at the receiver, resulting in timeout exceptions. Therefore, the message sender should control its message transmission rate according to the message receiver's processing capacity.
[0003] The current approach is that the message sender presets a maximum sending speed based on the message receiver's processing capacity, and accumulates the number of messages sent per unit time. When the accumulated number reaches the preset maximum value, message sending is paused until the next unit time when the sending speed is recalculated. When the message sender's application service is deployed in a distributed manner, meaning multiple nodes are sending messages to the message receiver simultaneously, to ensure that the total message sending speed does not exceed the preset maximum value, the maximum sending speed of each node is equally divided among the total sending speed. That is, for the total sending speed M and the number of nodes N, the sending speed of each node should not exceed M / N.
[0004] However, in reality, each node has a different message processing capacity, which can cause some nodes to experience message congestion while others remain idle for extended periods. As a result, the overall message sending speed of the message sender will be lower than the maximum message processing capacity of the receiver, leading to a waste of resources. Summary of the Invention
[0005] To address the shortcomings of existing technologies, this invention aims to provide a method, storage medium, and device for controlling message sending speed.
[0006] To achieve the above objectives, the present invention adopts the following technical solution:
[0007] A method for controlling message sending speed includes the following steps:
[0008] S1. After receiving the message to be sent, the message sender first divides the message into priorities according to the message's timeliness and business attributes, based on a preset classification standard, and puts the message into the message queue corresponding to its priority.
[0009] S2. Process message sending for message queues of different priorities:
[0010] Before sending a high-priority message, it checks whether the number of messages sent in the current sending cycle has reached the maximum number of messages that can be sent. If it has not reached the maximum number of messages that can be sent, it will be sent directly and a message priority flag will be set to indicate that there is a high-priority message to be sent in the current sending cycle. After the message is sent, the number of messages sent in the current sending cycle will be accumulated.
[0011] Before sending a low-priority message, the system first checks if the number of messages sent in the current sending cycle has reached the maximum sending limit. If not, it checks if there is a higher-priority message identifier in the current sending cycle. If not, the message is sent directly. If there is, it checks if the number of messages sent in the current sending cycle has reached the preset percentage of the maximum sending limit. If not, the message is sent directly; otherwise, it waits until the next sending cycle to process the message. After the message is sent, the number of messages sent in the current sending cycle is accumulated. If the current priority is not the lowest priority, the message identifier of the corresponding priority is set; otherwise, no message identifier is set.
[0012] S3. At the start of the next sending cycle, reset the number of sent messages to 0 and clear the message identifiers for each priority level.
[0013] Furthermore, when the application service of the message sender is deployed in a distributed manner, the number of messages sent and the priority message identifier of the current sending period are stored in a third-party cache database. When each node processes the sending of messages to its local message queues of various priorities, it retrieves the number of messages sent and the priority message identifier of the current sending period from the third-party cache database and executes the sending process in step S2 accordingly.
[0014] The present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.
[0015] The present invention also provides a computer device, including a processor and a memory, wherein the memory is used to store a computer program; and the processor is used to execute the computer program to implement the above-described method.
[0016] The beneficial effects of this invention are as follows:
[0017] 1) This invention implements a hierarchical processing strategy for messages, with messages of higher priority being sent first, ensuring the timeliness of messages without affecting the overall sending speed.
[0018] 2) In this invention, the message sender adopts a unified message sending control mechanism in a distributed environment, which can ensure that the overall sending capacity of the system is utilized to the greatest extent possible. Detailed Implementation
[0019] The present invention will be further described below. It should be noted that this embodiment is based on the present technical solution and provides detailed implementation methods and specific operation processes, but the protection scope of the present invention is not limited to this embodiment.
[0020] This embodiment provides a method for controlling message sending speed, including the following steps:
[0021] S1. After receiving a message to be sent, the message sender first prioritizes the message according to its timeliness and business attributes, based on a preset classification standard, and places it into the message queue corresponding to its priority level. In this embodiment, the priority is divided into three levels: high, medium, and low. Different numbers of priority levels can also be used as needed.
[0022] S2. Process the messages for each priority queue. For high-priority messages, send them first, provided the sending rate does not exceed the preset maximum. Low-priority messages give way to high-priority messages. The specific process is as follows:
[0023] Before sending a high-priority message, the system checks whether the number of messages sent in the current sending cycle has reached the maximum number of messages that can be sent. If it has not reached the maximum number of messages that can be sent, the message will be sent directly, and a message flag indicating its priority will be set to indicate that there is a high-priority message to be sent in the current sending cycle. After the message is sent, the number of messages sent in the current sending cycle will be accumulated.
[0024] Before sending a low-priority message, the system first checks if the number of messages sent in the current sending cycle has reached the maximum sending limit. If not, it checks if there is a higher-priority message identifier in the current sending cycle. If not, the message is sent directly. If there is, it checks if the number of messages sent in the current sending cycle has reached a preset percentage of the maximum sending limit. If not, the message is sent directly; otherwise, it waits until the next sending cycle to process the message. After a message is sent, the number of messages sent in the current sending cycle is accumulated. If the current priority is not the lowest priority, the message identifier of the corresponding priority is set; otherwise, no message identifier is set.
[0025] Taking setting high, medium, and low priorities as an example, before sending a medium-priority message, it first checks whether the number of messages sent in the current sending cycle has reached the maximum sending limit. If not, it checks whether there is a high-priority message identifier in the current sending cycle. If not, it sends the message directly. If there is a high-priority message identifier, it checks whether the number of messages sent in the current sending cycle has reached 50% of the maximum sending limit. If not, it sends the message directly; otherwise, it waits until the next sending cycle. After the message is sent, the number of messages sent in the current sending cycle is accumulated, and the medium-priority message identifier is set.
[0026] Before sending a low-priority message, the system first checks whether the number of messages sent in the current sending cycle has reached the maximum number of messages that can be sent. If it has not, it checks whether there is a high-priority or medium-priority message identifier in the current sending cycle. If not, the message is sent directly. If there is a high-priority or medium-priority message identifier, the system checks whether the number of messages sent in the current sending cycle has reached 20% of the maximum number of messages that can be sent. If not, the message is sent directly; otherwise, it waits until the next sending cycle. Once the message is sent, the number of messages sent in the current sending cycle is accumulated.
[0027] S3. At the start of the next sending cycle, reset the number of sent messages to 0 and clear the message identifiers for each priority level.
[0028] When the application service of the message sender is deployed in a distributed manner, the number of messages sent and the priority message identifiers for the current sending period are stored in a third-party cache database such as Redis. When each node processes the sending of messages to its local message queues of various priorities, it retrieves the number of messages sent and the priority message identifiers for the current sending period from the third-party cache database and executes the sending process in step S2 accordingly. Each node adopts the same message sending rate control strategy and controls the sending rate based on the total number of messages sent and the priority message identifiers. In this way, if some nodes fail or process slowly, other nodes can continue to process messages normally within the maximum sending rate range.
[0029] For those skilled in the art, various corresponding changes and modifications can be made based on the above technical solutions and concepts, and all such changes and modifications should be included within the protection scope of the claims of this invention.
Claims
1. A method of controlling the speed of message transmission, characterized by, The method comprises the following steps: S1, after receiving a message to be sent, the message sender first divides the message into priority levels according to the timeliness and business attributes of the message and preset division criteria, and puts the message into a message queue corresponding to the priority level; S2, the message queues of each priority level are sent: Before sending the high-priority message, it is checked whether the number of messages sent in the current sending period has reached the maximum number of messages to be sent; if not, the high-priority message is directly sent, and a message identifier of the high-priority level is set to indicate that a high-priority message needs to be sent in the current sending period; and the number of messages sent in the current sending period is accumulated after the sending is completed; Before sending the low-priority message, it is checked whether the number of messages sent in the current sending period has reached the maximum number of messages to be sent; if not, it is further checked whether there is a message identifier of a higher priority level in the current sending period; if not, the low-priority message is directly sent; if there is, it is checked whether the number of messages sent in the current sending period has reached a preset percentage of the maximum number of messages to be sent; if not, the low-priority message is directly sent; otherwise, the low-priority message is sent in the next sending period; after the sending of the message is completed, the number of messages sent in the current sending period is accumulated; if the current priority level is not the lowest priority level, a message identifier of the current priority level is set; otherwise, no message identifier is set; S3, when the next sending period starts, the number of messages sent is reset to 0, and the message identifiers of each priority level are cleared; When the application service of the message sender is distributed, the number of messages sent in the current sending period and the priority message identifiers are stored in a third-party cache database; when each node sends the message queues of each priority level, the number of messages sent in the current sending period and the priority message identifiers are obtained from the third-party cache database, and the sending process of step S2 is executed according to the obtained number of messages sent in the current sending period and the priority message identifiers.
2. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to realize the method of claim 1.
3. A computer device, comprising: The computer readable storage medium stores a computer program, and the computer program is executed by the processor to realize the method of claim 1.
Citation Information
Patent Citations
Short message flow control method and device and storage medium
CN114205762A