CN108023938B - Message sending method and server - Google Patents
Message sending method and server Download PDFInfo
- Publication number
- CN108023938B CN108023938B CN201711112524.XA CN201711112524A CN108023938B CN 108023938 B CN108023938 B CN 108023938B CN 201711112524 A CN201711112524 A CN 201711112524A CN 108023938 B CN108023938 B CN 108023938B
- Authority
- CN
- China
- Prior art keywords
- message
- queue
- gateway
- server
- sent
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 48
- 230000003111 delayed effect Effects 0.000 claims description 6
- 230000008569 process Effects 0.000 abstract description 11
- 238000010586 diagram Methods 0.000 description 11
- 238000004590 computer program Methods 0.000 description 8
- 238000012986 modification Methods 0.000 description 5
- 230000004048 modification Effects 0.000 description 5
- 230000008859 change Effects 0.000 description 4
- 230000006870 function Effects 0.000 description 4
- 230000005540 biological transmission Effects 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 2
- 230000004075 alteration Effects 0.000 description 1
- 239000003795 chemical substances by application Substances 0.000 description 1
- 125000004122 cyclic group Chemical group 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000007726 management method Methods 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/56—Provisioning of proxy services
- H04L67/568—Storing data temporarily at an intermediate stage, e.g. caching
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L47/00—Traffic control in data switching networks
- H04L47/10—Flow control; Congestion control
- H04L47/29—Flow control; Congestion control using a combination of thresholds
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L47/00—Traffic control in data switching networks
- H04L47/50—Queue scheduling
- H04L47/62—Queue scheduling characterised by scheduling criteria
- H04L47/622—Queue service order
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The embodiment of the invention discloses a message sending method and a server, comprising the following steps: aiming at any message transmitter in the server, the server acquires a first message to be transmitted from a message queue of the message transmitter, judges whether the number of messages transmitted to the first gateway in the current time period of the first message transmitter reaches a set threshold value or not according to the first gateway to which the first message is transmitted, if so, stores the first message into the message queue again, and otherwise, transmits the first message to the first gateway. Because there can be messages to be sent of multiple gateways in the message queue of the message sender. Therefore, by adopting the scheme, when the number of the messages sent to the first gateway in the current time period is determined to reach the set threshold value, the obtained first message to be sent to the first gateway is stored in the message queue again, so that the server can continuously obtain and process the next message from the message queue, and the mutual influence of message sending of different gateways is effectively avoided.
Description
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a message sending method and a server.
Background
In a traditional MAS (Mobile Agent Server) service, after a user opens an account for a telecommunications carrier, the telecommunications carrier deploys an independent MAS Server for the user and sets a gateway for the user. When a user needs to send a short message, the short message is submitted to the MAS server, and then the MAS server is connected with a gateway for user account opening, so that the short message is sent.
Generally, the MAS server may connect several or several tens of gateways when providing a service for sending a short message to a user. Thus, a sender can be created for each gateway inside the MAS server, and the sender comprises a queue with limited size and a thread pool consisting of a plurality of threads. Therefore, after receiving the short message to be sent by the user, the server determines the gateway corresponding to the message through internal relevant logic, further finds the sender of the gateway according to the gateway identifier, and then submits the message to the sender, and the sender sends the message according to the sending speed of the gateway. It can be seen that, under the condition that the number of gateways connected by the MAS server is not large, the above-mentioned scheme can realize highly efficient short message sending, because each gateway has an independent thread pool, not only can the CPU be effectively utilized, but also the mutual influence between the messages of different gateways can be avoided.
However, with the change of the service mode, the telecom operator gradually deploys the MAS service on the cloud server, in such a scenario, the cloud server usually needs to connect ten thousand gateways, so that the huge number of gateways is not desirable, and a scheme of creating an independent thread pool for each gateway is not desirable, otherwise, the CPU is busy switching among massive threads and is unable to execute other services, thereby causing the rate of message sending to be reduced. If the scheme that the massive gateways use one unified thread pool is adopted, messages sent to the multiple gateways are stored in the same queue according to the sequence of submitting the messages to the cloud server, and the cloud server processes the messages in the queue in sequence, if the number of the messages sent to a certain gateway is large, the messages sent to other gateways are affected.
Therefore, there is a need for a message sending method, which is used to solve the technical problem in the prior art that messages sent to different gateways are mutually affected when a cloud server is connected to a mass gateway for message sending in a complex scenario.
Disclosure of Invention
The invention provides a message sending method and a server, which are used for solving the technical problem that messages sent to different gateways are mutually influenced in the complex scene that a cloud server is connected with massive gateways to send messages in the prior art.
The message sending method provided by the embodiment of the invention is applied to a server, wherein the server comprises a plurality of message senders, and each message sender comprises a message queue for storing messages to be sent; the message transmitter is used for transmitting messages to corresponding gateways, and the message transmitter corresponds to at least one gateway; the method comprises the following steps:
aiming at a first message transmitter, the server acquires a first message to be sent from a message queue of the first message transmitter; the first message is stored in a message queue of the first message sender by the server according to a first gateway to which the first message is sent; the first message sender is any one of the plurality of message senders;
and the server judges whether the number of messages sent to the first gateway by the first message sender in the current time period reaches a set threshold value or not according to the first gateway, if so, the first message is stored in the message queue again, and if not, the first message is sent to the first gateway.
Optionally, the server stores the first message in a message queue of the first message sender by:
the server receives the first message and determines a first gateway to which the first message is to be sent;
the server determines a first message transmitter corresponding to the first gateway according to the first gateway and the corresponding relation between each gateway and the message transmitter stored in the server;
the server stores the first message in a message queue of the first message sender.
Optionally, the storing, by the server, the first message in a message queue of the first message sender includes:
the server acquires a first message quantity of messages to be sent to the first gateway, which are stored in a message queue of the first message sender;
and if the server determines that the number of the first messages is smaller than the queue message quota corresponding to the first gateway, the server stores the first messages into the message queue.
Optionally, the method further comprises:
if the server determines that the first message quantity is greater than or equal to the queue message quota corresponding to the first gateway, acquiring a second message quantity of messages to be sent, stored in a message cache of the server, to be sent to the first gateway;
and if the server determines that the number of the second messages is less than or equal to the cache message quota corresponding to the first gateway, the server stores the first messages into the message cache, otherwise, a delayed submission instruction is sent out to instruct a sender of the first messages to submit the first messages again after the set time.
Optionally, the method further comprises:
the server acquires the first message quantity and the second message quantity according to a set period;
and if the server determines that the first message quantity is smaller than the queue message quota corresponding to the first gateway and the second message quantity is not zero, storing the message to be sent, which is stored in the message cache and is to be sent to the first gateway, in a message queue of the first message sender according to the first message quantity, the second message quantity and the queue message quota corresponding to the first gateway.
Optionally, the message queue includes a sending queue and a receiving queue;
the server acquires a first message to be sent from a message queue of the first message sender, and the method comprises the following steps: the server acquires a first message to be sent from a sending queue of the first message sender;
if the set threshold is reached, the first message is stored in the message queue again, including: if the set threshold value is reached, storing the first message into the receiving queue;
the server stores the first message in a message queue of the first message sender, including: the server stores the first message into the receiving queue;
the method further comprises the following steps:
and if the server determines that the sending of the message stored in the sending queue of the first message sender is finished, setting the sending queue as a receiving queue and setting the receiving queue as a sending queue.
Optionally, the method further comprises:
the server periodically acquires the total number of messages sent by each message sender in a set time period;
and the server adjusts the corresponding relation between each gateway and the message transmitter according to the total number of the messages transmitted by each message transmitter.
Based on the same inventive concept, an embodiment of the present invention further provides a server, where the server includes:
the system comprises an acquisition module, a sending module and a receiving module, wherein the acquisition module is used for acquiring a first message to be sent from a message queue of a first message sender aiming at the first message sender; the first message is stored in a message queue of the first message sender according to a first gateway to which the first message is to be sent; the first message sender is any one of a plurality of message senders;
and the processing module is used for judging whether the number of messages sent to the first gateway by the first message sender in the current time period reaches a set threshold value or not according to the first gateway, storing the first message into the message queue again if the number of messages reaches the set threshold value, and sending the first message to the first gateway if the number of messages does not reach the set threshold value.
Optionally, the server further includes a transceiver module, configured to:
receiving the first message, and determining a first gateway to which the first message is to be sent;
determining a first message transmitter corresponding to the first gateway according to the first gateway and the corresponding relation between each gateway and the message transmitter stored in the server;
storing the first message in a message queue of the first message sender.
Optionally, the transceiver module is specifically configured to:
acquiring a first message quantity of messages to be sent to the first gateway, which are stored in a message queue of the first message sender;
and if the number of the first messages is determined to be smaller than the queue message quota corresponding to the first gateway, storing the first messages into the message queue.
Optionally, the transceiver module is further configured to:
if the first message quantity is determined to be larger than or equal to the queue message quota corresponding to the first gateway, acquiring a second message quantity of messages to be sent, stored in a message cache of the server, to be sent to the first gateway;
if the second message quantity is less than or equal to the cache message quota corresponding to the first gateway, the first message is stored in the message cache, otherwise, a delayed submission instruction is sent out to instruct a sender of the first message to submit the first message again after the set time.
Optionally, the processing module is further configured to:
acquiring the first message quantity and the second message quantity according to a set period;
and if it is determined that the first message quantity is smaller than the queue message quota corresponding to the first gateway and the second message quantity is not zero, storing the message to be sent, which is stored in the message cache and is to be sent to the first gateway, in a message queue of the first message sender according to the first message quantity, the second message quantity and the queue message quota corresponding to the first gateway.
Optionally, the message queue includes a sending queue and a receiving queue;
the acquisition module is specifically configured to: acquiring a first message to be sent from a sending queue of the first message sender;
the processing module is specifically configured to: if the set threshold value is reached, storing the first message into the receiving queue;
the transceiver module is specifically configured to: storing the first message in the receive queue;
the server further comprises a switching module configured to:
and if the fact that the messages stored in the sending queue of the first message sender are sent is determined to be finished, setting the sending queue as a receiving queue, and setting the receiving queue as a sending queue.
Optionally, the processing module is further configured to:
periodically acquiring the total number of messages sent by each message sender in a set time period;
and adjusting the corresponding relation between each gateway and the message transmitter according to the total number of the messages transmitted by each message transmitter.
Another embodiment of the present invention provides a server, which includes a memory and a processor, wherein the memory is used for storing program instructions, and the processor is used for calling the program instructions stored in the memory and executing any one of the above methods according to the obtained program.
Another embodiment of the present invention provides a computer storage medium having stored thereon computer-executable instructions for causing a computer to perform any one of the methods described above.
In the embodiment of the invention, the server comprises a plurality of message transmitters, aiming at any message transmitter, the server acquires a first message to be transmitted from a message queue of the message transmitter, judges whether the number of the messages transmitted to the first gateway by the first message transmitter in the current time period reaches a set threshold value or not according to the first gateway to which the first message is transmitted, if so, stores the first message into the message queue again, otherwise, transmits the first message to the first gateway. Since one message sender corresponds to at least one gateway, messages to be sent to multiple gateways can be stored in a message queue of one message sender. Therefore, by adopting the technical scheme in the embodiment of the invention, when the number of the messages sent to the first gateway in the current time period is determined to reach the set threshold value, the obtained first message to be sent to the first gateway is stored in the message queue again, so that the server can continuously obtain and process the next message from the message queue, and therefore, the problem that the messages subsequently sent to other gateways cannot be sent when the messages processed by the server at present cannot be sent can be effectively avoided, the mutual influence of message sending of different gateways is effectively avoided, and the message sending efficiency, throughput and timeliness of the system are improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic diagram of a control structure of a server according to an embodiment of the present invention.
Fig. 2 is a schematic flowchart of a message sending method according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating a method for storing a first message in a message queue of a first message sender according to an embodiment of the present invention
Fig. 4 is a schematic structural diagram of a server according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiments of the present invention will be described in further detail with reference to the drawings attached hereto.
Fig. 1 is a schematic diagram of a control structure of a server in an embodiment of the present invention, and as shown in fig. 1, the server includes a plurality of message transmitters (such as the message transmitters 1011, 1012, 1013 shown in fig. 1), a message buffer 102, and a control center 103.
The message transmitters are used for transmitting messages to the corresponding gateways, and each message transmitter comprises a message queue used for storing messages to be transmitted. The message buffer is also used for storing messages to be sent of each gateway, but for a certain gateway, the messages to be sent of the gateway stored in the message buffer are stored in the message buffer only when the message queue of the message sender corresponding to the gateway is full relative to the first gateway. The control center is used for recording the message transmitters respectively corresponding to the gateways, and counting the number of messages to be sent stored in the message queue of the message transmitter corresponding to each gateway, the number of messages to be sent stored in the message cache of each gateway, and the number of messages sent by each gateway.
Specifically, in the embodiment of the present invention, the server stores the correspondence between each gateway and the message sender, and one message sender may correspond to one or more gateways. If the message sender only corresponds to one gateway, the message queue of the message sender only stores the message to be sent of the gateway, and if the message sender corresponds to a plurality of gateways, the message to be sent of the plurality of gateways can be stored in the message queue of the message sender.
It should be further noted that, in the embodiment of the present invention, gateways corresponding to different message transmitters do not overlap with each other, and from the perspective of a gateway, one gateway may correspond to only one message transmitter. Therefore, the message to be sent of a certain gateway is sent only through one appointed message sender, and the server can effectively and centrally control and manage the message sending of the gateway.
In the embodiment of the present invention, the server may further set a queue message quota for each gateway, where the queue message quota corresponding to one gateway is the maximum number of messages to be sent of the gateway that can be stored in the message queue of the message sender corresponding to the gateway. As a preferred implementation manner, the value of the queue message quota may be set to the maximum number of messages that the message sender corresponding to the gateway allows to send to the gateway within a set time period, for example, the queue message quota corresponding to a certain gateway may be set to the number of messages that the message sender corresponding to the gateway can send to the gateway within 1 second.
In the embodiment of the present invention, the queue message quota set by the server for each gateway may be the same or different, and a person skilled in the art may specifically set the numerical value of the queue message quota of the gateway for the traffic of each gateway, which is not specifically limited by the present invention.
It can be seen that, for a certain message sent to a certain gateway, after the server receives the message, the message can be stored in the message queue of the message sender only when the message quantity of the message to be sent of the gateway stored in the message queue of the message sender corresponding to the gateway is less than the queue message quota corresponding to the gateway. If the number of messages of the gateway to be sent, which are stored in the message queue, reaches the queue message limit, the messages cannot be stored in the message queue.
In the embodiment of the invention, the server is also provided with a buffer queue for each gateway, the buffer queue of one gateway is used for storing the messages to be sent of the gateway, and the messages in the buffer queue are arranged according to the time sequence stored in the buffer queue. Correspondingly, the message cache in the embodiment of the present invention may specifically be a hash table, where the hash table stores the correspondence between the gateway identifier of each gateway and the cache queue, with the gateway identifier of each gateway as a key value.
Therefore, when the server needs to acquire the message to be sent of a certain gateway from the message cache, the server can quickly locate the cache queue of the gateway by inquiring the hash table according to the gateway identifier of the gateway, so that the message to be sent of the gateway can be acquired from the cache queue of the gateway. In the embodiment of the present invention, the hash table may have a variety of specific implementation manners, for example, ConcurrentHashMap and the like. The present invention is not particularly limited thereto.
In the embodiment of the present invention, the server may further set the buffer message quota for each gateway, where the buffer message quota corresponding to one gateway is the number of messages to be sent that can be stored in the buffer queue corresponding to the gateway at most. For the same gateway, the buffer message quota of the gateway is greater than the queue message quota, that is, the value of the buffer message quota may also be set to the maximum number of messages that the message sender corresponding to the gateway is allowed to send to the gateway in the set time period, but the length of the set time period of the buffer message quota is greater than the length of the time period of the queue message quota. For example, if the queue message quota of a certain gateway is set as the number of messages that can be sent to the gateway within 1 second by the message sender corresponding to the gateway, the cache message quota corresponding to the gateway can be set as the number of messages that can be sent to the gateway within 10 seconds by the message sender corresponding to the gateway.
In the embodiment of the present invention, a person skilled in the art may specifically set the cache message quota of each gateway according to actual service needs, and the cache message quotas of each gateway may be the same or different, which is not specifically limited by the present invention.
It should be noted that, after the server specifically sets the queue message quota and the cache message quota for each gateway, the queue message quota and the cache message quota corresponding to each gateway may also be recorded in the control center, so as to perform query when the server acquires and processes messages.
Fig. 2 is a flowchart illustrating a process corresponding to a message sending method according to an embodiment of the present invention, where as shown in fig. 2, the method includes:
step S201: aiming at a first message transmitter, the server acquires a first message to be sent from a message queue of the first message transmitter; the first message is stored in a message queue of the first message sender by the server according to a first gateway to which the first message is sent;
step S202: and the server judges whether the number of messages sent to the first gateway by the first message sender in the current time period reaches a set threshold value or not according to the first gateway, if so, the first message is stored in the message queue again, and if not, the first message is sent to the first gateway.
Since one message sender corresponds to at least one gateway, messages to be sent to multiple gateways can be stored in a message queue of one message sender. Therefore, by adopting the technical scheme in the embodiment of the invention, when the number of the messages sent to the first gateway in the current time period is determined to reach the set threshold value, the obtained first message to be sent to the first gateway is stored in the message queue again, so that the server can continuously obtain and process the next message from the message queue, and therefore, the problem that the messages subsequently sent to other gateways cannot be sent when the messages processed by the server at present cannot be sent can be effectively avoided, the mutual influence of message sending of different gateways is effectively avoided, and the message sending efficiency, throughput and timeliness of the system are improved.
In this embodiment of the present invention, the first message sender is any one of a plurality of message senders of a server, and the first message sender is taken as an example in the embodiment of the present invention to describe a message sending process.
Specifically, in step S201, the server obtains a first message to be sent from a message queue of a first message sender, where the first message is stored in the message queue of the first message sender by a first gateway to which the server is to send according to the first message. Due to the first-in first-out characteristic of the data structure of the queue, the first message acquired by the server stores the message with the earliest time in all the messages to be sent of the message queue, namely the first message in the message queue.
Subsequently, the server may determine, according to the acquired first message, a first gateway to which the first message is to be sent, where the first gateway is one of the one or more gateways corresponding to the first message sender.
Further, in step S202, the server may obtain the number of messages that have been sent to the first gateway by the first message sender in the current time period, and determine whether the number of messages reaches the set threshold. The set threshold is the maximum number of messages allowed to be sent to a certain gateway by the message sender in a time period, and marks the maximum message sending speed set by the server for the gateway. In the embodiment of the present invention, the server may set the setting threshold for each gateway, and the setting thresholds corresponding to each gateway may be the same or different. If the set thresholds corresponding to the two gateways are the same, it means that the server sets the same maximum message transmission speed for the two gateways. Those skilled in the art specifically set the set threshold according to the actual service condition of each gateway, and the present invention is not limited to this specifically.
Specifically, if the number of messages reaches the set threshold, which indicates that the message transmission of the first gateway has reached the set maximum message transmission speed, the server determines not to transmit the first message in the current time period, and stores the first message in the message queue again. Since the server always obtains the message at the beginning and stores the message at the end of the message queue, the first message in the message queue is changed from the first message in the message queue to the last message in the message queue after the first message is stored in the message queue again. If the number of the messages does not reach the set threshold value, the first message sending speed does not reach the set maximum message sending speed, and therefore the server sends the first message to the first gateway.
It is assumed that in the message queue of the first message sender, the next message after the first message is the second message. Since the gateways to which the first message and the second message are to be sent may be different, when the message sending speed of the first gateway reaches the maximum message sending speed, the first message is stored in the message queue again, the second message is changed from the second message in the message queue to the first message in the message queue, and the server may obtain the second message from the message queue and determine whether the second message can be sent. In this scenario, if the gateway to which the second message is to be sent is the second gateway, at this time, if the message sending speed of the second gateway does not reach the set maximum message sending speed, the server may normally send the second message. Similarly, if the gateway to which the second message is to be sent is the first gateway, or the second gateway to which the second message is to be sent also reaches the set maximum message sending speed, the server may store the second message in the message queue again.
Therefore, the problem that messages to be sent of other gateways cannot be sent when the messages of one gateway cannot be sent due to the fact that the messages of the one gateway reach the maximum sending speed can be avoided, and mutual influence of message sending of different gateways is avoided.
In the embodiment of the present invention, each message sender further includes a sending thread, and the sending thread is configured to sequentially obtain and send each message to be sent in the message queue. Therefore, the server executes the steps S201 to S202 described above through the sending thread in the first sender, and acquires the first message from the message queue of the first message sender, determines whether the message can be sent, sends the message, and the like.
Because each message sender processes the message sending in the message queue of the message sender through the sending thread of the message sender, and the server comprises a plurality of message senders, the server works by utilizing a plurality of threads simultaneously, and the overall throughput of the system can be effectively improved.
In this embodiment of the present invention, before the server performs the above steps S101 to S102 to process the first message, the server may further store the first message into a message queue of the first message sender in the following manner, as shown in fig. 3, including the following steps:
step S301: the server receives the first message and determines a first gateway to which the first message is to be sent;
step S302: the server determines a first message transmitter corresponding to the first gateway according to the first gateway and the corresponding relation between each gateway and the message transmitter stored in the server;
step S303: the server stores the first message in a message queue of the first message sender.
Specifically, in step S301, the server receives a first message, and determines a first gateway to which the first message is to be sent according to the first message.
In step S302, the server may directly store the corresponding relationship between each gateway and the message sender, or may also assign the message sent to a certain gateway to a certain message sender according to a set rule, for example, the gateway identifier may be used as a key value key, and a set hash algorithm is used to calculate the message sender corresponding to a certain gateway, or a cyclic redundancy check algorithm may be used to calculate the message sender corresponding to a certain gateway, which is not specifically limited in the present invention.
In step S303, the server may obtain a first message quantity to be sent to the first gateway, where the first message quantity is stored in a message queue of the first message sender, and store the first message in the message queue if it is determined that the first message quantity is smaller than a queue message quota corresponding to the first gateway.
Otherwise, if the first message quantity is determined to be greater than or equal to the queue message limit corresponding to the first gateway, it is indicated that the first message cannot be stored in the message queue of the first message sender at present, and therefore, the server can further obtain a second message quantity stored in the message cache and to be sent to the first gateway, if the second message quantity is determined to be less than or equal to the cache message limit corresponding to the first gateway, the first message is stored in the message cache, and if the first message quantity of the message queue of the subsequent first message sender is less than the queue message limit of the first gateway, the first message can be stored in the message queue again.
Otherwise, if the first message quantity is greater than or equal to the queue message quota corresponding to the first gateway, and meanwhile, the second message quantity is greater than or equal to the cache message quota corresponding to the first gateway, it indicates that the message queue of the current first message sender and the message cache of the server are full, and the message sent to the first gateway cannot be received currently, so that the server may send a delayed submission instruction to the sender of the first message to instruct the sender of the first message to submit the first message again after the set time. For example, the setting time may be several seconds, several minutes or other time duration, and the specific value thereof may be set by a person skilled in the art according to the actual situation, and the invention is not limited thereto.
For the first gateway, since the server can store the message sent to the first gateway into the message buffer in the case that the number of messages sent to the first gateway stored in the message queue of the first message sender reaches the queue message quota of the first gateway, therefore, in the embodiment of the present invention, the server may further obtain the first message quantity and the second message quantity according to a set period, if it is determined that the first message quantity is smaller than the queue message quota corresponding to the first gateway and the second message quantity is not zero, the message to be sent, which is stored in the message buffer and is to be sent to the first gateway, may be stored in the message queue of the first message sender according to the first message quantity, the second message quantity, and the queue message quota corresponding to the first gateway until the first message quantity reaches the queue message quota or the second message quantity becomes zero.
Specifically, if the number of the acquired first messages is smaller than the queue message quota corresponding to the first gateway, it indicates that the number of messages to be sent of the first gateway, which can be currently stored in the message queue of the first message sender, is equal to the difference between the queue message quota and the first message number.
Furthermore, if the second message quantity is less than or equal to the difference between the queue message quota and the first message quantity, all messages to be sent of the first gateway stored in the message buffer can be stored in the message queue of the first message sender, and in this case, the buffer queue corresponding to the first gateway in the message buffer becomes empty.
If the second number of messages is greater than the difference between the queue message quota and the first number of messages, the number of messages stored in the message buffer (queue message quota-first number of messages) may be stored in the message queue of the first message sender, in which case the number of messages stored in the message queue is the first number of messages (queue message quota-first number of messages) in the buffer queue corresponding to the first gateway in the message buffer.
In the embodiment of the present invention, the server may set a scanning thread to separately perform the above scanning of the message queue and the message buffer of the first message sender to determine the first message number and the second message number, and send the messages in the message buffer to the message queue.
In the embodiment of the present invention, the message queue of each message sender may be one queue, or may be a message queue composed of two queues, i.e., a sending queue and a receiving queue. Wherein the sending queue is only used for the server to acquire and send messages, and the received messages are only used for storing messages.
Specifically, if the message queue of each message sender includes two queues, namely a sending queue and a receiving queue, the server stores the message into the receiving queue when receiving the message and judging that the message can be stored into the message queue; and meanwhile, the server acquires the messages from the sending queue one by one, if the gateway corresponding to the messages is judged not to reach the set maximum sending speed, the messages are sent to the corresponding gateway, and otherwise, the messages are taken out and stored in the receiving queue.
In addition, if all the messages to be sent stored in the sending queue are sent, the server also switches the sending queue and the receiving queue, namely sets the sending queue as the receiving queue and sets the receiving queue as the sending queue, and then continues to send the messages. Currently, if the receiving queue is empty when the sending of the message to be sent in the sending queue is completed, the server may wait for a period of time, and switch the queue after receiving a certain amount of messages in the receiving queue.
In the embodiment of the present invention, the correspondence between each gateway and the message sender stored in the server may be kept unchanged after the setting, but considering that the service condition of each gateway may change dynamically with the change of time, in this embodiment of the present invention, the server may further dynamically adjust the correspondence between each gateway and the message sender according to the operating condition of each message sender.
Specifically, a management thread may be set in the server, and is used to periodically scan the control center to determine the total number of messages in the message queue of each message sender and the number of messages to be sent, which are stored in the corresponding message queue by each gateway. If the number of messages to be sent stored in the message queue of a certain message sender is found to be much larger than the number of messages to be sent stored in the message queues of other message senders, one or more gateways corresponding to the message sender can be dynamically allocated to the other message senders.
In the embodiment of the invention, the adjustment of the corresponding relation between each gateway and the message sender can be realized by changing the algorithm of the message specified message sender. For example, if the server determines the sender processing the message by using a hash algorithm according to the gateway identifier of the gateway to which the message is to be sent after receiving the message, the server may change the corresponding relationship between each gateway and the message sender by changing the hash algorithm of the message-designated message sender.
Therefore, by dynamically adjusting the corresponding relation between each gateway and the message sender, the problem that the overall throughput of the system is reduced due to the fact that messages received by the server are concentrated into a few message senders to be processed can be prevented, and therefore hot spots of the system can be eliminated, and stable operation of the system is guaranteed.
Based on the same inventive concept, an embodiment of the present invention further provides a server, and fig. 4 is a schematic structural diagram of the server provided in the embodiment of the present invention, as shown in fig. 4, the server 400 includes:
an obtaining module 401, configured to obtain, for a first message sender, a first message to be sent from a message queue of the first message sender; the first message is stored in a message queue of the first message sender according to a first gateway to which the first message is to be sent; the first message sender is any one of a plurality of message senders;
a processing module 402, configured to determine, according to the first gateway, whether the number of messages sent to the first gateway by the first message sender in the current time period reaches a set threshold, if the number of messages reaches the set threshold, store the first message in the message queue again, and if the number of messages does not reach the set threshold, send the first message to the first gateway.
Optionally, the server further includes a transceiver module 403, configured to:
receiving the first message, and determining a first gateway to which the first message is to be sent;
determining a first message transmitter corresponding to the first gateway according to the first gateway and the corresponding relation between each gateway and the message transmitter stored in the server;
storing the first message in a message queue of the first message sender.
Optionally, the transceiver module 403 is specifically configured to:
acquiring a first message quantity of messages to be sent to the first gateway, which are stored in a message queue of the first message sender;
and if the number of the first messages is determined to be smaller than the queue message quota corresponding to the first gateway, storing the first messages into the message queue.
Optionally, the transceiver module 403 is further configured to:
if the first message quantity is determined to be larger than or equal to the queue message quota corresponding to the first gateway, acquiring a second message quantity of messages to be sent, stored in a message cache of the server, to be sent to the first gateway;
if the second message quantity is less than or equal to the cache message quota corresponding to the first gateway, the first message is stored in the message cache, otherwise, a delayed submission instruction is sent out to instruct a sender of the first message to submit the first message again after the set time.
Optionally, the processing module 402 is further configured to:
acquiring the first message quantity and the second message quantity according to a set period;
and if it is determined that the first message quantity is smaller than the queue message quota corresponding to the first gateway and the second message quantity is not zero, storing the message to be sent, which is stored in the message cache and is to be sent to the first gateway, in a message queue of the first message sender according to the first message quantity, the second message quantity and the queue message quota corresponding to the first gateway.
Optionally, the message queue includes a sending queue and a receiving queue;
the obtaining module 401 is specifically configured to: acquiring a first message to be sent from a sending queue of the first message sender;
the processing module 402 is specifically configured to: if the set threshold value is reached, storing the first message into the receiving queue;
the transceiver module 403 is specifically configured to: storing the first message in the receive queue;
the server further comprises a switching module 404 for:
and if the fact that the messages stored in the sending queue of the first message sender are sent is determined to be finished, setting the sending queue as a receiving queue, and setting the receiving queue as a sending queue.
Optionally, the processing module 402 is further configured to:
periodically acquiring the total number of messages sent by each message sender in a set time period;
and adjusting the corresponding relation between each gateway and the message transmitter according to the total number of the messages transmitted by each message transmitter.
Based on the same inventive concept, the embodiment of the present invention further provides another server, where the server may include a Central Processing Unit (CPU), a memory, an input/output device, and the like, the input device may include a keyboard, a mouse, a touch screen, and the like, and the output device may include a display device, such as a Liquid Crystal Display (LCD), a Cathode Ray Tube (CRT), and the like.
The memory may include Read Only Memory (ROM) and Random Access Memory (RAM), and provides the processor with program instructions and data stored in the memory. In an embodiment of the present invention, the memory may be configured to store a program of the above-described message sending method.
The processor is used for executing the message sending method according to the obtained program instructions by calling the program instructions stored in the memory.
Based on the same inventive concept, embodiments of the present invention provide a computer storage medium for storing computer program instructions for the server, which includes a program for executing the message sending method.
The computer storage media may be any available media or data storage device that can be accessed by a computer, including, but not limited to, magnetic memory (e.g., floppy disks, hard disks, magnetic tape, magneto-optical disks (MOs), etc.), optical memory (e.g., CDs, DVDs, BDs, HVDs, etc.), and semiconductor memory (e.g., ROMs, EPROMs, EEPROMs, non-volatile memory (NAND FLASH), Solid State Disks (SSDs)), etc.
From the above, it can be seen that:
in the embodiment of the invention, the server comprises a plurality of message transmitters, aiming at any message transmitter, the server acquires a first message to be transmitted from a message queue of the message transmitter, judges whether the number of the messages transmitted to the first gateway by the first message transmitter in the current time period reaches a set threshold value or not according to the first gateway to which the first message is transmitted, if so, stores the first message into the message queue again, otherwise, transmits the first message to the first gateway. Since one message sender corresponds to at least one gateway, messages to be sent to multiple gateways can be stored in a message queue of one message sender. Therefore, by adopting the technical scheme in the embodiment of the invention, when the number of the messages sent to the first gateway in the current time period is determined to reach the set threshold value, the obtained first message to be sent to the first gateway is stored in the message queue again, so that the server can continuously obtain and process the next message from the message queue, and therefore, the problem that the messages subsequently sent to other gateways cannot be sent when the messages processed by the server at present cannot be sent can be effectively avoided, the mutual influence of message sending of different gateways is effectively avoided, and the message sending efficiency, throughput and timeliness of the system are improved.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart block or blocks and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.
Claims (16)
1. A message sending method is characterized in that the method is applied to a server, the server comprises a plurality of message senders, and each message sender comprises a message queue for storing messages to be sent; the message transmitter is used for transmitting messages to corresponding gateways, and the message transmitter corresponds to a plurality of gateways; the method comprises the following steps:
aiming at a first message transmitter, the server acquires a first message to be sent from a message queue of the first message transmitter; the first message is stored in a message queue of the first message sender by the server according to a first gateway to which the first message is sent; the first message sender is any one of the plurality of message senders;
and the server judges whether the number of messages sent to the first gateway by the first message sender in the current time period reaches a set threshold value or not according to the first gateway, if so, the first message is stored in the message queue again, and if not, the first message is sent to the first gateway.
2. The method of claim 1, wherein the server stores the first message in a message queue of the first message sender by:
the server receives the first message and determines a first gateway to which the first message is to be sent;
the server determines a first message transmitter corresponding to the first gateway according to the first gateway and the corresponding relation between each gateway and the message transmitter stored in the server;
the server stores the first message in a message queue of the first message sender.
3. The method of claim 2, wherein storing the first message in a message queue of the first message sender by the server comprises:
the server acquires a first message quantity of messages to be sent to the first gateway, which are stored in a message queue of the first message sender;
and if the server determines that the number of the first messages is smaller than the queue message quota corresponding to the first gateway, the server stores the first messages into the message queue.
4. The method of claim 3, further comprising:
if the server determines that the first message quantity is greater than or equal to the queue message quota corresponding to the first gateway, acquiring a second message quantity of messages to be sent, stored in a message cache of the server, to be sent to the first gateway;
and if the server determines that the number of the second messages is less than or equal to the cache message quota corresponding to the first gateway, the server stores the first messages into the message cache, otherwise, a delayed submission instruction is sent out to instruct a sender of the first messages to submit the first messages again after the set time.
5. The method of claim 4, further comprising:
the server acquires the first message quantity and the second message quantity according to a set period;
and if the server determines that the first message quantity is smaller than the queue message quota corresponding to the first gateway and the second message quantity is not zero, storing the message to be sent, which is stored in the message cache and is to be sent to the first gateway, in a message queue of the first message sender according to the first message quantity, the second message quantity and the queue message quota corresponding to the first gateway.
6. The method of any of claims 1 to 5, wherein the message queues include a send queue and a receive queue;
the server acquires a first message to be sent from a message queue of the first message sender, and the method comprises the following steps: the server acquires a first message to be sent from a sending queue of the first message sender;
if the set threshold is reached, the first message is stored in the message queue again, including: if the set threshold value is reached, storing the first message into the receiving queue;
the server stores the first message in a message queue of the first message sender, including: the server stores the first message into the receiving queue;
the method further comprises the following steps:
and if the server determines that the sending of the message stored in the sending queue of the first message sender is finished, setting the sending queue as a receiving queue and setting the receiving queue as a sending queue.
7. The method of claim 6, further comprising:
the server periodically acquires the total number of messages sent by each message sender in a set time period;
and the server adjusts the corresponding relation between each gateway and the message transmitter according to the total number of the messages transmitted by each message transmitter.
8. A server, characterized in that the server comprises:
the system comprises an acquisition module, a sending module and a receiving module, wherein the acquisition module is used for acquiring a first message to be sent from a message queue of a first message sender aiming at the first message sender; the first message is stored in a message queue of the first message sender according to a first gateway to which the first message is to be sent; the first message sender is any one of a plurality of message senders; wherein the first message sender corresponds to a plurality of gateways;
and the processing module is used for judging whether the number of messages sent to the first gateway by the first message sender in the current time period reaches a set threshold value or not according to the first gateway, storing the first message into the message queue again if the number of messages reaches the set threshold value, and sending the first message to the first gateway if the number of messages does not reach the set threshold value.
9. The server according to claim 8, further comprising a transceiver module configured to:
receiving the first message, and determining a first gateway to which the first message is to be sent;
determining a first message transmitter corresponding to the first gateway according to the first gateway and the corresponding relation between each gateway and the message transmitter stored in the server;
storing the first message in a message queue of the first message sender.
10. The server according to claim 9, wherein the transceiver module is specifically configured to:
acquiring a first message quantity of messages to be sent to the first gateway, which are stored in a message queue of the first message sender;
and if the number of the first messages is determined to be smaller than the queue message quota corresponding to the first gateway, storing the first messages into the message queue.
11. The server according to claim 10, wherein the transceiver module is further configured to:
if the first message quantity is determined to be larger than or equal to the queue message quota corresponding to the first gateway, acquiring a second message quantity of messages to be sent, stored in a message cache of the server, to be sent to the first gateway;
if the second message quantity is less than or equal to the cache message quota corresponding to the first gateway, the first message is stored in the message cache, otherwise, a delayed submission instruction is sent out to instruct a sender of the first message to submit the first message again after the set time.
12. The server according to claim 11, wherein the processing module is further configured to:
acquiring the first message quantity and the second message quantity according to a set period;
and if it is determined that the first message quantity is smaller than the queue message quota corresponding to the first gateway and the second message quantity is not zero, storing the message to be sent, which is stored in the message cache and is to be sent to the first gateway, in a message queue of the first message sender according to the first message quantity, the second message quantity and the queue message quota corresponding to the first gateway.
13. The server according to any one of claims 9 to 11, wherein the message queue comprises a send queue and a receive queue;
the acquisition module is specifically configured to: acquiring a first message to be sent from a sending queue of the first message sender;
the processing module is specifically configured to: if the set threshold value is reached, storing the first message into the receiving queue;
the transceiver module is specifically configured to: storing the first message in the receive queue;
the server further comprises a switching module configured to:
and if the fact that the messages stored in the sending queue of the first message sender are sent is determined to be finished, setting the sending queue as a receiving queue, and setting the receiving queue as a sending queue.
14. The server according to claim 13, wherein the processing module is further configured to:
periodically acquiring the total number of messages sent by each message sender in a set time period;
and adjusting the corresponding relation between each gateway and the message transmitter according to the total number of the messages transmitted by each message transmitter.
15. A server, comprising:
a memory for storing program instructions;
a processor for calling program instructions stored in said memory to perform the method of any of claims 1 to 7 in accordance with the obtained program.
16. A computer-readable storage medium having stored thereon computer-executable instructions for, when executed by a processor, causing the computer to perform the method of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201711112524.XA CN108023938B (en) | 2017-11-13 | 2017-11-13 | Message sending method and server |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201711112524.XA CN108023938B (en) | 2017-11-13 | 2017-11-13 | Message sending method and server |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108023938A CN108023938A (en) | 2018-05-11 |
CN108023938B true CN108023938B (en) | 2020-10-16 |
Family
ID=62080564
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201711112524.XA Active CN108023938B (en) | 2017-11-13 | 2017-11-13 | Message sending method and server |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108023938B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109240836B (en) * | 2018-09-06 | 2020-10-30 | 苏州浪潮智能科技有限公司 | Method and device for configuring messages of message queue |
CN113177178A (en) * | 2021-04-30 | 2021-07-27 | 北京深演智能科技股份有限公司 | Message processing method and device, nonvolatile storage medium and processor |
CN116170385A (en) * | 2023-04-21 | 2023-05-26 | 四川汉科计算机信息技术有限公司 | Gateway information forwarding system, method, equipment and storage medium |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2008112248A1 (en) * | 2007-03-14 | 2008-09-18 | Amx, Llc | System, method and computer readable medium for communicating with a zigbee device from a peripheral network |
CN101707789A (en) * | 2009-11-30 | 2010-05-12 | 中兴通讯股份有限公司 | Method and system for controlling flow |
CN101951571A (en) * | 2010-08-27 | 2011-01-19 | 中兴通讯股份有限公司 | Short message retrying method and short message gateway |
CN102223680A (en) * | 2010-04-16 | 2011-10-19 | 华为技术有限公司 | Flow control method, equipment and system |
CN103475595A (en) * | 2013-08-20 | 2013-12-25 | 国家电网公司 | System and method for overload control of Parlay X gateway |
US8874677B2 (en) * | 2005-08-22 | 2014-10-28 | Triplay Communications Ltd. | Messaging system and method |
-
2017
- 2017-11-13 CN CN201711112524.XA patent/CN108023938B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8874677B2 (en) * | 2005-08-22 | 2014-10-28 | Triplay Communications Ltd. | Messaging system and method |
WO2008112248A1 (en) * | 2007-03-14 | 2008-09-18 | Amx, Llc | System, method and computer readable medium for communicating with a zigbee device from a peripheral network |
CN101707789A (en) * | 2009-11-30 | 2010-05-12 | 中兴通讯股份有限公司 | Method and system for controlling flow |
CN102223680A (en) * | 2010-04-16 | 2011-10-19 | 华为技术有限公司 | Flow control method, equipment and system |
CN101951571A (en) * | 2010-08-27 | 2011-01-19 | 中兴通讯股份有限公司 | Short message retrying method and short message gateway |
CN103475595A (en) * | 2013-08-20 | 2013-12-25 | 国家电网公司 | System and method for overload control of Parlay X gateway |
Also Published As
Publication number | Publication date |
---|---|
CN108023938A (en) | 2018-05-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US12075106B2 (en) | Message sending method and device, readable medium and electronic device | |
US11895577B2 (en) | Network slice selection method and apparatus | |
CN111240837B (en) | Resource allocation method, device, terminal and storage medium | |
WO2017186092A1 (en) | Network slice selection method and apparatus | |
KR20200012981A (en) | Network slice management methods, devices, and computer readable storage media | |
CN110268751A (en) | Method and system for selection access and mobile management function to ps domain in access net environment | |
CN108023938B (en) | Message sending method and server | |
JP6542899B2 (en) | Random access method, terminal and base station | |
CN109819477B (en) | A method for handling requests and corresponding entities | |
US20230283492A1 (en) | Traffic charging method, network device and storage medium | |
WO2021098369A1 (en) | System information sending method, network device, base station, and storage medium | |
KR102362244B1 (en) | Method and apparatus for transmitting and receiving data in mission-critical data communication system | |
CN109561403A (en) | A kind of short message dispatching method, equipment and storage medium | |
US20220038871A1 (en) | Charging method, apparatus, and system | |
CN107426109B (en) | Traffic scheduling method, VNF module and traffic scheduling server | |
US10740161B2 (en) | Broadcast message sending method and apparatus, and mobile terminal | |
US20230112127A1 (en) | Electronic device for deploying application and operation method thereof | |
CN110874314A (en) | Pressure measurement method, apparatus, device and medium | |
WO2021098730A1 (en) | Switching network congestion management method and apparatus, device, and storage medium | |
CN113626221B (en) | Message enqueuing method and device | |
WO2019109902A1 (en) | Queue scheduling method and apparatus, communication device, and storage medium | |
CN110620811B (en) | ONU management method and system under vOLT cluster architecture | |
US9647966B2 (en) | Device, method and non-transitory computer readable storage medium for performing instant message communication | |
CN115514708B (en) | Congestion control method and device | |
CN106209665A (en) | A kind of realize the method for load sharing, interface message processor (IMP), service processor and system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |