Message distribution method and related device

By maintaining a communication connection with the client on the server side and using different reliability reading methods according to the message level, the problem of delayed or lost message delivery during live broadcast is solved, and real-time and reliable transmission of messages is achieved.

CN118612469APending Publication Date: 2024-09-06TENCENT MUSIC ENTERTAINMENT TECH (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410664688.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-27
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

In Internet live broadcasts, delayed or lost message delivery will affect user experience. Existing technology results in poor real-time performance of message delivery, making it impossible to update the client in a timely manner.

Method used

When the server receives a message acquisition request from the client, it maintains the communication connection until there is a new message or the maximum connection time is exceeded, and uses different reliability reading methods to obtain and send messages according to the message level.

Benefits of technology

It improves the real-time and reliability of message sending, ensures that the client obtains new messages in a timely manner, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118612469A
    Figure CN118612469A
Patent Text Reader

Abstract

The embodiment of the invention provides a message distribution method and a related device, which are used for improving the real-time performance of a server for sending a message to a client. The method provided by the embodiment of the invention comprises the following steps: acquiring a message acquisition request sent by a client, wherein the message acquisition request carries an identification code of a message acquired last time; according to the type of the message, the level of the message in the message acquisition request is determined, and the level of the message is associated with the system operation state of the client; if it is determined that no new message exists in a preset message queue with the level corresponding to the level of the message according to the identification code, keeping communication connection with the client until the new message exists in the message queue with the corresponding level or the maximum communication connection time is exceeded; if a new message exists in the message queue of the corresponding level, the new message is acquired according to a message reading mode corresponding to the level of the message, and different message levels correspond to different reliability reading modes; and sending the new message to the client.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data communication technology, and in particular to a message distribution method and related devices. Background Art

[0002] In Internet live broadcast products, in order to liven up the atmosphere of the live broadcast room and increase user stickiness in watching live broadcasts, the server needs to send various interactive messages to the user terminal. These messages include: user barrage, expressions, likes, online number updates, gifts, red envelopes, etc. In addition, system and signaling messages such as live broadcast room status changes and live stream switching need to be sent to users. If these messages are delayed or lost during the sending process, it will directly affect the user's experience of watching live broadcasts, and in serious cases it may even cause abnormalities in the live broadcast room.

[0003] A common method of sending messages is for the client to request new messages from the server at regular intervals. However, this method means that the new message will be sent to the client only when the server receives the client's request, which results in poor real-time performance in sending new messages. Summary of the invention

[0004] The embodiment of the present invention provides a message distribution method and related devices, which are used for the server to maintain a communication connection with the client when receiving a message acquisition request from the client, so that when the server has a new message, the new message can be sent to the client in time, thereby improving the real-time performance of message sending.

[0005] A first aspect of an embodiment of the present application provides a message distribution method, which is applied to a server, and the method includes:

[0006] Obtain a message acquisition request sent by the client, wherein the message acquisition request carries an identification code of the last message acquired;

[0007] Determining a level of the message in the message acquisition request according to the type of the message, wherein the level of the message is associated with a system operation state of the client;

[0008] If it is determined according to the identification code that there is no new message in the preset message queue of the level corresponding to the level of the message, then maintaining the communication connection with the client until there is a new message in the message queue of the corresponding level or the maximum communication connection time is exceeded;

[0009] If there is a new message in the message queue of the corresponding level, the new message is obtained according to the reliability reading method corresponding to the level of the message, wherein different message levels correspond to different reliability reading methods;

[0010] The new message is sent to the client.

[0011] A second aspect of an embodiment of the present application provides a message distribution method, which is applied to a server, and the method includes:

[0012] Receive the message writing request sent by the client;

[0013] Determining a level of a message in the message writing request according to a type of the message, wherein the level of the message is associated with a system operation state of the client;

[0014] According to the level of the message, the message in the message writing request is written into a preset message queue of the corresponding level.

[0015] A third aspect of an embodiment of the present application provides a server, including a processor, which, when executing a computer program stored in a memory, is used to implement the message distribution method provided in the first aspect or the second aspect of the embodiment of the present application.

[0016] The fourth aspect of the embodiments of the present application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it is used to implement the message distribution method provided by the first aspect or the second aspect of the embodiments of the present application.

[0017] The fifth aspect of the embodiments of the present application provides a computer program product having a computer program / instruction stored thereon. When the computer program / instruction is executed by a processor, it is used to implement the message distribution method provided in the first aspect or the second aspect of the embodiments of the present application.

[0018] It can be seen from the above technical solutions that the embodiments of the present invention have the following advantages:

[0019] In an embodiment of the present application, a server obtains a message acquisition request sent by a client, wherein the message acquisition request carries an identification code of a message obtained last time; the level of the message in the message acquisition request is determined according to the type of the message, wherein the level of the message is associated with the system operating status of the client; if, according to the identification code, it is determined that there is no new message in a message queue of a level preset corresponding to the level of the message, the communication connection with the client is maintained until there is a new message in the message queue of the corresponding level or the maximum communication connection time is exceeded; if there is a new message in the message queue of the corresponding level, the new message is obtained according to the message reading method corresponding to the level of the message, wherein different message levels correspond to different reliability reading methods; and the new message is sent to the client.

[0020] Because the embodiment of the present application can determine the level of the message after the server receives the message acquisition request from the client, and based on the identification code in the message acquisition request, when there is no new message in the message queue of the corresponding level, maintain the communication connection with the client until there is a new message in the message queue of the corresponding level, thereby improving the real-time performance of the client obtaining new messages from the server.

[0021] On the other hand, the embodiment of the present application divides messages into different levels in advance according to the type of message, and adopts different reliability reading methods according to the level of the message, obtains new messages from message queues of different levels, and sends the obtained new messages to the client. That is, the embodiment of the present application adopts different reliability reading methods for messages of different levels, thereby achieving a balance between the real-time and reliability of the client obtaining new messages. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 This is a schematic diagram of the architecture of the message distribution system in the embodiment of the present application;

[0023] Figure 2 A schematic diagram of an embodiment of a method for distributing messages in an embodiment of the present application;

[0024] Figure 3 This is another schematic diagram of an embodiment of the method for distributing messages in an embodiment of the present application;

[0025] Figure 4 A schematic diagram of obtaining a new message from a first-level message queue in an embodiment of the present application;

[0026] Figure 5 A schematic diagram of obtaining a new message from a second-level message queue or a third-level message queue in an embodiment of the present application;

[0027] Figure 6 A schematic diagram of a circular queue in an embodiment of the present application;

[0028] Figure 7 This is another schematic diagram of an embodiment of the method for distributing messages in an embodiment of the present application;

[0029] Figure 8 A schematic diagram of an unreadable area in a circular queue in an embodiment of the present application;

[0030] Fig. 9 A schematic diagram of obtaining a new message when the sequence code is located in the unreadable area of ​​the first-level circular message queue in an embodiment of the present application;

[0031] Fig.10 This is a schematic diagram of an embodiment of the present application in which the sequence code is located in the readable area of ​​the second-level or third-level circular message queue;

[0032] Fig.11 A schematic diagram of obtaining a new message when the sequence code is located in an unreadable area of ​​a second-level or third-level circular message queue in an embodiment of the present application;

[0033] Fig.12 This is another schematic diagram of an embodiment of the method for distributing messages in an embodiment of the present application;

[0034] Fig.13 A schematic diagram of writing a message into a message queue set in a database in an embodiment of the present application;

[0035] Fig.14 A schematic diagram of writing a message into a message queue set in a memory in an embodiment of the present application. DETAILED DESCRIPTION

[0036] The embodiment of the present invention provides a message distribution method and related devices, which are used for a server to maintain a communication connection with the client when it receives a message acquisition request from a client, if there is no new message in the server, so that when the server has a new message, the new message can be sent to the client in time, thereby improving the real-time performance of message sending.

[0037] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0038] The terms "first", "second", "third", "fourth", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0039] The embodiment of the present application provides a method for message distribution, the general principle of which is as follows: when a message acquisition request sent by a client is obtained, wherein the message acquisition request carries an identification code of the message obtained last time, the level of the message in the message acquisition request is determined according to the type of the message, if it is determined according to the identification code that there is no new message in the message queue of the level corresponding to the level of the message, then the communication connection with the client is maintained until there is a new message in the message queue of the corresponding level or the maximum communication connection time is exceeded, if there is a new message in the message queue of the corresponding level, then the new message is obtained according to the reliability reading method corresponding to the level of the message, wherein different message levels correspond to different reliability reading methods, and the new message is sent to the client. The message distribution method provided by the present application can maintain the communication connection with the client after the server receives the message acquisition request sent by the client, when there is no new message in the pre-set message queue, and send the acquired new message to the client in a timely manner when there is a new message in the server, thereby improving the real-time performance of the server sending messages to the client.

[0040] On the other hand, the embodiment of the present application divides messages into different levels according to the type of message, and messages of different levels are stored in message queues of different levels. For messages of different levels, different reliability reading methods are used to obtain new messages from the message queue, thereby further achieving a balance between message real-time and reliability.

[0041] In order to better implement the above-mentioned message distribution method, the present application embodiment provides a message distribution system, please refer to Figure 1 , Figure 1 A schematic diagram of the architecture of a message distribution system provided for an embodiment of the present application, the message distribution system includes at least two clients 101 and a server 102, different types of applications can be installed on the client 101, such as an instant messaging application, a live broadcast application, a conference communication application, etc., the client 101 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart car, etc. The server 102 can be used to store application data and image data generated by different types of applications of the client 101. The server 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms, etc.

[0042] Among them, the above-mentioned message distribution method is executed by the server 102. When the server 102 receives a message acquisition request sent by the client 101, the server 102 determines the level of the message in the message acquisition request according to the type of the message, and according to the identification code carried in the message acquisition request, if it is determined that there is no new message in the pre-set message queue corresponding to the message level, then the communication connection with the client is maintained until there is a new message in the message queue of the corresponding level or the maximum communication connection time is exceeded. If there is a new message in the message queue of the corresponding level, the new message is obtained according to the reliability reading method corresponding to the level of the message, and the new message is sent to the client.

[0043] Based on the message distribution system and message distribution method provided above, please refer to Figure 2 , Figure 2 A schematic diagram of an embodiment of a message distribution method provided in an embodiment of the present application, wherein the message distribution method is executed by a server, and the message distribution method includes:

[0044] 201. Obtain a message acquisition request sent by a client, where the message acquisition request carries an identification code of the last message acquired;

[0045] In the live broadcast scenario, the client hosting the live broadcast and the client watching the live broadcast generally interact through the server. During the live broadcast, in order to liven up the atmosphere of the live broadcast room or increase the stickiness of users watching the live broadcast, the client hosting the live broadcast and the client watching the live broadcast need to interact. For example, the client hosting the live broadcast sends gifts or red envelopes to the clients watching the live broadcast, and the clients watching the live broadcast can also send user barrages, likes or gifts to the client hosting the live broadcast. Regardless of whether it is the client hosting the live broadcast or the client watching the live broadcast, when exchanging messages, one party first sends the message to the server for storage, and the other party obtains the message from the server.

[0046] Of course, in addition to the client hosting the live broadcast and the client watching the live broadcast being able to interact through messages, the server will also send some system messages to the client hosting the live broadcast and the client watching the live broadcast. For example, the server sends a system message about the number of online users updated to the client hosting the live broadcast, and sends a system message about the status change of the live broadcast room to the client watching the live broadcast.

[0047] Specifically in the embodiments of the present application, the client in the present application can be a client for hosting a live broadcast or a client for watching a live broadcast, as long as the client has the need to obtain messages from the server.

[0048] In an embodiment of the present application, a server obtains a message acquisition request sent by a client, wherein the message acquisition request carries an identification code of a message obtained last time. Specifically, the identification code in the embodiment of the present application only needs to uniquely identify each message. The identification code here can be a serial code, a hash code, or a graphic identification code, etc. There is no specific restriction on the type of the identification code here.

[0049] 202. Determine a level of the message according to the type of the message in the message acquisition request, wherein the level of the message is associated with a system operation status of the client;

[0050] When the server receives a message acquisition request from the client, it determines the level of the message according to the type of message to be acquired. The message level in the embodiment of the present application is related to the system operation status of the client. For example, the first-level messages are of the highest importance, and the client must ensure that they are received, otherwise it will affect the client's system operation status. The first-level messages here can be system messages and signaling messages in the live broadcast room. Once the first-level messages are lost, it may cause abnormalities in the live broadcast room. The second-level messages are second in importance, and messages of this level are not allowed to be lost by the client. Once lost, it may cause user complaints, such as paid gifts, etc. The third-level messages are the least important, and messages of this level are allowed to be lost, such as barrage, likes and other types of messages.

[0051] It should be noted that the above three message levels are only illustrative illustrations of message classification, and are not limitations on the classification levels. In actual application scenarios, messages can also be divided into 2 levels, 4 levels or 5 levels, etc. There is no specific limitation on the message classification levels here.

[0052] 203. If it is determined that there is no new message in the message queue of the preset level corresponding to the level of the message according to the identification code, the communication connection with the client is maintained until there is a new message in the message queue of the corresponding level or the maximum communication connection time is exceeded;

[0053] In the prior art, when a client sends a message acquisition request to a server, if there is no new message in the server, the client disconnects the communication connection with the server and sends a message acquisition request to the server again after a certain time interval, resulting in the client being unable to obtain the latest message in the server in real time.

[0054] To address this issue, the server in an embodiment of the present application determines that there are no new messages in the message queue of the corresponding level based on the identification code of the message acquisition request, and maintains a communication connection with the client until there are new messages in the message queue of the corresponding level, or the communication connection time between the server and the client is greater than the preset maximum communication connection time.

[0055] Because the embodiment of the present application can maintain a communication connection with the client when there is no new message in the message queue of the corresponding level until there is a new message in the message queue of the corresponding level, thereby ensuring the real-time nature of the client obtaining messages from the server.

[0056] It is easy to understand that in the embodiment of the present application, different levels of message queues are pre-set for messages of different levels to store messages of different levels. For example, when the messages are classified into three levels, three message queues are pre-set, respectively for storing messages of the three levels.

[0057] 204. If there is a new message in the message queue of the corresponding level, the new message is obtained according to the reliability reading method corresponding to the level of the message, wherein different message levels correspond to different reliability reading methods;

[0058] If there is a new message in the message queue of the corresponding level, the embodiment of the present application obtains the new message according to the reliability reading method corresponding to the message level, wherein messages of different levels correspond to different reliability reading methods. For example, when the message level is the first level, it corresponds to the highest level reliability reading method, and when the message level is the second level or the third level, it corresponds to the message reading method with the second lowest reliability.

[0059] 205. Send the new message to the client.

[0060] When a new message of a corresponding level is obtained from a message queue of a corresponding level according to different reliability reading methods, the new message of the corresponding level is sent to the client.

[0061] In an embodiment of the present application, a message acquisition request sent by a client is obtained, the message acquisition request carries an identification code of a last acquired message; the level of the message in the message acquisition request is determined according to the type of the message, wherein the level of the message is associated with the system operation status of the client; if, according to the identification code, it is determined that there is no new message in a message queue of a level pre-set to correspond to the level of the message, the communication connection with the client is maintained until there is a new message in the message queue of the corresponding level or the maximum communication connection time is exceeded; if there is a new message in the message queue of the corresponding level, the new message is obtained according to a reliability reading method corresponding to the level of the message, wherein different message levels correspond to different reliability reading methods; and the new message is sent to the client.

[0062] Because the embodiment of the present application can determine the level of the message after the server receives the message acquisition request from the client, and based on the identification code in the message acquisition request, when there is no new message in the message queue of the corresponding level, maintain the communication connection with the client until there is a new message in the message queue of the corresponding level, thereby improving the real-time performance of the client obtaining new messages from the server.

[0063] On the other hand, the embodiment of the present application divides messages into different levels in advance according to the type of message, and adopts different reliability reading methods according to the level of the message, obtains new messages from message queues of different levels, and sends the obtained new messages to the client. That is, the embodiment of the present application adopts different reliability reading methods for messages of different levels, thereby achieving a balance between the real-time and reliability of the client obtaining new messages.

[0064] Figure 2 In the embodiment, the message queue of the server can be set in the database or in the memory of the server. The following describes the message distribution method when the message queue is set at the above different addresses:

[0065] 1. The message queue is set in the database

[0066] See also Figure 3 , Figure 3 Another embodiment of the message distribution method:

[0067] 301. Obtain a message acquisition request sent by the client, where the message acquisition request carries a sequence code of the last message acquired;

[0068] Specifically, the message queue of the embodiment of the present application is set in the database. In order to facilitate the convenient management of the message queue in the database, the embodiment of the present application adopts a serial code as a specific identification code, and the serial code here is numbers or letters arranged in sequence.

[0069] 302. Determine a level of the message according to the type of the message in the message acquisition request, wherein the level of the message is associated with a system operation status of the client;

[0070] Specifically, the embodiment of the present application divides messages into different levels according to different message types. For example, the first level messages include system messages that ensure the normal operation of the client, the second level messages include user messages that do not allow the client to lose, and the third level messages include user messages that allow the client to lose.

[0071] Therefore, the server can determine the level of the message according to the message type in the message acquisition request sent by the client. For example, when the message type obtained is a system message to ensure the normal operation of the client's live broadcast room, such as the number of online people in the live broadcast room, then this type of message is a first-level message; when the message type obtained is a reward gift, then this type of message is a second-level message; and when the message type obtained is a free gift, then this type of message is a third-level message.

[0072] In a specific live broadcast scenario, in order to facilitate the classification of messages according to their types, a correspondence table between message types and message levels can be pre-set in the server, and the messages can be quickly and accurately graded according to the correspondence table.

[0073] Of course, the correspondence table between message types and message levels is only one way to determine the message level based on the message type. The correspondence between the message type and the message level can also be determined by other methods. Therefore, the AI ​​model, etc., does not make specific restrictions on the method of determining the message level based on the message type.

[0074] 303. If it is determined according to the sequence code that there is no new message in the message queue of the preset level corresponding to the message level, the communication connection with the client is maintained until there is a new message in the message queue of the corresponding level or the maximum communication connection time is exceeded;

[0075] If the message to be obtained in the message acquisition request is of the first level, and if there is no new message in the first level message queue, the server maintains the communication connection with the client until there is a new message in the first level message queue, or the connection time between the server and the client exceeds the preset maximum communication connection time (the maximum communication connection time here is the fixed communication time set in advance by the user, such as 1 minute or 2 minutes, etc.).

[0076] Similarly, when the message level is the second level or the third level, if there is no new message in the second level message queue or the third level message queue, the server also maintains the communication connection with the client until there is a new message in the second level message queue or the third level message queue or the maximum communication connection time is exceeded.

[0077] Furthermore, the embodiments of the present application can also set different maximum communication connection times according to the type of message. For example, when the message is at the first level, the first maximum communication connection time is set, and when the message is at the second level, the second maximum communication connection time is set, and when the message is at the third level, the third maximum communication connection time is set, wherein the first maximum communication connection time>the second maximum communication connection time>the third maximum communication connection time.

[0078] 304. If there is a new message in the first-level message queue, determine the position of the sequence code in the first-level message queue according to the sequence code, where the position of the sequence code is used to represent the position of the last message read;

[0079] Because the server stores messages in a message queue, and the messages in the message queue are arranged according to sequence codes, and the message acquisition request sent by the client carries the sequence code of the last message acquired, the server can determine the location where the message was last read based on the sequence code of the last message acquired, and execute step 305 from the location where the message was last read.

[0080] 305. Starting from the position where the message was read last time, obtain new messages in the direction in which the messages were written.

[0081] In order to ensure that the first level of messages can be obtained, the embodiment of the present application obtains new messages from the location where the message was read last time according to the writing direction of the message.

[0082] Of course, when acquiring new messages here, a preset number of new messages may be acquired, or all new information may be acquired. There is no specific restriction on the number of new messages acquired here.

[0083] For ease of understanding, Figure 4 A schematic diagram is given for obtaining new messages from the location where the message was last read in the direction in which the message was written.

[0084] 306. Send the new message to the client, and at the same time send the maximum sequence code of the new message obtained to the client, where the maximum sequence code is used to represent the sequence code of the message obtained by the client last time;

[0085] After acquiring a new message, the embodiment of the present application sends the new message to the client, and at the same time sends the maximum sequence code of the acquired new message to the client, where the maximum sequence code is used to represent the sequence code of the message acquired by the client last time.

[0086] As in Figure 4 In the example, the sequence codes of the new message are sequence code 3 to sequence code 11. In addition to sending messages 3 to 11 to the client, the present application also sends sequence code 11 to the client, so that the client uses position 11 as the sequence code of the last message read.

[0087] 307. If the position of the sequence code cannot be determined in the first-level message queue according to the sequence code, all messages are obtained in the first-level message queue starting from the first message in the direction in which the messages are written.

[0088] Because the sequence code may be tampered with during the transmission process, when the position of the sequence code cannot be determined in the first-level message queue based on the sequence code, in order to ensure that all new messages can be obtained, the embodiment of the present application starts from the first message in the first-level message queue and obtains all messages in the direction in which the messages are written.

[0089] 308. Send all messages to the client, and at the same time send the maximum sequence code in all messages to the client, where the maximum sequence code is used to represent the sequence code of the message last obtained by the client;

[0090] After all messages are obtained, all messages are sent to the client, and at the same time, the maximum sequence code in all messages is sent to the client, wherein the maximum sequence code is used to represent the sequence code of the message obtained by the client last time.

[0091] As in Figure 4 In the example, messages 1 to 11 are all sent to the client, and sequence code 11 is also sent to the client, so that the client uses position 11 as the position where the message was last read.

[0092] 309. If there is a new message in the second-level message queue or the third-level message queue, determine the position of the sequence code in the second-level message queue or the third-level message queue according to the sequence code, and the position of the sequence code is used to represent the position of the last message read;

[0093] Because the server stores the messages in the message queue, and the messages in the message queue are arranged according to the sequence code, and the message acquisition request sent by the client carries the sequence code of the last message acquired, the server can determine the location where the message was last read based on the sequence code of the last message acquired to execute step 310.

[0094] 310. Starting from the latest message position in the second-level message queue or the third-level message queue, obtain new messages in the reverse direction of the message writing until the position of the sequence code is reached.

[0095] Different from the first level message, when the message is of the second level or the third level, the embodiment of the present application starts from the latest message position in the second level message queue or the third level message queue, and obtains new messages in the reverse direction of the message writing until the position of the sequence code.

[0096] For ease of understanding, Figure 5 A schematic diagram of a method for acquiring new messages in a second-level message queue or a third-level message queue is provided. Because the importance of second-level messages and third-level messages is less important than that of first-level messages, when acquiring new messages from a second-level message queue or a third-level message queue, the embodiment of the present application obtains new messages from Figure 5 At position 11 in the sequence code, read the new message in the opposite direction of the message writing until the position of the sequence code (that is, position 2 where the message was read last time).

[0097] This way of acquiring messages ensures that the latest messages are acquired first each time, thus avoiding the problem of cumulative delays when messages are sent too frequently.

[0098] 311. Send a new message to the client, and also send the maximum sequence code of the new message obtained to the client, wherein the maximum sequence code is used to represent the sequence code of the message obtained by the client last time.

[0099] In an embodiment of the present application, after obtaining a new message in a message queue of different levels, the new message is sent to the client, and the maximum sequence code of the new message is also sent to the client, so that the client uses the maximum sequence code as the sequence code of the message obtained last time.

[0100] As in Figure 5 In the example, the sequence code 11 is sent to the client, so that the client uses the sequence code 11 as the sequence code of the message obtained last time.

[0101] In the embodiment of the present application, on the one hand, the message queue is set in the database, and when the database performs concurrent read and write operations on the same message queue, a transaction isolation mechanism is adopted to ensure that only read operations or write operations can occur on the same message queue at the same time, thereby avoiding reading invalid dirty data when read and write operations are concurrent; on the other hand, the embodiment of the present application adopts different message acquisition methods for messages of different levels. For example, for messages of the first level, the first level message queue adopts the method of starting from the position of the serial number and obtaining new messages in the direction of message writing in the first level message queue, and when the position of the serial number cannot be found, all messages are obtained from the position of the first message, thereby ensuring that all new messages can be obtained, and for messages of the second or third level, the corresponding level message queue starts from the latest message position and obtains new messages in the opposite direction of message writing, so that the latest message is obtained first each time, thereby avoiding the problem of message accumulation delay when the message sending frequency is too fast, that is, the embodiment of the present application adopts different reliability reading methods for messages of different levels, thereby achieving a balance between message real-time performance and message reliability.

[0102] 2. The message queue is set in memory

[0103] Because when the message queue is stored in the database, when the client frequently requests the database, it will cause a high load on the database. To address this problem, the embodiment of the present application further sets the message queue in the memory. Because the storage space in the memory is limited, the embodiment of the present application can set the message queue in the memory as a ring queue. For ease of understanding, Figure 6A schematic diagram of a ring queue is given, wherein when the storage of the message in the ring queue in the embodiment of the present application overflows, it is allowed to perform overwriting from the starting position of the ring queue, that is, Figure 6 When the message is stored at position 8, the overwrite can be restarted from position 1.

[0104] It should be noted that when the message queue is set in the memory, the embodiment of the present application mainly utilizes the feature of the circular queue that can be written over and over. Of course, if the message queue is still set as a linear storage queue, but if the linear message queue is set to support overwrite writing when the storage overflows, then the linear message queue is also within the protection scope of the present application.

[0105] Because messages of different levels generally involve different sending frequencies, such as first-level messages generally have a lower sending frequency, while second-level and third-level messages have a higher sending frequency, the embodiments of the present application can also set storage spaces of different sizes in the memory corresponding to the sending frequency of the messages, such as setting a smaller storage space for low-frequency first-level messages, and setting a larger storage space for high-frequency second-level and third-level messages.

[0106] See also Figure 7 , Figure 7 A schematic diagram of another embodiment of a method for message distribution is shown below:

[0107] 701. Obtain a message acquisition request sent by a client, where the message acquisition request carries a sequence code of a message obtained last time;

[0108] Specifically, the message queue of the embodiment of the present application is set in the memory. In order to facilitate the convenient management of the message queue in the memory, the embodiment of the present application also adopts a serial code as a specific identification code, and the serial code here is numbers or letters arranged in sequence.

[0109] 702. Determine a level of the message according to the type of the message in the message acquisition request, wherein the level of the message is associated with a system operation status of the client;

[0110] 703. If it is determined according to the sequence code that there is no new message in the preset message queue of the level corresponding to the message level, the communication connection with the client is maintained until there is a new message in the message queue of the corresponding level or the maximum communication connection time is exceeded;

[0111] It should be noted that the description of step 702 to step 703 is similar to the description of step 302 to step 303, and will not be repeated here.

[0112] 704. If there is a new message in the first-level message queue and there is a message being written in the first-level message queue, obtain the parameter of the last write position, and determine the current write end position according to the parameter of the last write position and the number of written messages;

[0113] Because when messages are stored in memory, the memory needs to support high concurrency scenarios, that is, for message queues at the same level, it may be necessary to perform both the operation of writing messages and the operation of reading messages. When the operation of reading messages and the operation of writing messages are concurrent, the read operation may cause invalid dirty data to be read. To address this issue, the embodiment of the present application can also obtain the parameters of the last write position when there are new messages in the first-level message queue and there are messages being written in the first-level message queue at the same time, and determine the local write end position based on the parameters of the last write position and the number of messages written, so as to execute step 705 based on the last write position and the local write end position.

[0114] It should be noted that generally a parameter is specially set in the message queue to store the parameters of each write position.

[0115] 705. According to the direction of message writing, the area between the last writing position and the current writing end position is set as an unreadable area;

[0116] When the last write position and the local write end position are determined in step 704, the area between the last write position and the current write end position is set as an unreadable area according to the writing direction of the message.

[0117] For ease of understanding, Figure 8 A schematic diagram of setting an unreadable area in a ring message queue according to the last write position and the current write end position is given.

[0118] 706. If the sequence code is located in the readable area of ​​the first-level message queue, start from the end position of this write or the last write position, and search for the position of the sequence code, where the position of the sequence code is used to represent the position of the last message read; from the position of the sequence code, obtain a new message in the direction of message writing until the last write position.

[0119] If the sequence code (that is, the position of the last message read) is located in the readable area of ​​the first-level message queue, the position of the sequence code is searched starting from the current write end position or the last write position.

[0120] Furthermore, because the message queue has a ring structure, when searching for the sequence code position starting from the local write end position, the sequence code position can be searched in the direction of message writing. When searching for the sequence code position starting from the last write end position, the sequence code position is searched in the reverse direction of message writing. This can improve the efficiency of searching for the sequence code position.

[0121] When the sequence code position is found, the new message is obtained according to the writing direction of the message until the last writing position, that is, Figure 8 In the example, the data is read from position 2 to position 5.

[0122] 707. If the sequence code is located in the unreadable area of ​​the first-level message queue, starting from the current write end position, new messages are obtained in the direction of message writing until the last write position.

[0123] If the sequence code is located in the unreadable area of ​​the first-level message queue, assuming that the end position of this write is Fig. 9 As shown, it is located at position 3, and the sequence code (the last read position) is located at position 2. Starting from the end position of this write (that is, position 3), new messages are obtained in the direction of message writing until the last write position, that is, position 5.

[0124] In steps 705 to 707 of the embodiment of the present application, in a scenario where the memory supports concurrent reading and writing, the area between the last write position and the current write end position is set as an unreadable area, and when the sequence code (that is, the last read position) is located in the unreadable area or the readable area, new messages are obtained in different ways, thereby ensuring the validity of the data read by the first-level message queue in the scenario of concurrent reading and writing.

[0125] 708. If there is a new message in the second-level or third-level message queue, and there is a message being written in the second-level or third-level message queue, obtain the parameter of the last write position, and determine the current write end position according to the parameter of the last write position and the number of written messages;

[0126] Similar to step 704, when there are new messages in the second-level or third-level message queue and there are messages being written in the second-level or third-level message queue at the same time, the parameters of the last write position are also obtained, and the end position of this write is determined based on the parameters of the last write position and the number of written messages.

[0127] 709. According to the direction of message writing, the area between the last writing position and the current writing end position is set as an unreadable area;

[0128] Similar to step 705, in order to avoid the situation where the message read is invalid dirty data when performing read operations and write operations in the same message queue at the same time, after the embodiment of the present application determines the last write position and the end position of this write in step 704, the area between the last write position and the end position of this write is set to an unreadable area according to the direction of message writing.

[0129] 710. If the sequence code is located in the readable area of ​​the second-level message queue or the third-level message queue, the position of the sequence code is searched in the second-level message queue or the third-level message queue according to the sequence code, and the position of the sequence code is used to indicate the position of the last message read;

[0130] When the sequence code (and the position where the message was last read) is located in the second-level message queue or the third-level message queue, the position of the sequence code is searched in the second-level message queue or the third-level message queue according to the sequence code.

[0131] For ease of understanding, Fig.10 A schematic diagram is given in which the sequence code is located in the readable area in the second-level or third-level message queue.

[0132] 711. In the second-level message queue or the third-level message queue, starting from the last write position, obtain new messages in the reverse direction of the message write until the position of the sequence code.

[0133] Different from the first-level message queue, after the position of the sequence code is determined in the second-level message queue or the third-level message queue, new messages are obtained in the reverse direction of the message writing starting from the end position of this writing until the position of the sequence code is reached.

[0134] As in Fig.10 In the example, it starts from position 5 and obtains new messages in the reverse direction of the message writing until position 2.

[0135] It should be noted that in the process of obtaining new messages, you can start from position 5 and obtain a preset number of new messages (such as 1 or 2), or you can obtain all new messages (such as reading directly from position 5 to position 2). There is no specific limit on the number of messages obtained at a single time.

[0136] 712. If the sequence code is located in the unreadable area of ​​the second-level message queue or the third-level message queue, starting from the last write position, new messages are obtained in the reverse direction of the message write until the current write end position.

[0137] If the sequence code is located in the unreadable area of ​​the second-level message queue or the third-level message queue, new messages are obtained starting from the last write position in the reverse direction of the message write until the current write end position.

[0138] Specifically in Fig.11 In the example, if the end position of this write is position 3 and the sequence code is at position 2, then starting from the last write position, a new message is obtained in the reverse direction of the message writing until the end position of this write, that is, starting from position 5, a new message is obtained in the reverse direction of the message writing until position 3, that is, the message at position 4 is read.

[0139] 713. Send the new message to the client, and also send the maximum sequence code of the new message obtained to the client, where the maximum sequence code is used to represent the sequence code of the message obtained by the client last time;

[0140] After reading a new message in the message queue, the new message is sent from the client, and the maximum sequence code of the new message is sent to the client at the same time, wherein the sequence code here is used to represent the sequence code of the message obtained by the client last time.

[0141] As in step 712, because the message at position 4 is sent to the client, the embodiment of the present application also sends sequence code 4 to the client, so that the client uses sequence code 4 as the sequence code of the message obtained last time.

[0142] In the embodiment of the present application, on the one hand, the message queue is set in the memory, and the reading speed and writing speed of the memory data are relatively fast compared to the database. Therefore, compared with setting the message queue in the database, the embodiment of the present application improves the message reading speed and writing data;

[0143] On the other hand, in order to solve the problem of limited memory space, the embodiment of the present application sets the message queue as a ring queue, so that when the message in the ring queue overflows, an overwrite write is performed, thereby realizing the reuse of the memory space;

[0144] Furthermore, the embodiments of the present application also adopt different message acquisition methods for messages of different levels. For example, for messages of the first level, when the sequence code is located in the readable area, new messages are acquired in the direction of message writing starting from the position of the sequence code until the last write position, and when the sequence code is located in the unreadable area, new messages are acquired in the direction of message writing starting from the end position of this write until the last write position, thereby ensuring the reliability of first-level message acquisition. For messages of the second or third level, when the sequence code is located in the readable area, new messages are acquired in the reverse direction of message writing starting from the last write position until the position of the sequence code, and when the sequence code is located in the unreadable area, new messages are acquired in the reverse direction of message writing starting from the end position of this write until the last write position, thereby avoiding the problem of message accumulation delay when the message sending frequency is too fast. That is, the embodiments of the present application adopt different reliability reading methods for messages of different levels, thereby achieving a balance between message real-time performance and message reliability.

[0145] against Figure 2 , Figure 3 or Figure 7 In the embodiment of the present invention, after the server sends the acquired new message to the client, if the server receives a message acquisition request sent by the client again, in order to avoid bringing a high load to the server due to the client frequently sending message acquisition requests to the server, the embodiment of the present application can also perform the following steps to implement a server adaptive flow control mechanism:

[0146] Specifically, after the server sends the acquired new message to the client, if it acquires the message acquisition request sent by the client again, it counts the current load status of the server; calculates the response waiting time of the server according to the current load status of the server; after the response waiting time, it determines whether there is a new message in the server.

[0147] In order to avoid the server frequently responding to the client's message acquisition request, which causes a high load problem on the server, when the embodiment of the present application receives the client's message acquisition request again:

[0148] 1. Count the current load status of the server;

[0149] For example, if the number of message acquisition requests processed by the server in a unit time is counted regularly (for example, every 10 minutes) (that is, the QPS of the server is counted regularly), in order to prevent the QPS counted regularly from fluctuating greatly, a smoothing algorithm (such as the EMA algorithm or the MA algorithm) can be used to smooth the QPS counted regularly. Specifically, the process of smoothing the QPS using the EMA algorithm is as follows:

[0150] QPS avg =β*QPS pre +(1-β)*QPS current

[0151] Among them, QPS avg is the smoothed QPS value, QPS pre is the average QPS calculated in the previous period, QPS current is the QPS value collected in the current period, β is the attenuation factor, 0<β<1.

[0152] Furthermore, in order to evaluate the current load status of the server, in addition to calculating the QPS of the server according to the smoothing algorithm avg In addition to the data, we can also further calculate the maximum QPS number that the server can theoretically carry. For the convenience of description, the maximum QPS number that the server can theoretically carry is recorded as QPS max ,in:

[0153] QPS max =N*qps;

[0154] N is the number of cores of the server, and qps is the number of message retrieval requests that can be processed by a single core of the server.

[0155] 2. Calculate the server response waiting time based on the server's current load status;

[0156] Specifically, when calculating the server response waiting time, it can be calculated according to the following formula:

[0157]

[0158] Where t is the response waiting time, t max is the preset maximum waiting time, α is the start factor, where 0<α<1.

[0159] 3. After the response waiting time, determine whether there is any new message in the server.

[0160] After the server calculates the response waiting time, if t>0, it will wait for t time and then determine whether there is a new message in the server. If t<0, it will immediately determine whether there is a new message in the server.

[0161] In an embodiment of the present application, when the server receives two consecutive message acquisition requests sent by the client, the server calculates its current load status and automatically adjusts the client's response waiting time based on the current load status, thereby realizing an adaptive mechanism for client traffic and avoiding the high load problem caused by the client frequently sending message acquisition requests.

[0162] Further, based on Figure 2 , Figure 3 or Figure 7 In the embodiment of the present application, when the server sends a new message to the client, because the screen sizes of the clients are different, the number of messages displayed per unit time on different clients is also different. If the server sends a fixed number of messages to the client each time, the message display of some clients may be limited. To address this problem, the client in the embodiment of the present application may also be locally provided with a message cache queue, wherein the message cache queue is used to store new messages. Figure 2 , Figure 3 or Figure 7 In the embodiment, when the client sends a message acquisition request to the server, the message acquisition request may also carry the client's display frequency f for new messages and the message data n stored in the message cache queue, and when the server sends a new message to the client, the following steps may be performed:

[0163] Using the response waiting time t calculated in the above embodiment, the client's display frequency f of new messages and the message data n stored in the message cache queue, the preset number count of new messages sent to the client is calculated, and the preset number of new messages is sent to the client.

[0164] Specifically, when calculating the preset number count, the following formula may be used for calculation:

[0165] Count=t*fn

[0166] It should be noted that the above formula is only one way to calculate the preset number count according to t, f and n. The above formula can also be transformed to obtain the preset number count:

[0167] For example, Count = t*f-γn, where γ is the adjustment coefficient of n;

[0168] As long as the preset number count is calculated based on t, f and n, it is within the protection scope of this application.

[0169] In an embodiment of the present application, the client's waiting response time t, the client's display frequency f of new messages and the message data n stored in the message cache queue are used to calculate the preset number count of new messages sent to the client each time, and the preset number count is a dynamically adjusted value, so that according to each client's display frequency of new messages and the message data n stored in each client's message cache queue, a preset number of new messages is sent to the client on demand, thereby achieving precise control of the number of messages sent and improving the user experience of the user end when using the client.

[0170] The above method describes in detail the process of the client sending a message acquisition request to the server. The following describes the process of the client sending a message write request to the server in the message distribution method. Fig.12 , another embodiment of a message distribution method, comprising:

[0171] 1201. Receive a message writing request sent by a client;

[0172] Specifically, in an embodiment of the present application, before the server writes the received message into the message queue, it needs to first receive a message write request sent by the client, and write the corresponding message into the message queue of the corresponding level pre-set by the server according to the message write request.

[0173] 1202. Determine the level of the message in the message writing request according to the type of the message, wherein the level of the message is associated with the system operation status of the client;

[0174] After receiving the message writing request, the server further determines the level of the message according to the type of the message in the message writing request, wherein the level of the message is associated with the system operation status of the client;

[0175] Specifically, when the message type is a system message to ensure the normal operation of the client's live broadcast room, this type of message is a first-level message, and when the message type is a message that does not allow the client to lose, such as a gift given at one's own expense, this type of message is a second-level message, and when the obtained message type is a message that allows loss to occur, such as a free gift, this type of message is a third-level message.

[0176] Specifically, when determining the message level according to the message type, it can be based on a pre-set correspondence table or other methods, such as an AI model, etc. There is no specific restriction on the method of determining the message level according to the message type.

[0177] 1203. According to the level of the message, write the message in the message write request into a preset message queue of the corresponding level.

[0178] After obtaining the level of the message, the message in the message write request is written into a preset message queue of the corresponding level. For example, when the message is at the first level, it is written into the first level message queue, and when the message is at the second level, it is written into the second level message queue, and so on.

[0179] In an embodiment of the present application, message queues of different levels are preset in advance, so that messages of different levels can be stored in message queues of different levels, thereby providing a basis for obtaining messages of different levels from message queues of different levels at a later stage.

[0180] based on Fig.12 In the embodiment, message queues of different levels can be set in a database or in the memory of a server. The following describes the process of writing a message in a message write request into a preset message queue of a corresponding level according to the level of the message when the message queues are set at different addresses:

[0181] 1. The message queue is set in the database;

[0182] When the message queue is set in the database, after the server determines the level of the message in the message write request, the server obtains the parameters of the last write position in the message queue of the corresponding level, and determines the last write position in the message queue of the corresponding level based on the parameters of the last write position; starting from the last write position, the message in the message write request is written to the message queue of the corresponding level.

[0183] For ease of understanding, the following distance description:

[0184] Assumptions Fig.13 The message queue in is set in the database. Before writing a new message to the message queue, the server first obtains the last write position parameter from the message queue and determines the last write position according to the last write parameter position. Assuming that the last write position is 5, Fig.12 In the process, new messages are written starting from position 5 along the direction of the message queue.

[0185] It should be noted that when the message queue is set in the database, the transaction isolation mechanism can be used to ensure concurrent write operations on the message queue. For example, when two threads exist at the same time, Fig.12 When performing a write operation in a message queue, generally one thread's write operation is executed first. After the write operation of one thread is completed, another thread is allowed to perform a write operation, thereby ensuring that there will be no confusion when performing concurrent write operations in the message queue.

[0186] 2. The message queue is set in memory;

[0187] In order to avoid the problem of high load on the database caused by frequent client access to the database, the present application can also set the message queue in the memory. Because the read and write speed of the memory is faster than performing read and write operations in the database, the embodiment of the present application sets the message queue in the memory, which can improve the speed and efficiency of writing messages in the message queue.

[0188] Although the memory has a faster reading speed than the database, the storage space of the memory is limited. Therefore, the embodiment of the present application further sets the message queue in the memory in a ring queue, and when the storage of the messages in the ring queue overflows, it is allowed to perform overwrite writing from the starting position of the ring queue, thereby realizing the reuse of the memory space and solving the problem of limited memory storage space.

[0189] When the message queue is set in the memory, after determining the level of the message in the message write request, the server obtains the parameters of the last write position in the message queue of the corresponding level; according to the parameters of the last write position, the last write position is determined in the message queue of the corresponding level; starting from the last write position, the messages in the message write request are sequentially written to the message queue of the corresponding level to obtain the end position of this write operation; the parameters of the last write position are updated to the end position parameters of this write operation through the atomic operation of CAS comparison and exchange.

[0190] Because the memory needs to support scenarios with high concurrency in reading and writing, the embodiment of the present application obtains the parameters of the last write position in the message queue of the corresponding level after determining the level of the message in the message write request, and determines the last write position in the message queue of the corresponding level based on the parameters of the last write position; starting from the last write position, the messages in the message write request are sequentially written to the message queue of the corresponding level to obtain the end position of this write operation.

[0191] Specifically, in the process of writing messages sequentially to the message queue of the corresponding level, because the circular queue performs overwrite writing, in order to quickly obtain the write position of the message, the write position of the message can be quickly determined by taking the modulus of the message subscript and the queue length.

[0192] As in Fig.14 In the example, if the circular message queue is full, the write position of the 12th message can be obtained by the following calculation: take 12 and 8 modulo to get the remainder 4, then position 4 is the write position of the 12th message.

[0193] In addition, for the circular queue, the embodiment of the present application also needs to support concurrent scenarios of multiple write operations. Therefore, when the embodiment of the present application updates the last write position parameter to the current write end position parameter, the CAS (Compare and Swap) atomic operation can be used to update the last write position parameter to the current write end position parameter.

[0194] Specifically when performing CAS atomic operations:

[0195] The server first obtains the current value in the memory and compares the current value with the expected value. If they are equal, the new value is written to the memory address to complete the update operation. If they are not equal, it means that other threads have modified the value of the memory address. At this time, it is necessary to re-read the current value and perform the comparison and update operation again until success.

[0196] Among them, the advantage of CAS atomic operation is that it avoids the overhead and thread blocking caused by using the lock mechanism and improves concurrency performance.

[0197] Because when the embodiment of the present application sets the message queue in the memory, the concurrency problem caused by multiple write operations can be solved through CAS atomic operations, and the CAS atomic operation can avoid the overhead and thread blocking problems caused by the use of the lock mechanism in the prior art, thereby improving the concurrency performance.

[0198] An embodiment of the present application also provides a computer program product having a computer program / instruction stored thereon, which, when executed by a processor, is used to implement the message distribution method described in the above method embodiment.

[0199] Next, the computer device in the embodiment of the present invention is described from the perspective of hardware processing:

[0200] The computer device is used to implement the function of the server. In an embodiment of the present invention, an embodiment of the computer device includes:

[0201] Processor and memory;

[0202] When the memory is used to store a computer program and the processor is used to execute the computer program stored in the memory, the message distribution method described in the above method embodiment can be implemented.

[0203] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, and a cloud server. The computer device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that a processor and a memory are merely examples of computer devices and do not constitute a limitation of the computer device. The computer device may include more or fewer components, or a combination of certain components, or different components. For example, the computer device may also include input and output devices, network access devices, buses, and the like.

[0204] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the computer device, and uses various interfaces and lines to connect various parts of the entire computer device.

[0205] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the computer device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created according to the use of the terminal, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0206] The present invention also provides a computer-readable storage medium, which is used to implement the functions of a server and stores a computer program. When the computer program is executed by a processor, the processor can implement the message distribution method described in the above method embodiment.

[0207] It is understandable that if the above-mentioned message distribution method is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a corresponding computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned corresponding embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0208] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A message distribution method, characterized in that: Applied to a server, the method comprises: Obtain a message acquisition request sent by the client, wherein the message acquisition request carries an identification code of the last message acquired; Determining a level of the message according to the type of the message in the message acquisition request, wherein the level of the message is associated with a system operation state of the client; If it is determined according to the identification code that there is no new message in the preset message queue of the level corresponding to the level of the message, then maintaining the communication connection with the client until there is a new message in the message queue of the corresponding level or the maximum communication connection time is exceeded; If there is a new message in the message queue of the corresponding level, the new message is obtained according to the reliability reading method corresponding to the level of the message, wherein different message levels correspond to different reliability reading methods; The new message is sent to the client.

2. The method according to claim 1, characterized in that If the preset message queue is stored in the database, the level of the message includes a first level, wherein the first level message includes a system message to ensure the normal operation of the client, and the identification code includes a sequence code; If there is a new message in the first level message queue, obtaining the new message in a reliability reading mode corresponding to the first level includes: If there is a new message in the first-level message queue, determine the position of the sequence code in the first-level message queue according to the sequence code, and the position of the sequence code is used to represent the position of the last message read; Starting from the position where the message was read last time, new messages are obtained in the direction in which the messages are written.

3. The method according to claim 2, characterized in that The method further comprises: If the position of the sequence code cannot be determined in the first-level message queue according to the sequence code, all messages are obtained in the first-level message queue starting from the first message in the direction in which the messages are written; Send all messages to the client.

4. The method according to claim 1, characterized in that: If the preset message queue is stored in the database, the level of the message includes a second level and a third level, wherein the second level message includes a message that does not allow the client to have a loss behavior, and the third level message includes a message that allows the client to have a loss behavior, and the identification code includes a sequence code; If there is a new message in the second-level message queue or the third-level message queue, the new message is obtained according to the message reading method corresponding to the second level or the reliability reading method corresponding to the third level, including: If there is a new message in the second-level message queue or the third-level message queue, determine the position of the sequence code in the second-level message queue or the third-level message queue according to the sequence code, and the position of the sequence code is used to represent the position of the last message read; Starting from the latest message position in the second-level message queue or the third-level message queue, the new message is acquired in the reverse direction of the message writing until the position of the sequence code is reached.

5. The method according to claim 1, characterized in that If the preset message queue is stored in the memory, the message queue is set as a ring message queue, wherein when the storage of messages in the ring message queue overflows, overwriting is allowed from the starting position of the ring message queue, and the identification code includes a sequence code.

6. The method according to claim 5, characterized in that If the level of the message in the message acquisition request is the first level, if there is a new message in the first level message queue, acquiring the new message in a reliability reading mode corresponding to the first level includes: If there is a new message in the first-level message queue, and there is also a message being written in the first-level message queue, then the parameter of the last write position is obtained, and the current write end position is determined according to the parameter of the last write position and the number of written messages; According to the direction of message writing, the area between the last writing position and the current writing end position is set as an unreadable area; If the sequence code is located in the readable area of ​​the first-level message queue, starting from the current writing end position or the last writing position, the position of the sequence code is searched, wherein the position of the sequence code is used to represent the position of the last message read; From the position of the sequence code, the new message is obtained according to the direction of message writing until the last writing position.

7. The method according to claim 6, characterized in that The method further comprises: If the sequence code is located in the unreadable area of ​​the first-level message queue, the new message is obtained starting from the current writing end position in the direction of message writing until the last writing position.

8. The method according to claim 5, characterized in that If the level of the message is the second level or the third level, if there is a new message in the second level message queue or the third level message queue, obtaining the new message in a reliability reading mode corresponding to the second level or the third level includes: If there is a new message in the second-level or third-level message queue, and there is a message being written in the second-level or third-level message queue at the same time, then the parameter of the last write position is obtained, and the current write end position is determined according to the parameter of the last write position and the number of written messages; According to the direction of message writing, the area between the last writing position and the current writing end position is set as an unreadable area; If the sequence code is located in the readable area of ​​the second-level message queue or the third-level message queue, searching for the position of the sequence code in the second-level message queue or in the third-level message queue according to the sequence code, the position of the sequence code being used to represent the position of the last message read; In the second-level message queue or the third-level message queue, starting from the last writing position, the new message is acquired in the reverse direction of the message writing until the position of the sequence code.

9. The method according to claim 8, characterized in that The method further comprises: If the sequence code is located in the unreadable area of ​​the second-level message queue or the third-level message queue, the new message is obtained starting from the last write position in the reverse direction of the message write until the current write end position.

10. The method according to any one of claims 6 to 9, characterized in that After acquiring the new message, the method further includes: The maximum sequence code of the acquired new message is sent to the client, wherein the maximum sequence code is used to represent the identification code of the message acquired by the client last time.

11. The method according to claim 1, characterized in that: After sending the new message to the client, the method further includes: If the message acquisition request sent by the client is obtained again, the current load status of the server is counted; Calculating the response waiting time of the server according to the current load status of the server; After the response waiting time, it is determined whether there is a new message in the server.

12. The method according to claim 11, characterized in that The current load status of the statistics server includes: Obtain the number of message acquisition requests processed by the server per unit time; A smoothing algorithm is used to perform smoothing processing on the number of message requests processed by the server within a unit time, so as to obtain an average number of message acquisition requests processed by the server within a unit time.

13. The method according to claim 12, characterized in that Calculating the response waiting time of the server according to the current load status of the server, including: Get the number of core processors of the server; Calculate the maximum number of message acquisition requests that can be processed by the server within a unit time according to the number of core processors of the server and the number of message acquisition requests that can be processed by a single core processor of the server within a unit time; The response waiting time is calculated according to an average number of message acquisition requests processed by the server within a unit time and a maximum number of message acquisition requests that can be processed by the server within a unit time.

14. The method according to claim 11, characterized in that The client is locally provided with a message cache queue, wherein the message cache queue is used to store new messages; The message acquisition request also carries the display frequency of the new message by the client and the number of messages stored in the message cache queue; The method further comprises: Calculate a preset number of new messages to be sent to the client according to the response waiting time, the display frequency of the new message by the client, and the number of messages stored in the message cache queue; The sending of the new message to the client comprises: The preset number of new messages are sent to the client.

15. A message distribution method, characterized in that: Applied to a server, the method comprises: Receive the message writing request sent by the client; Determining a level of a message in the message writing request according to a type of the message, wherein the level of the message is associated with a system operation state of the client; According to the level of the message, the message in the message writing request is written into a preset message queue of the corresponding level.

16. The method according to claim 15, characterized in that If the preset message queue is stored in the database, writing the message in the message write request into the message queue of the corresponding level according to the level of the message includes: Get the parameters of the last written position in the message queue of the corresponding level; Determining the last write position in the message queue of the corresponding level according to the parameter of the last write position; Starting from the last written position, the message in the message write request is written into the message queue of the corresponding level.

17. The method according to claim 15, characterized in that If the preset message queue is stored in the memory, the message queue is set as a ring message queue, wherein when the messages in the ring message queue overflow, overwriting is allowed to be performed from the starting position of the ring message queue.

18. The method according to claim 17, characterized in that Writing the message in the message write request into a message queue of a corresponding level according to the level of the message includes: Get the parameters of the last written position in the message queue of the corresponding level; Determining the last write position in the message queue of the corresponding level according to the parameter of the last write position; Starting from the last write position, the messages in the message write request are sequentially written into the message queue of the corresponding level to obtain the end position of this write operation; The parameters of the last write position are updated to the end position parameters of this write operation through the atomic operation of CAS comparison and exchange.

19. A server, comprising a processor, characterized in that: When executing the computer program stored in the memory, the processor is configured to implement the message distribution method according to any one of claims 1 to 14, or any one of claims 15 to 18.

20. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it is used to implement the message distribution method according to any one of claims 1 to 14, or any one of claims 15 to 18.

21. A computer program product having a computer program / instructions stored thereon, characterized in that: The computer program / instructions, when executed by a processor, are used to implement the message distribution method as described in any one of claims 1 to 14, or any one of claims 15 to 18.