Event message processing method, device, electronic device and readable storage medium

By writing event messages to the message queue and processing them in sequence, the problem of multiple game clients simultaneously modifying public data latency is solved, achieving lower latency and higher concurrency game performance.

CN111282263BActive Publication Date: 2024-08-30BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202010140390.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-03
Publication Date
2024-08-30
Estimated Expiration
2040-03-03

AI Technical Summary

Technical Problem

In multiplayer real-time interactive games, when multiple game clients modify public data at the same time, frequent locking and unlocking operations lead to increased game latency and affect performance.

Method used

Write event messages into the message queue that belongs to the game client, and process and send response messages according to the writing order of the message queue, avoiding locking and unlocking operations, and using message dispatch threads, consumer threads, and sending threads to process messages respectively. Event messages in the queue.

Benefits of technology

It reduces game latency, improves the response speed and concurrency capabilities of multiple game clients, and reduces the burden on the CPU caused by lock conflicts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111282263B
    Figure CN111282263B
Patent Text Reader

Abstract

The embodiment of the present invention provides a method, device, electronic device and readable storage medium for processing event messages, which are applied to a game server, including: writing a received event message into a message queue associated with a game room, reading the first event message to be processed from the message queue, processing the event message to be processed, obtaining a response message corresponding to the event message to be processed, and sending a response message to a game client belonging to the game room. Applying the technical solution provided by the embodiment of the present invention, event messages sent by multiple game clients belonging to a game room can be written into a message queue pre-created for the game room, and then these event messages are processed one by one, and the response messages obtained after processing are sent to the above-mentioned multiple game clients, driving these multiple game clients to update the game screen, replacing the locking and unlocking operations, thereby reducing the delay of the game.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of product application technology, and in particular to a method, device, electronic device and readable storage medium for processing event messages. Background Art

[0002] For multiplayer real-time interactive games, the game client sends an interaction instruction. After receiving the interaction instruction, the game server responds to the interaction instruction, obtains a response message, and sends the response message to the client so that the client can update the game screen.

[0003] When multiple game clients send multiple interactive instructions for a piece of public data at the same time, they usually add a mutex lock to the public data to avoid conflicts. For example, when game client A and game client B request to modify the same piece of public data at the same time, game client A can add a mutex lock to the public data when modifying it to prevent game client B from modifying it. When the mutex lock added by game client A is released, game client B can continue to modify the public data.

[0004] However, when a large number of game clients modify this public data at the same time, multiple locking and unlocking operations need to be performed during the processing, which may cause some game clients to wait for a long time, affecting performance indicators such as game latency. Summary of the invention

[0005] The purpose of the embodiments of the present invention is to provide a method, device, electronic device and readable storage medium for processing event messages, so as to solve the problem of long response delay when multiple game clients send event messages at the same time. The specific technical solution is as follows:

[0006] In a first aspect, an embodiment of the present invention provides a method for processing an event message, which is applied to a game server, comprising:

[0007] After receiving an event message sent by a game client, writing the event message into a message queue associated with a game room to which the game client belongs, the event message being generated by the game client based on the received interactive operation;

[0008] According to the writing order of each event message contained in the message queue, read the event message written first from the message queue as the event message to be processed;

[0009] Processing the event message to be processed to obtain a response message corresponding to the event message to be processed;

[0010] The response message is sent to the game client belonging to the game room.

[0011] Furthermore, writing the event message into a message queue associated with the game room to which the game client belongs includes:

[0012] Determine whether there is an unread event message in the position pointed to by the write pointer in the message queue associated with the game room to which the game client belongs;

[0013] If it does not exist, write the event message to the location pointed to by the write pointer.

[0014] Further, if the event message does not exist, after writing the event message to the location pointed to by the write pointer, the method further includes:

[0015] Determine whether the position pointed to by the write pointer is the last position of the message queue;

[0016] If yes, change the position pointed by the write pointer to the first position of the message queue;

[0017] If not, the position pointed to by the write pointer is moved back one position in the message queue.

[0018] Further, the reading the event message written first from the message queue as the event message to be processed according to the writing order of the event messages contained in the message queue includes:

[0019] Determine whether there is an unread event message at the position pointed to by the read pointer in the message queue;

[0020] If there is an unread event message, the event message at the position pointed to by the read pointer is read as the event message to be processed.

[0021] Furthermore, if there is an unread event message, after reading the event message at the position pointed to by the read pointer as the event message to be processed, the method further includes:

[0022] Determine whether the position pointed to by the read pointer is the last position of the message queue;

[0023] If so, change the position pointed to by the read pointer to the first position of the message queue;

[0024] If not, the position pointed to by the read pointer is moved back one position in the message queue.

[0025] Furthermore, the method further comprises:

[0026] If there is no unread event message, after waiting for a preset time, the step of determining whether there is an unread event message at the position pointed to by the read pointer in the message queue is performed again; or

[0027] If there is no unread event message, the position pointed to by the read pointer is changed to the first position of the message queue of another game room.

[0028] Furthermore, before sending the response message to the game client belonging to the game room, the method further includes:

[0029] Detecting whether the time interval between the current time and the last synchronization time of the game room is greater than or equal to a preset time interval, wherein the last synchronization time is the time when a response message was last sent to a game client belonging to the game room;

[0030] If not, wait until the time interval between the current moment and the last synchronization time is greater than or equal to the preset time interval, and then execute the step of sending the response message to the game client belonging to the game room.

[0031] Furthermore, writing the event message into a message queue associated with the game room to which the game client belongs includes:

[0032] Using a pre-created message dispatching thread, the event message is written into a message queue associated with the game room to which the game client belongs;

[0033] The step of reading the event message written first from the message queue as the event message to be processed according to the writing order of the event messages contained in the message queue comprises: using a pre-created message consumption thread to read the event message written first from the message queue as the event message to be processed according to the writing order of the event messages contained in the message queue;

[0034] The processing of the event message to be processed to obtain a response message corresponding to the event message to be processed includes: using the message consumption thread to process the event message to be processed to obtain a response message corresponding to the event message to be processed;

[0035] The sending the response message to the game client belonging to the game room includes: sending the response message to the game client belonging to the game room by using a pre-created message sending thread.

[0036] In a second aspect, an embodiment of the present invention provides an event message processing device, which is applied to a game server, including:

[0037] A writing unit, configured to write, after receiving an event message sent by a game client, the event message into a message queue associated with a game room to which the game client belongs, wherein the event message is generated by the game client based on a received interactive operation;

[0038] A reading unit, configured to read the event message written first from the message queue as the event message to be processed according to the writing order of the event messages contained in the message queue;

[0039] A processing unit, configured to process the event message to be processed and obtain a response message corresponding to the event message to be processed;

[0040] A sending unit is used to send the response message to the game client belonging to the game room.

[0041] Furthermore, the writing unit is specifically used to determine whether there is an unread event message in the position pointed to by the write pointer in the message queue associated with the game room to which the game client belongs, and if not, write the event message to the position pointed to by the write pointer.

[0042] Furthermore, the write unit is also used to determine whether the position pointed to by the write pointer is the last position of the message queue, and if so, change the position pointed to by the write pointer to the first position of the message queue, and if not, move the position pointed to by the write pointer back one position in the message queue.

[0043] Furthermore, the reading unit is specifically used to determine whether there is an unread event message in the position pointed to by the read pointer in the message queue, and if there is an unread event message, read the event message in the position pointed to by the read pointer as the event message to be processed.

[0044] Furthermore, the reading unit is also used to determine whether the position pointed to by the read pointer is the last position of the message queue, and if so, change the position pointed to by the read pointer to the first position of the message queue, and if not, move the position pointed to by the read pointer back one position in the message queue.

[0045] Furthermore, the reading unit is also used to, if there is no unread event message, wait for a preset period of time and then again execute the step of determining whether there is an unread event message at the position pointed to by the read pointer in the message queue; or if there is no unread event message, change the position pointed to by the read pointer to the first position of the message queue of another game room.

[0046] Furthermore, the sending unit is also used to detect whether the time interval between the current moment and the previous synchronization time of the game room is greater than or equal to a preset time interval before sending the response message to the game client belonging to the game room, wherein the previous synchronization time is the time when a response message was last sent to the game client belonging to the game room, and if not, wait until the time interval between the current moment and the previous synchronization time is greater than or equal to the preset time interval, and then execute the step of sending the response message to the game client belonging to the game room.

[0047] Furthermore, the writing unit is specifically used to write the event message into a message queue associated with the game room to which the game client belongs by using a pre-created message dispatching thread;

[0048] The reading unit is specifically configured to use a pre-created message consumption thread to read the first event message written from the message queue according to the writing order of the event messages contained in the message queue as the event message to be processed;

[0049] The processing unit is specifically used to process the pending event message by using the message consumption thread to obtain a response message corresponding to the pending event message;

[0050] The sending unit is specifically configured to send the response message to the game client belonging to the game room by using a pre-created message sending thread.

[0051] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0052] Memory, used to store computer programs;

[0053] The processor is used to implement any step of the method for processing event messages when executing the program stored in the memory.

[0054] In a fourth aspect, an embodiment of the present invention provides a readable storage medium, wherein the readable storage medium stores a computer program, and when the computer program is executed by a processor, any step of the method for processing event messages is implemented.

[0055] In a fifth aspect, an embodiment of the present invention further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-mentioned event message processing methods.

[0056] An event message processing method, device, electronic device and readable storage medium provided by an embodiment of the present invention are applied to a game server. After receiving an event message sent by a game client, the event message is written into a message queue associated with a game room to which the game client belongs. The event message is generated by the game client based on the received interactive operation, and according to the writing order of the event messages contained in the message queue, the first event message written is read from the message queue as the event message to be processed, and the event message to be processed is processed to obtain a response message corresponding to the event message to be processed, and a response message is sent to the game client belonging to the game room to drive the game client to update the game screen.

[0057] By applying the technical solution provided by the embodiment of the present invention, event messages sent by multiple game clients belonging to a game room can be written into a message queue pre-created for the game room, and then these event messages can be processed one by one, and the response messages obtained after processing can be sent to the above-mentioned multiple game clients, driving these multiple game clients to update the game screen, replacing the locking and unlocking operations, thereby reducing the game delay.

[0058] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0060] Figure 1 A first flow chart of a method for processing event messages provided by an embodiment of the present invention;

[0061] Figure 2 A schematic diagram of creating a game room for a game server provided by an embodiment of the present invention;

[0062] Figure 3 A flow chart of writing event messages provided by an embodiment of the present invention;

[0063] Figure 4 A schematic diagram of a message queue provided by an embodiment of the present invention;

[0064] Figure 5 A flow chart of reading event messages provided by an embodiment of the present invention;

[0065] Figure 6A second flow chart of the method for processing event messages provided by an embodiment of the present invention;

[0066] Figure 7 A signaling diagram of a method for processing event messages provided by an embodiment of the present invention;

[0067] Figure 8 A schematic diagram of the structure of a game server provided by an embodiment of the present invention;

[0068] Fig. 9 A schematic diagram of the structure of an event message processing device provided by an embodiment of the present invention;

[0069] Fig.10 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0070] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions 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 are within the scope of protection of the present invention.

[0071] The embodiments of the present invention disclose a method, device, electronic device and readable storage medium for processing event messages, which are described in detail below.

[0072] like Figure 1 As shown, Figure 1 The flowchart of the method for processing event messages provided by the embodiment of the present invention, which can be applied to a game server, comprises the following steps:

[0073] Step 11, after receiving the event message sent by the game client, write the event message into the message queue associated with the game room to which the game client belongs.

[0074] Step 12: Read the event message written first from the message queue according to the writing order of the event messages contained in the message queue as the event message to be processed.

[0075] Step 13: Process the event message to be processed and obtain a response message corresponding to the event message to be processed.

[0076] Step 14: Send a response message to the game client belonging to the game room.

[0077] Using the above Figure 1The method for processing event messages shown in the figure may allow multiple game clients to belong to a game room. Event messages sent by multiple game clients belonging to a game room may be written into a message queue pre-created for the game room, and then these event messages may be processed one by one, and response messages obtained after processing may be sent to the multiple game clients, driving these multiple game clients to update the game screen, thereby replacing the locking and unlocking operations and reducing the game latency.

[0078] like Figure 2 As shown, Figure 2 A schematic diagram of a game server creating a game room provided by an embodiment of the present invention. Taking three game clients as an example, there are three game clients belonging to the game room, namely game client 1, game client 2 and game client 3. These three game clients send matching requests to the matching server, and the matching requests carry the ID (Identity Document) of the game client. After the matching server matches the above three game clients based on the matching requests, it generates a matching message, and the matching message includes the ID of the above three game clients. The matching server sends the matching message to the Netty server, and the Netty server routes the matching message to the game server 1 in the game server cluster through a random algorithm. After receiving the matching message, the game server 1 creates a game room for the above three game clients.

[0079] After the game room is created, optionally, a message queue associated with the game room can be created for the game room. Optionally, the message queue can also be pre-existing. After the game room is created, the message queue associated with the game room is selected from the unoccupied existing message queues. Furthermore, the association relationship between the game room and the message queue can be maintained by establishing an association information table.

[0080] In one embodiment, the above event message may be generated by the game client based on the received interactive operation. Optionally, after receiving the interactive operation, the game client encapsulates the interactive event responding to the interactive operation into an event message.

[0081] In one embodiment of the present application, after receiving the event message sent by the game client, the event message is written into the message queue associated with the game room to which the game client belongs (step 11), such as Figure 3 As shown, further, the following steps may be included:

[0082] Step 31, determining whether there is an unread event message in the position pointed to by the write pointer in the message queue associated with the game room to which the game client belongs.

[0083] The message queue associated with the game room to which the game client belongs contains multiple locations. Each location in the message queue can be used to store event messages. The game server can write received event messages in each location of the message queue, and can also read event messages stored in each location of the message queue when necessary. Optionally, the location that the write pointer initially points to is the first position of the message queue, that is, the location of the first event message written into the message queue is the first position of the message queue.

[0084] Determine whether there is an unread event message in the position pointed to by the write pointer in the message queue. If yes, execute step 32; if no, execute step 33. Figure 4 As shown, Figure 4 A schematic diagram of a message queue provided for an embodiment of the present invention, wherein the length of the message queue is 5, and the positions in the message queue are marked as 0, 1, 2, 3, and 4 from left to right, respectively. The position initially pointed to by the write pointer is the first position of the message queue, that is, the position marked as 0. It is determined whether there is an unread message in the position marked as 0. If so, execute step 32; if not, execute step 33.

[0085] Step 32, after waiting for the first time period, execute step 31 again;

[0086] The first duration may be set according to actual needs, and when there is an unread event message in the position pointed to by the write pointer in the message queue, the game server waits for the first duration and executes step 31 again. For example, when there is an unread event message in the position pointed to by the write pointer in the message queue, the game server waits for 10 milliseconds, and again determines whether there is an unread event message in the position pointed to by the write pointer in the message queue, and repeats this process until the unread event message is read by the game server.

[0087] Step 33, write the event message to the location pointed by the write pointer;

[0088] When there is no unread event message in the position pointed to by the write pointer in the message queue, the game server writes the event message to the position pointed to by the write pointer.

[0089] Step 34, determine whether the position pointed to by the write pointer is the last position of the message queue;

[0090] The game server determines whether the position pointed to by the write pointer is the last position of the message queue. Optionally, if it is the last position of the message queue, execute step 35; if it is not the last position of the message queue, execute step 36. Figure 4For example, determine whether the position pointed to by the write pointer is the last position of the message queue, that is, determine whether the position pointed to by the write pointer is the position marked as 4. If it is the position marked as 4, execute step 35; if it is not the position marked as 4, execute step 36.

[0091] Step 35, change the position pointed by the write pointer to the first position of the message queue;

[0092] When the write pointer points to the last position in the message queue, the game server changes the write pointer to the first position. Figure 4 For example, if the position pointed to by the write pointer is the position marked as 4, the game server changes the position pointed to by the write pointer to the position marked as 0.

[0093] Step 36, shift the position pointed by the write pointer back one position in the message queue.

[0094] When the position pointed by the write pointer is not the end of the message queue, the game server moves the position pointed by the write pointer back one position in the message queue to Figure 4 For example, if the position pointed to by the write pointer is the position marked as 1, the game server moves the position pointed to by the write pointer back one position in the message queue and changes it to the position marked as 2.

[0095] use Figure 3 The illustrated embodiment can avoid the problem that the game server writes a newly received event message to the position pointed to by the write pointer in the message queue when the event message has not been read yet, resulting in event message overwriting and thus missing the event message.

[0096] In one embodiment of the present application, the above step of reading the first event message written from the message queue as the event message to be processed according to the writing order of each event message contained in the message queue (step 12), such as Figure 5 As shown, further, the following steps may be included:

[0097] Step 51, determining whether there is an unread event message at the position pointed to by the read pointer in the message queue.

[0098] A message queue is pre-created for the game room. The position in the message queue is used by the game server to write and read event messages. Optionally, the position initially pointed to by the read pointer is the first position of the message queue. It is determined whether there is an unread event message in the position pointed to by the read pointer in the message queue. If there is, step 52 is executed. Figure 4 For example, the position initially pointed to by the read pointer is the first position of the message queue, that is, the position marked as 0. It is determined whether there is an unread message in the position marked as 0. If so, step 52 is executed.

[0099] Step 52: read the event message at the position pointed to by the read pointer as the event message to be processed.

[0100] When there is an unread event message in the position pointed to by the read pointer in the message queue, the game server reads the event message in the position pointed to by the read pointer as the event message to be processed.

[0101] Step 53, determine whether the position pointed to by the read pointer is the last position of the message queue.

[0102] The game server determines whether the position pointed to by the read pointer is the last position of the message queue. If it is the last position of the message queue, step 54 is executed; if it is not the last position of the message queue, step 55 is executed. Figure 4 For example, determine whether the position pointed to by the read pointer is the last position of the message queue, that is, determine whether the position pointed to by the write pointer is the position marked as 4. If it is the position marked as 4, execute step 54; if it is not the position marked as 4, execute step 55.

[0103] Step 54, change the position pointed by the read pointer to the first position of the message queue.

[0104] When the read pointer points to the last position in the message queue, the game server changes the read pointer to the first position. Figure 4 For example, if the position pointed to by the read pointer is the position marked as 4, the game server changes the position pointed to by the read pointer to the position marked as 0.

[0105] Step 55, shift the position pointed by the read pointer backward by one position in the message queue.

[0106] When the position pointed by the read pointer is not the end of the message queue, the game server moves the position pointed by the read pointer back one position in the message queue to Figure 4 For example, if the position pointed to by the read pointer is the position marked as 1, the game server moves the position pointed to by the read pointer back one position in the message queue and changes it to the position marked as 2.

[0107] In one embodiment of the present application, with respect to the above-mentioned determination of whether there are unread event messages in the position pointed to by the read pointer in the message queue (step 51), if the result obtained is that there are no unread event messages, one implementation method is: the game server can wait for a preset period of time, and then execute the step of determining whether there are unread event messages in the position pointed to by the read pointer in the message queue again. For example, when there are no unread event messages in the position pointed to by the read pointer in the message queue, the game server waits for 5 milliseconds, and determines again whether there are unread event messages in the position pointed to by the read pointer in the message queue, and repeats this process until the game server writes the event message in the position pointed to by the read pointer in the message queue. By applying this implementation method, the writing status of event messages in the message queue can be detected in real time, and the event messages written by the game server can be read in a timely manner, thereby improving the response speed of the game server to event messages and reducing game delays;

[0108] Another implementation is: the game server can change the position pointed by the read pointer to the first position of the message queue of another game room. The game server pre-creates a game room list, which includes multiple game rooms. The game server can change the position pointed by the read pointer to the first position of the message queue of another game room. Applying this implementation, the game server can read the message queue of the next game room in the room list when all event messages in the message queue of one game room have been read, saving thread resources of the game server.

[0109] In one embodiment of the present application, before the step of sending a response message to the game client belonging to the game room (step 15), the following steps may also be included:

[0110] Detect whether the time interval between the current time and the last synchronization time of the game room is greater than or equal to a preset time interval, wherein the last synchronization time is the time when a response message was last sent to multiple game clients;

[0111] If not, wait until the time interval between the current moment and the last synchronization time is greater than or equal to the preset time interval, and then execute the step of sending response messages to multiple game clients.

[0112] like Figure 6 As shown, Figure 6 The flowchart of the method for processing event messages provided by the embodiment of the present invention, which can be applied to a game server, comprises the following steps:

[0113] Step 61, after receiving the event message sent by the game client, write the event message into the message queue associated with the game room to which the game client belongs.

[0114] The above event messages may be game start instructions, game pause instructions, certain specific operation instructions for the game screen, etc. sent by multiple game clients in a game room to the game server, and the embodiment of the present invention does not limit this. After matching, multiple game clients are assigned to the same game room. After receiving the event messages sent by the game clients, the game server writes the event messages to the message queue pre-created for the game room. This step can be combined with the above Figure 3 The steps shown are the same, please refer to the above Figure 3 Description.

[0115] Step 62: Read the event message written first from the message queue according to the writing order of the event messages contained in the message queue as the event message to be processed.

[0116] This step can be combined with the above Figure 5 The steps shown are the same, please refer to the above Figure 5 Description.

[0117] Step 63: Process the event message to be processed and obtain a response message corresponding to the event message to be processed.

[0118] The game server processes the event message to be processed and obtains a response message corresponding to the event message to be processed.

[0119] Step 64, detecting whether the time interval between the current time and the last synchronization time of the game room is greater than or equal to a preset time interval, wherein the last synchronization time is the time when a response message was last sent to a game client belonging to the game room; if it is greater than or equal to the preset time interval, executing step 65; if it is less than the preset time interval, executing step 66;

[0120] The game server stores the last synchronization time, which is the time when a response message was last sent to the game client belonging to the game room. The game server detects whether the time interval between the current time and the last synchronization time of the game room is greater than or equal to the preset time interval; for example, the last synchronization time stored in the game server is 9:30:09 am, and the game server obtains the current time as 9:30:11 am, and the preset time interval is 2 seconds. The game server detects that the time interval between the current time and the last synchronization time is 2 seconds, which is equal to the preset time interval, so step 65 is executed; the game server obtains the current time as 9:30:10 am, and detects that the time interval between the current time and the last synchronization time is 1 second, which is less than the preset time interval, so step 66 is executed.

[0121] Step 65: Send a response message to the game client belonging to the game room.

[0122] The game server simultaneously sends a response message to the multiple game clients belonging to the same game room. After receiving the response message, the game client updates the game screen based on the response message.

[0123] Step 66, wait, execute step 64, until the time interval between the current moment and the last synchronization time is greater than or equal to the preset time interval, execute step 65.

[0124] When the game server detects that the time interval between the current moment and the last synchronization time of the game room is less than the preset time interval, it waits for the preset time length, and again detects whether the time interval between the current moment and the last synchronization time of the game room is greater than or equal to the preset time interval, until the time interval between the current moment and the last synchronization time is greater than or equal to the preset time interval, the game server sends a response message to the multiple game clients belonging to the same game room.

[0125] In one embodiment of the present application, the length of the message queue is the product of the number of event messages sent per second by multiple game clients counted in a historical time period and the second time length.

[0126] For example, the game server counts that the average number of event messages sent per second by multiple game clients in a game room is 10 in one month, and the second duration is 2 seconds, so the length of the message queue is 20, that is, there are 20 positions in the message queue. The length of the message queue can be adjusted according to the historical data counted by the game server, saving the storage resources of the game server.

[0127] In one embodiment of the present application, the game server uses a pre-created message dispatching thread to write the event message into a message queue associated with the game room to which the game client belongs.

[0128] Optionally, the game server pre-creates a message dispatching thread, which can find the message queue in the game room corresponding to the ID of the game room in the room list according to the ID of the game room, and write the event messages sent by multiple game clients belonging to the game room into the message queue of the game room.

[0129] The game server uses the pre-created message consumption thread to read the first event message written from the message queue according to the writing order of the event messages contained in the message queue as the event message to be processed;

[0130] The game server pre-creates message consumption threads. The number of message consumption threads can be the number of CPU (Central Processing Unit) cores. The message consumption thread can be bound to a room list containing multiple game room IDs. The message consumption thread first reads the message queue in the game room corresponding to the first game room ID in the room list, and reads the event message from the message queue in the order of writing from first to last as the event message to be processed;

[0131] The game server uses the above message consumption thread to process the event message to be processed and obtains a response message corresponding to the event message to be processed;

[0132] The game server uses a pre-created message sending thread to send a response message to the game client belonging to the game room.

[0133] The game server uses a pre-created message sending thread to send response messages to multiple game clients.

[0134] The game server pre-creates a message sending thread, which sends response messages to multiple game clients belonging to the game room.

[0135] By adopting the method provided in the above embodiment, the task of sending response messages to multiple game clients can be assigned to the message sending thread to avoid affecting the response speed of the message consuming thread, and the CPU cache of the game server will no longer load the cache frequently due to lock conflicts, which can greatly increase the concurrency of the server and improve the cache hit efficiency.

[0136] Combination Figure 7 The signaling diagram shown further explains the method for processing event messages provided by the embodiment of the present invention, which includes the following steps:

[0137] Step 71, multiple game clients send event messages to the Netty server;

[0138] The Netty server establishes a TCP channel between the Netty server and multiple game clients, and messages can be sent and received through the TCP channel. Multiple game clients send event messages to the Netty server.

[0139] Step 72, the Netty server forwards the event message to the game server;

[0140] The Netty server stores the correspondence between the above-mentioned multiple game clients and game servers, and the Netty server sends the event message to the corresponding game server according to the correspondence.

[0141] Step 73, the game server uses a pre-created message dispatching thread to write the event message into a message queue created for the game room;

[0142] The game server pre-creates a message dispatch thread. After receiving event messages from multiple game clients, the game server uses the message dispatch thread to write the event messages into the message queue created for the game room. Figure 3 The steps shown are the same, and the specific description can refer to the above Figure 3 Description.

[0143] Step 74, the game server uses a pre-created message consumption thread to read the event message in the message queue to obtain the event message to be processed;

[0144] The embodiment of the present invention also provides Figure 8 The structural diagram of the game server described above, the game server pre-creates the number of CPU core message consumption threads through the Round Robin algorithm, each message consumption thread is bound to a room list, and the binding relationship between the message consumption thread and the room list can be obtained through Figure 8 Maintained by the room manager.

[0145] The room list includes at least one game room, and the message consumption thread bound to the game room is used to read the event message in the message queue to obtain the event message to be processed. Figure 5 The steps shown are the same, and the specific description can refer to the above Figure 5 Description.

[0146] Step 75, the game server uses the message consumption thread to process the pending event message and obtains a response message;

[0147] After receiving the pending event message, the game server uses the message consumption thread to process the pending event message and obtains a corresponding response message.

[0148] Step 76, the game server uses the message sending thread to send the response message to the Netty server;

[0149] The game server uses a pre-created message sending thread to send the above response message to the Netty server.

[0150] In step 77, the Netty server forwards the response message to multiple game clients.

[0151] The Netty server forwards the response message to multiple game clients through the above TCP channel.

[0152] Corresponding to the method for processing event messages, an embodiment of the present invention also provides a device for processing event messages. Fig. 9 As shown, Fig. 9 A schematic diagram of the structure of an event message processing device provided by an embodiment of the present invention. The device includes:

[0153] A writing unit 91 is used to write the event message sent by the game client into a message queue associated with the game room to which the game client belongs after receiving the event message sent by the game client, wherein the event message is generated by the game client based on the received interactive operation;

[0154] The reading unit 92 is used to read the first event message written from the message queue according to the writing order of each event message contained in the message queue as the event message to be processed;

[0155] A processing unit 93 is used to process the event message to be processed and obtain a response message corresponding to the event message to be processed;

[0156] The sending unit 94 is used to send a response message to the game client belonging to the game room.

[0157] Furthermore, the write unit 91 is specifically used to determine whether there is an unread event message in the position pointed to by the write pointer in the message queue associated with the game room to which the game client belongs, and if not, write the event message to the position pointed to by the write pointer.

[0158] Furthermore, the write unit 91 is also used to determine whether the position pointed to by the write pointer is the last position of the message queue, and if so, change the position pointed to by the write pointer to the first position of the message queue, and if not, move the position pointed to by the write pointer back one position in the message queue.

[0159] Furthermore, the reading unit 92 is specifically used to determine whether there is an unread event message in the position pointed to by the read pointer in the message queue, and if there is an unread event message, read the event message in the position pointed to by the read pointer as the event message to be processed.

[0160] Furthermore, the reading unit 92 is also used to determine whether the position pointed to by the read pointer is the last position of the message queue, and if so, change the position pointed to by the read pointer to the first position of the message queue, and if not, move the position pointed to by the read pointer back one position in the message queue.

[0161] Furthermore, the reading unit 92 is also used to, if there is no unread event message, wait for a preset period of time, and then again execute the step of determining whether there is an unread event message in the position pointed to by the read pointer in the message queue; or if there is no unread event message, change the position pointed to by the read pointer to the first position of the message queue of another game room.

[0162] Furthermore, the sending unit 94 is also used to detect whether the time interval between the current moment and the last synchronization time of the game room is greater than or equal to a preset time interval before sending a response message to the game client belonging to the game room, wherein the last synchronization time is the time when a response message was last sent to the game client belonging to the game room, and if not, wait until the time interval between the current moment and the last synchronization time is greater than or equal to the preset time interval, and then execute the step of sending a response message to the game client belonging to the game room.

[0163] Furthermore, the writing unit 91 is specifically used to write the event message into the message queue associated with the game room to which the game client belongs by using the pre-created message dispatching thread;

[0164] The reading unit 92 is specifically configured to use a pre-created message consumption thread to read the first event message written from the message queue according to the writing order of the event messages contained in the message queue as the event message to be processed;

[0165] The processing unit 93 is specifically used to process the event message to be processed by using the message consumption thread to obtain a response message corresponding to the event message to be processed;

[0166] The sending unit 94 is specifically configured to send a response message to the game client belonging to the game room by using a pre-created message sending thread.

[0167] Corresponding to the method for processing event messages, an embodiment of the present invention further provides an electronic device, such as Fig.10 As shown, it includes a processor 101, a communication interface 102, a memory 103 and a communication bus 104, wherein the processor 101, the communication interface 102, and the memory 103 communicate with each other through the communication bus 104.

[0168] Memory 103, used for storing computer programs;

[0169] The processor 101 is used to execute the program stored in the memory 103, and implements the following steps:

[0170] After receiving an event message sent by a game client, writing the event message into a message queue associated with a game room to which the game client belongs, the event message being generated by the game client based on the received interactive operation;

[0171] According to the writing order of each event message contained in the message queue, read the event message written first from the message queue as the event message to be processed;

[0172] Processing the event message to be processed to obtain a response message corresponding to the event message to be processed;

[0173] The response message is sent to the game client belonging to the game room.

[0174] By applying the technical solution provided by the embodiment of the present invention, event messages sent by multiple game clients belonging to a game room can be written into a message queue pre-created for the game room, and then these event messages can be processed one by one, and the response messages obtained after processing can be sent to the above-mentioned multiple game clients, driving these multiple game clients to update the game screen. Since there is no need to frequently perform locking and unlocking operations, the game delay is reduced.

[0175] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0176] The communication interface is used for communication between the above electronic device and other devices.

[0177] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0178] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0179] In another embodiment of the present invention, a readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, any step of the above-mentioned event message processing method is implemented.

[0180] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is run on a computer, the computer executes any event message processing method of the above embodiments.

[0181] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0182] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0183] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, electronic device, and readable storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.

[0184] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A method for processing an event message, characterized in that: Applied to game servers, including: After receiving an event message sent by a game client, writing the event message into a message queue associated with a game room to which the game client belongs, the event message being generated by the game client based on the received interactive operation; According to the writing order of each event message contained in the message queue, the event message written first is read from the message queue as the event message to be processed; wherein each event message contained in the message queue is: an interaction instruction sent by multiple game clients belonging to the same game room for the same public data; Processing the event message to be processed to obtain a response message corresponding to the event message to be processed; Sending the response message to the game client belonging to the game room; The step of reading the event message written first from the message queue as the event message to be processed according to the writing order of the event messages contained in the message queue comprises: using a pre-created message consumption thread to read the event message written first from the message queue as the event message to be processed according to the writing order of the event messages contained in the message queue; The processing of the event message to be processed to obtain a response message corresponding to the event message to be processed includes: using the message consumption thread to process the event message to be processed to obtain a response message corresponding to the event message to be processed; Each message consumption thread is bound to a room list, and a room list includes at least one game room.

2. The method according to claim 1, characterized in that The step of writing the event message into a message queue associated with the game room to which the game client belongs includes: Determine whether there is an unread event message in the position pointed to by the write pointer in the message queue associated with the game room to which the game client belongs; If it does not exist, write the event message to the location pointed to by the write pointer.

3. The method according to claim 2, characterized in that If the event message does not exist, after writing the event message to the location pointed to by the write pointer, the method further includes: Determine whether the position pointed to by the write pointer is the last position of the message queue; If yes, change the position pointed by the write pointer to the first position of the message queue; If not, the position pointed to by the write pointer is moved back one position in the message queue.

4. The method according to any one of claims 1 to 3, characterized in that: The step of reading the event message written first from the message queue according to the writing order of the event messages contained in the message queue as the event message to be processed includes: Determine whether there is an unread event message at the position pointed to by the read pointer in the message queue; If there is an unread event message, the event message at the position pointed to by the read pointer is read as the event message to be processed.

5. The method according to claim 4, characterized in that If there is an unread event message, after reading the event message at the position pointed to by the read pointer as the event message to be processed, the method further includes: Determine whether the position pointed to by the read pointer is the last position of the message queue; If so, change the position pointed to by the read pointer to the first position of the message queue; If not, the position pointed to by the read pointer is moved back one position in the message queue.

6. The method according to claim 4, characterized in that The method further comprises: If there is no unread event message, after waiting for a preset time, the step of determining whether there is an unread event message at the position pointed to by the read pointer in the message queue is performed again; or, If there is no unread event message, the position pointed to by the read pointer is changed to the first position of the message queue of another game room.

7. The method according to any one of claims 1-3 or 5-6, characterized in that: Before sending the response message to the game client belonging to the game room, the method further includes: Detecting whether the time interval between the current time and the last synchronization time of the game room is greater than or equal to a preset time interval, wherein the last synchronization time is the time when a response message was last sent to a game client belonging to the game room; If not, wait until the time interval between the current moment and the last synchronization time is greater than or equal to the preset time interval, and then execute the step of sending the response message to the game client belonging to the game room.

8. The method according to claim 1, characterized in that The step of writing the event message into a message queue associated with the game room to which the game client belongs includes: Using a pre-created message dispatching thread, the event message is written into a message queue associated with the game room to which the game client belongs; The sending the response message to the game client belonging to the game room includes: sending the response message to the game client belonging to the game room by using a pre-created message sending thread.

9. An event message processing device, characterized in that: Applied to game servers, including: A writing unit, configured to write, after receiving an event message sent by a game client, the event message into a message queue associated with a game room to which the game client belongs, wherein the event message is generated by the game client based on a received interactive operation; A reading unit, configured to read the first event message written in the message queue as the event message to be processed according to the writing order of the event messages contained in the message queue; wherein the event messages contained in the message queue are: interaction instructions sent by multiple game clients belonging to the same game room for the same public data; A processing unit, configured to process the event message to be processed and obtain a response message corresponding to the event message to be processed; A sending unit, configured to send the response message to a game client belonging to the game room; The reading unit is specifically configured to use a pre-created message consumption thread to read the first event message written from the message queue according to the writing order of the event messages contained in the message queue as the event message to be processed; The processing unit is specifically used to process the pending event message by using the message consumption thread to obtain a response message corresponding to the pending event message; Each message consumption thread is bound to a room list, and a room list includes at least one game room.

10. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor is used to implement any method step of claims 1-8 when executing a program stored in a memory.

11. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps of any one of claims 1-8 are implemented.

Citation Information

Patent Citations

  • Fight game server system

    CN103188245A

  • Network game data transmission method

    CN104821947A

  • Message processing method and device based on message queue system

    CN107197015A

  • Method and system for entering same game room based on two-dimensional code of live broadcast interface

    CN110743163A