CN111282263A - Event message processing method and device, electronic equipment and readable storage medium - Google Patents

Event message processing method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN111282263A
CN111282263A CN202010140390.8A CN202010140390A CN111282263A CN 111282263 A CN111282263 A CN 111282263A CN 202010140390 A CN202010140390 A CN 202010140390A CN 111282263 A CN111282263 A CN 111282263A
Authority
CN
China
Prior art keywords
message
game
event message
event
message queue
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010140390.8A
Other languages
Chinese (zh)
Inventor
陈生飞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN202010140390.8A priority Critical patent/CN111282263A/en
Publication of CN111282263A publication Critical patent/CN111282263A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/30Interconnection arrangements between game servers and game devices; Interconnection arrangements between game devices; Interconnection arrangements between game servers
    • A63F13/35Details of game servers
    • A63F13/358Adapting the game course according to the network or server load, e.g. for reducing latency due to different connection speeds between clients
    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F2300/00Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game
    • A63F2300/50Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game characterized by details of game servers
    • A63F2300/53Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game characterized by details of game servers details of basic data processing
    • A63F2300/534Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game characterized by details of game servers details of basic data processing for network load management, e.g. bandwidth optimization, latency reduction

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The embodiment of the invention provides a method and a device for processing an event message, electronic equipment and a readable storage medium, which are applied to a game server and comprise the following steps: writing the received event message into a message queue associated with the game room, reading the written event message to be processed firstly from the message queue, processing the event message to be processed to obtain a response message corresponding to the event message to be processed, and sending the response message to the game client belonging to the game room. By applying the technical scheme provided by the embodiment of the invention, event messages sent by a plurality of game clients belonging to one game room can be written into a message queue pre-established for the game room, then the event messages are processed one by one, and response messages obtained after processing are sent to the game clients, so that the game clients are driven to update game pictures, the locking and unlocking operations are replaced, and the time delay of the game is reduced.

Description

Event message processing method and device, electronic equipment and readable storage medium
Technical Field
The present invention relates to the field of product application technologies, and in particular, to a method and an apparatus for processing an event message, an electronic device, and a readable storage medium.
Background
For the multi-player real-time interactive game, the game client sends an interactive instruction, the game server receives the interactive instruction and then responds the interactive instruction to obtain a response message, and the response message is sent to the client so that the client updates the game picture.
When multiple game clients send multiple interactive commands simultaneously for a common piece of data, the common piece of data is usually locked by mutual exclusion to avoid collision. For example, when the game client a and the game client B request to modify the same common data at the same time, the game client a may add a mutual exclusion lock to the common data to prevent the game client B from modifying the common data, and the game client B may continue to modify the common data only after the mutual exclusion lock added by the game client a is released.
However, when the number of game clients that modify the common data is large, the locking and unlocking operations need to be performed multiple times during the processing, which may result in long waiting time of some game clients and affect performance indexes such as time delay of the game.
Disclosure of Invention
Embodiments of the present invention provide an event message processing method, an event message processing apparatus, an electronic device, and a readable storage medium, so as to solve the problem of a large response delay when a plurality of game clients send event messages at the same time. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides an event message processing method, applied to a game server, 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, wherein the event message is generated by the game client based on received interactive operation;
reading the event message written first from the message queue according to the writing sequence of each event message contained in the message queue as the event message to be processed;
processing the event message to be processed to obtain a response message corresponding to the event message to be processed;
and sending the response message to the game client belonging to the game room.
Further, the writing the event message into a message queue associated with a game room to which the game client belongs includes:
judging whether unread event messages exist in the positions pointed by the write pointers in the message queues associated with the game rooms to which the game clients belong;
and if not, writing the event message into the position pointed by the write pointer.
Further, after writing the event message into the location pointed by the write pointer if the event message does not exist, the method further includes:
judging whether the position pointed by the write pointer is the last bit of the message queue;
if so, changing the position pointed by the write pointer to the first bit of the message queue;
if not, the position pointed by the write pointer is shifted backwards by one bit in the message queue.
Further, the reading, according to the writing sequence of each event message included in the message queue, the event message written first from the message queue as the event message to be processed includes:
judging whether an unread event message exists in the position pointed by the read pointer in the message queue;
and if the unread event message exists, reading the event message in the position pointed by the read pointer as the event message to be processed.
Further, after reading the event message in the position pointed by the read pointer as the event message to be processed if there is an unread event message, the method further includes:
judging whether the position pointed by the read pointer is the last bit of the message queue;
if so, changing the position pointed by the read pointer to the first bit of the message queue;
if not, the position pointed by the read pointer is shifted backwards by one bit in the message queue.
Further, the method further comprises:
if the unread event message does not exist, after waiting for a preset time, executing the step of judging whether the unread event message exists in the position pointed by the read pointer in the message queue again; or
And if the unread event message does not exist, changing the position pointed by the reading pointer to the first position of the message queue of the other game room.
Further, 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 synchronous time of the game room is greater than or equal to a preset time interval or not, wherein the last synchronous time is the time when a response message is sent to the game client belonging to the game room last time;
if not, waiting until the time interval between the current time and the last synchronization time is greater than or equal to a preset time interval, and executing the step of sending the response message to the game client belonging to the game room.
Further, the writing the event message into a message queue associated with a game room to which the game client belongs includes:
writing the event message into a message queue associated with a game room to which the game client belongs by utilizing a pre-established message dispatching thread;
the reading, according to the writing sequence of each event message included in the message queue, the event message written first from the message queue as the event message to be processed includes: reading the event message written first from the message queue by using a pre-established message consumption thread according to the writing sequence of each event message contained in the message queue, and taking the event message as a to-be-processed event message;
the processing the event message to be processed to obtain a response message corresponding to the event message to be processed includes: processing 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;
the sending the response message to the game client belonging to the game room includes: and sending the response message to the game client belonging to the game room by utilizing a pre-created message sending thread.
In a second aspect, an embodiment of the present invention provides an event message processing apparatus, applied to a game server, including:
the writing unit is used for writing the event message into a message queue associated with a 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;
a reading unit, configured to read, according to a writing order of each event message included in the message queue, an event message written first from the message queue as an event message to be processed;
the processing unit is used for processing the event message to be processed to obtain a response message corresponding to the event message to be processed;
and the sending unit is used for sending the response message to the game client belonging to the game room.
Further, the writing unit is specifically configured to determine whether an unread event message exists in a location pointed by a write pointer in a message queue associated with the game room to which the game client belongs, and if not, write the event message into the location pointed by the write pointer.
Further, the writing unit is further configured to determine whether a position pointed by the write pointer is a last bit of the message queue, change the position pointed by the write pointer to a first bit of the message queue if the position pointed by the write pointer is the last bit of the message queue, and shift the position pointed by the write pointer back by one bit in the message queue if the position pointed by the write pointer is not the last bit of the message queue.
Further, the reading unit is specifically configured to determine whether an unread event message exists in a location pointed by the read pointer in the message queue, and if the unread event message exists, read the event message in the location pointed by the read pointer as the to-be-processed event message.
Further, the reading unit is further configured to determine whether a position pointed by the read pointer is a last bit of the message queue, change the position pointed by the read pointer to a first bit of the message queue if the position pointed by the read pointer is the last bit of the message queue, and shift the position pointed by the read pointer back by one bit in the message queue if the position pointed by the read pointer is not the last bit of the message queue.
Further, the reading unit is further configured to, if there is no unread event message, wait for a preset duration, and then perform the step of determining whether there is an unread event message in the position pointed by the read pointer in the message queue again; or if the unread event message does not exist, changing the position pointed by the read pointer to the first position of the message queue of another game room.
Further, the sending unit is further configured to detect whether a time interval between a current time and a last 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, where the last synchronization time is a time when the 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 time and the last synchronization time is greater than or equal to the preset time interval, and execute the step of sending the response message to the game client belonging to the game room.
Further, the writing unit is specifically configured to write the event message into a message queue associated with a game room to which the game client belongs, by using a pre-created message distribution thread;
the reading unit is specifically configured to read, by using a pre-created message consumption thread, the event message written first from the message queue according to the writing order of the event messages included in the message queue, and use the event message as the event message to be processed;
the processing unit is specifically configured 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;
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.
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, where the processor and the communication interface complete communication between the memory and the processor through the communication bus;
a memory for storing a computer program;
and the processor is used for realizing any step of the event message processing method when executing the program stored on the memory.
In a fourth aspect, the embodiment of the present invention provides a readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the computer program implements any step of the method for processing the event message.
In a fifth aspect, an embodiment of the present invention further provides a computer program product including instructions, which when run on a computer, causes the computer to execute any one of the above-mentioned event message processing methods.
The event message processing method, the event message processing device, the electronic equipment and the readable storage medium are applied to a game server, after the event message sent by a game client is received, 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 received interactive operation, the event message written first is read from the message queue according to the writing sequence of each event message contained in the message queue and is used as a to-be-processed event message, the to-be-processed event message is processed to obtain a response message corresponding to the to-be-processed event message, the response message is sent to the game client belonging to the game room, and the game client is driven to update a game picture.
By applying the technical scheme provided by the embodiment of the invention, the event messages sent by a plurality of game clients belonging to one game room can be written into the message queue pre-established for the game room, then the event messages are processed one by one, and the processed response messages are sent to the game clients, so that the game clients are driven to update the game pictures, the locking and unlocking operations are replaced, and the time delay of the game is reduced.
Of course, not all of the advantages described above need to be achieved at the same time in the practice of any one product or method of the invention.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a first flowchart of an event message processing method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a game server creating a game room according to an embodiment of the present invention;
FIG. 3 is a flow chart of a write event message according to an embodiment of the present invention;
fig. 4 is a schematic diagram of a message queue according to an embodiment of the present invention;
FIG. 5 is a flowchart of reading an event message according to an embodiment of the present invention;
fig. 6 is a second flowchart of a method for processing an event message according to an embodiment of the present invention;
fig. 7 is a signaling diagram of a method for processing an event message according to an embodiment of the present invention;
FIG. 8 is a schematic structural diagram of a game server according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of an event message processing apparatus according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment of the invention discloses a method and a device for processing an event message, electronic equipment and a readable storage medium, which are respectively described in detail below.
As shown in fig. 1, fig. 1 is a flowchart of a method for processing an event message according to an embodiment of the present invention, where the method may be applied to a game server, and includes the following steps:
and 11, after receiving the event message sent by the game client, writing the event message into a message queue associated with the game room to which the game client belongs.
And step 12, reading the event message written first from the message queue according to the writing sequence of each event message contained in the message queue as the event message to be processed.
And step 13, processing the event message to be processed to obtain a response message corresponding to the event message to be processed.
And step 14, sending a response message to the game client belonging to the game room.
By adopting the event message processing method shown in fig. 1, a plurality of game clients belonging to a game room may be provided, event messages sent by a plurality of game clients belonging to one game room may be written into a message queue created in advance for the game room, the event messages are processed one by one, and response messages obtained after processing are sent to the game clients, so that the game clients are driven to update game pictures, and locking and unlocking operations are replaced, thereby reducing the time delay of a game.
As shown in fig. 2, fig. 2 is a schematic diagram of a game server creating a game room according to an embodiment of the present invention. Taking 3 game clients as an example, the game clients belonging to a game room include three game clients, namely a game client 1, a game client 2 and a game client 3, the three game clients send matching requests to a matching server, the matching requests carry IDs (Identity documents) of the game clients, the matching server generates matching messages after matching the three game clients based on the matching requests, the matching messages include the IDs of the three game clients, the matching server sends the matching messages to a Netty server, the Netty server routes the matching messages to the game servers 1 in a game server cluster through a random algorithm, and the game servers 1 create game rooms for the three game clients after receiving the matching messages.
After the game room is created, optionally, a message queue associated with the game room may be created for the game room, optionally, the message queue may also be pre-existing, after the game room is created, a message queue associated with the game room is selected from the unoccupied existing message queues, and further, the association relationship between the game room and the message queue may be maintained by establishing an association information table.
In an embodiment, the event message may be generated by the game client based on the received interactive operation, and optionally, after receiving the interactive operation, the game client encapsulates an interactive event responding to the interactive operation into the event message.
In an embodiment of the present application, after receiving the event message sent by the game client, the writing the event message into a message queue associated with the game room to which the game client belongs (step 11), as shown in fig. 3, further may include the following steps:
step 31, it is determined whether there is an unread event message in the location pointed to by the write pointer in the message queue associated with the game room to which the game client belongs.
The game server can write the received event message in each position of the message queue and read the event message stored in each position of the message queue when needed. Optionally, the position to which the write pointer initially points is the first position of the message queue, that is, the position of the event message written first in the message queue is the first position of the message queue.
It is determined whether there is an unread event message in the location pointed to by the write pointer in the message queue and, if so, step 32 is performed, and if not, step 33 is performed. As shown in fig. 4, fig. 4 is a schematic diagram of a message queue according to an embodiment of the present invention, where the length of the message queue is 5, positions in the message queue are respectively marked as 0, 1, 2, 3, and 4 from left to right, a position initially pointed by a write pointer is a first position of the message queue, that is, a position marked as 0, and it is determined whether there is an unread message in the positions marked as 0, if so, step 32 is executed, and if not, step 33 is executed.
Step 32, after waiting for the first duration, executing step 31 again;
the first duration may be set according to actual requirements, and when there is an unread event message in the position pointed by the write pointer in the message queue, the game server waits for the first duration, and performs step 31 again. For example, when there is an unread event message in the location pointed by the write pointer in the message queue, the game server waits for 10 milliseconds, determines again whether there is an unread event message in the location pointed by the write pointer in the message queue, and repeats this process until the unread event message is read by the game server.
Step 33, writing the event message into the position pointed by the write pointer;
when the write pointer does not have an unread event message in the positions pointed to by the message queue, the game server writes the event message in the position pointed to by the write pointer.
Step 34, judging whether the position pointed by the write pointer is the last position of the message queue;
the game server judges whether the position pointed by the write pointer is the last position of the message queue, optionally, if the position pointed by the write pointer is the last position of the message queue, step 35 is executed; if not, go to step 36. Taking fig. 4 as an example, it is determined whether the position pointed by the write pointer is the last bit of the message queue, that is, it is determined whether the position pointed by the write pointer is the position marked with 4, if the position pointed by the write pointer is the position marked with 4, step 35 is executed; if not, step 36 is performed.
Step 35, changing the position pointed by the write pointer to the first position of the message queue;
when the position pointed by the write pointer is the last bit of the message queue, the game server changes the position pointed by the write pointer to the first bit, and if the position pointed by the write pointer is the position marked with 4, taking fig. 4 as an example, the game server changes the position pointed by the write pointer to the position marked with 0.
Step 36, the position pointed by the write pointer is shifted one bit back in the message queue.
When the position pointed by the write pointer is not the last position of the message queue, the game server moves the position pointed by the write pointer back by one bit in the message queue, taking fig. 4 as an example, if the position pointed by the write pointer is the position marked with 1, the game server moves the position pointed by the write pointer back by one bit in the message queue and changes the position pointed by the write pointer to the position marked with 2.
With the embodiment shown in fig. 3, it can be avoided that, in a case where an event message in a position pointed by the write pointer in the message queue has not been read, the game server writes a received new event message in the position again, and an event message is overwritten, thereby causing a problem that the event message is missed to be read.
In an embodiment of the application, the step of reading the event message written first from the message queue as the to-be-processed event message according to the writing sequence of the event messages included in the message queue (step 12) may further include the following steps, as shown in fig. 5:
step 51, determine whether there is an unread event message in the location pointed to by the read pointer in the message queue.
A message queue is created in advance for the game room, the position in the message queue is used for the game server to write and read the event message, optionally, the position initially pointed by the read pointer is the first position of the message queue, whether the unread event message exists in the position pointed by the read pointer in the message queue is judged, and if so, step 52 is executed. Taking fig. 4 as an example, the position initially pointed to by the read pointer is the first position of the message queue, i.e. the position marked as 0, and whether there is an unread message in the position marked as 0 is determined, if so, step 52 is executed.
Step 52, the event message in the position pointed by the read pointer is read as the pending event message.
When the read pointer has an unread event message in the position pointed by the message queue, the game server reads the event message in the position pointed by the read pointer as a pending event message.
Step 53, determine whether the position pointed by the read pointer is the last bit of the message queue.
The game server judges whether the position pointed by the reading pointer is the last position of the message queue, if so, step 54 is executed; if not, go to step 55. Taking fig. 4 as an example, it is determined whether the position pointed by the read pointer is the last bit of the message queue, that is, it is determined whether the position pointed by the write pointer is the position marked with 4, if so, step 54 is executed; if not, step 55 is performed.
Step 54, the position pointed by the read pointer is changed to the first bit of the message queue.
When the position pointed by the read pointer is the last position of the message queue, the game server changes the position pointed by the read pointer to the first position, taking fig. 4 as an example, if the position pointed by the read pointer is the position marked with 4, the game server changes the position pointed by the read pointer to the position marked with 0.
The position pointed to by the read pointer is shifted one bit back in the message queue, step 55.
When the position pointed by the read pointer is not the last position of the message queue, the game server moves the position pointed by the read pointer back by one bit in the message queue, taking fig. 4 as an example, if the position pointed by the read pointer is the position marked with 1, the game server moves the position pointed by the read pointer back by one bit in the message queue and changes the position pointed by the read pointer to the position marked with 2.
In an embodiment of the present application, for the above-mentioned determining whether there is an unread event message in the location pointed by the read pointer in the message queue (step 51), if the obtained result is that there is no unread event message, an implementation manner is: the game server may wait for a preset duration and then perform the step of determining whether the unread event message exists in the position pointed by the read pointer in the message queue. For example, when there is no unread event message in the position pointed to by the read pointer in the message queue, the game server waits for 5 milliseconds, determines again whether there is an unread event message in the position pointed to by the read pointer in the message queue, and repeats this process until the game server writes an event message in the position pointed to by the read pointer in the message queue. By applying the embodiment, the writing condition of the event message in the message queue can be detected in real time, the event message written by the game server can be read in time, the response speed of the game server to the event message is improved, and the game time delay is reduced;
the other implementation mode is as follows: the game server may change the position pointed to by the read pointer to the first of the message queue of another game room. The game server is pre-created with a game room list including a plurality of game rooms, and the game server can change the position pointed by the read pointer to the first position of the message queue of another game room. By applying the embodiment, the game server can read the message queue of the next game room in the room list under the condition that all event messages in the message queue of one game room are read, so that the thread resource of the game server is saved.
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 be further included:
detecting whether the time interval between the current time and the last synchronous time of the game room is greater than or equal to a preset time interval or not, wherein the last synchronous time is the time when response messages are sent to the game clients last time;
if not, waiting until the time interval between the current time and the last synchronous time is greater than or equal to the preset time interval, and executing the step of sending response messages to the game clients.
As shown in fig. 6, fig. 6 is a flowchart of a method for processing an event message according to an embodiment of the present invention, where the method may be applied to a game server, and includes the following steps:
and step 61, after receiving the event message sent by the game client, writing the event message into a message queue associated with the game room to which the game client belongs.
The event message may be a game start instruction, a game pause instruction, a specific operation instruction for a game screen, and other messages sent to the game server by a plurality of game clients belonging to one game room, which is not limited in the embodiment of the present invention. And for the game clients, after receiving the event message sent by the game client, the game server writes the event message into a message queue pre-established for the game room. This step may be the same as the step shown in fig. 3, and specifically, refer to the description of fig. 3.
And step 62, reading the event message written first from the message queue as the event message to be processed according to the writing sequence of each event message contained in the message queue.
This step may be the same as the step shown in fig. 5, and specifically, refer to the description of fig. 5.
And 63, processing the event message to be processed to obtain a response message corresponding to the event message to be processed.
And the game server processes the event message to be processed to obtain a response message corresponding to the event message to be processed.
Step 64, detecting whether the time interval between the current time and the last synchronous time of the game room is greater than or equal to a preset time interval, wherein the last synchronous time is the time when the response message is sent to the game client belonging to the game room last time; if the time interval is greater than or equal to the preset time interval, executing step 65; if the time interval is less than the preset time interval, go to step 66;
the game server stores the last synchronous time, the last synchronous time is the time when the response message is sent to the game client belonging to the game room last time, and the game server detects whether the time interval between the current time and the last synchronous time of the game room is greater than or equal to a preset time interval or not; for example, the last synchronization time stored in the game server is 30 minutes and 9 seconds at 9 am, the game server obtains that the current time is 30 minutes and 11 seconds at 9 am, the preset time interval is 2 seconds, and 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 that the current time is 30 minutes and 10 seconds at 9 am, and detects that the time interval between the current time and the last synchronization time is 1 second and is less than the preset time interval, so step 66 is executed.
Step 65, a response message is sent to the game client belonging to the game room.
The game server simultaneously sends response messages to the game clients belonging to the same game room, and the game clients update game pictures based on the response messages after receiving the response messages.
And step 66, waiting, executing step 64, and executing step 65 until the time interval between the current time and the last synchronization time is greater than or equal to the preset time interval.
When the game server detects that the time interval between the current time and the last synchronous time of the game room is smaller than the preset time interval, the game server waits for the preset time length, and detects whether the time interval between the current time and the last synchronous time of the game room is larger than or equal to the preset time interval again until the time interval between the current time and the last synchronous time is larger than or equal to the preset time interval, and the game server sends response messages to the game clients belonging to the same game room.
In an embodiment of the application, the length of the message queue is a product of the number of event messages sent by the plurality of game clients per second counted in the historical time period and the second time period.
For example, the game server counts that the number of event messages sent by a plurality of game clients belonging to one game room per second is 10 on average in one month, and the second time duration is 2 seconds, 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 historical data counted by the game server, so that the storage resource of the game server is saved.
In one embodiment of the present application, the game server uses a pre-created message dispatch thread to write an event message into a message queue associated with the game room to which the game client belongs.
Optionally, the game server creates a message dispatch thread in advance, and the message dispatch thread may find, according to the ID of the game room, a message queue in the game room corresponding to the ID in the room list, and write the event messages sent by the game clients belonging to the game room into the message queue in the game room.
The game server reads the event message written first from the message queue as the event message to be processed according to the writing sequence of each event message contained in the message queue by using the pre-established message consumption thread;
the game server creates a message consumption thread in advance, the number of the message consumption threads can be the core number of a Central Processing Unit (CPU), the message consumption thread can bind a room list containing a plurality of game room IDs, the message consumption thread reads a message queue in a game room corresponding to a first game room ID in the room list, and reads event messages from the message queue as event messages to be processed according to a writing sequence from first to last;
the game server processes the event message to be processed by utilizing the message consumption thread to obtain a response message corresponding to the event message to be processed;
the game server sends a response message to the game client belonging to the game room by using a pre-created message sending thread.
The game server sends response messages to the plurality of game clients by using a pre-created message sending thread.
The game server creates a message sending thread in advance, and the message sending thread sends response messages to a plurality of game clients belonging to the game room.
By adopting the method provided by the embodiment, the task of sending the response message to the game clients can be completed by the message sending thread, the response speed of the message consuming thread is prevented from being influenced, and the CPU cache of the game server is not frequently loaded with the cache due to lock conflict, so that the concurrency number of the server can be greatly increased, and the hit efficiency of the cache is improved.
The method for processing an event message according to the embodiment of the present invention is further explained with reference to the signaling diagram shown in fig. 7, which includes the following steps:
step 71, a plurality of game clients send event messages to the Netty server;
the Netty server establishes a TCP channel between the Netty server and the plurality of game clients, and can transmit and receive messages through the TCP channel, and the plurality of game clients transmit event messages to the Netty server.
Step 72, the Netty server forwards the event message to the game server;
the Netty server stores the corresponding relations between the game clients and the game servers, and the Netty server sends the event message to the corresponding game server according to the corresponding relations.
Step 73, the game server writes the event message into a message queue created for the game room by using a pre-created message dispatching thread;
the game server creates a message dispatching thread in advance, and after receiving the event messages of the plurality of game clients, the message dispatching thread is used for writing the event messages into a message queue created for the game room. Step 73 is the same as the step shown in fig. 3, and the detailed description can refer to the description of fig. 3 above.
Step 74, the game server reads the event message in the message queue by using the pre-established message consumption thread to obtain the event message to be processed;
an embodiment of the present invention further provides a schematic structural diagram of a game server as shown in fig. 8, where the game server creates a number of message consumption threads of the CPU core in advance through a Round Robin algorithm, each message consumption thread is bound to a room list, and a binding relationship between the message consumption thread and the room list may be maintained by a room manager in fig. 8.
The room list at least comprises one game room, and the event message in the message queue is read by using the message consumption thread bound with the game room to obtain the event message to be processed. Step 74 is the same as the step shown in fig. 5, and the detailed description may refer to the description of fig. 5 above.
Step 75, the game server processes the event message to be processed by using the message consumption thread to obtain a response message;
after the game server obtains the event message to be processed, the game server processes the event message to be processed by utilizing the message consumption thread to obtain a corresponding response message.
Step 76, the game server sends a response message to the Netty server by using the message sending thread;
the game server transmits the response message to the Netty server by using a pre-created message transmission thread.
The Netty server forwards the response message to the plurality of game clients, step 77.
The Netty server forwards the response message to the plurality of game clients through the TCP channel.
Corresponding to the event message processing method, the embodiment of the invention also provides an event message processing device. As shown in fig. 9, fig. 9 is a schematic structural diagram of an event message processing apparatus according to an embodiment of the present invention. The device includes:
the writing unit 91 is configured to write an event message into a message queue associated with a game room to which the game client belongs after receiving the event message sent by the game client, where the event message is generated by the game client based on the received interactive operation;
a reading unit 92, configured to read, according to a writing order of each event message included in the message queue, an event message written first from the message queue as an event message to be processed;
the processing unit 93 is configured to process the event message to be processed to obtain a response message corresponding to the event message to be processed;
a sending unit 94, configured to send a response message to the game client belonging to the game room.
Further, the writing unit 91 is specifically configured to determine whether an unread event message exists in the positions pointed by the writing pointer in the message queue associated with the game room to which the game client belongs, and if not, write the event message into the position pointed by the writing pointer.
Further, the writing unit 91 is further configured to determine whether the position pointed by the write pointer is the last bit of the message queue, and if so, change the position pointed by the write pointer to the first bit of the message queue, and if not, shift the position pointed by the write pointer back by one bit in the message queue.
Further, the reading unit 92 is specifically configured to determine whether an unread event message exists in the position pointed by the read pointer in the message queue, and if the unread event message exists, read the event message in the position pointed by the read pointer as the to-be-processed event message.
Further, the reading unit 92 is further configured to determine whether the position pointed by the read pointer is the last bit of the message queue, change the position pointed by the read pointer to the first bit of the message queue if the position pointed by the read pointer is the last bit of the message queue, and shift the position pointed by the read pointer back by one bit in the message queue if the position pointed by the read pointer is not the last bit of the message queue.
Further, the reading unit 92 is further configured to, if there is no unread event message, wait for a preset time period, and then perform the step of determining whether there is an unread event message in the position pointed by the read pointer in the message queue again; or if the unread event message does not exist, changing the position pointed by the read pointer to the first position of the message queue of another game room.
Further, the sending unit 94 is further configured to detect whether a time interval between the current time and a last 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, where the last synchronization time is a time when the 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 time and the last synchronization time is greater than or equal to the preset time interval, and execute the step of sending the response message to the game client belonging to the game room.
Further, the writing unit 91 is specifically configured to write the event message into a message queue associated with a game room to which the game client belongs by using a pre-created message distribution thread;
a reading unit 92, configured to specifically read, by using a pre-created message consumption thread, the event message written first from the message queue according to the writing order of each event message included in the message queue, and use the event message as the to-be-processed event message;
the processing unit 93 is specifically configured to process the event message to be processed by using the message consumption thread, so as to obtain a response message corresponding to the event message to be processed;
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.
Corresponding to the event message processing method, an embodiment of the present invention further provides an electronic device, as shown in fig. 10, including a processor 101, a communication interface 102, a memory 103, and a communication bus 104, where the processor 101, the communication interface 102, and the memory 103 complete mutual communication via the communication bus 104,
a memory 103 for storing a computer program;
the processor 101 is configured to implement the following steps when executing the program stored in the memory 103:
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, wherein the event message is generated by the game client based on received interactive operation;
reading the event message written first from the message queue according to the writing sequence of each event message contained in the message queue as the event message to be processed;
processing the event message to be processed to obtain a response message corresponding to the event message to be processed;
and sending the response message to the game client belonging to the game room.
By applying the technical scheme provided by the embodiment of the invention, the event messages sent by a plurality of game clients belonging to one game room can be written into the message queue pre-established for the game room, then the event messages are processed one by one, and the processed response messages are sent to the game clients to drive the game clients to update the game pictures.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
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 memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component.
In still another embodiment provided by the present invention, a readable storage medium is further provided, in which a computer program is stored, and the computer program, when executed by a processor, implements any step of the above-mentioned event message processing method.
In yet another embodiment, a computer program product containing instructions is provided, which when run on a computer causes the computer to execute the method for processing an event message in any of the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the device, the electronic device and the readable storage medium embodiments, since they are substantially similar to the method embodiments, the description is simple, and the relevant points can be referred to the partial description of the method embodiments.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (11)

1. A processing method of event messages is applied to a game server and comprises the following steps:
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, wherein the event message is generated by the game client based on received interactive operation;
reading the event message written first from the message queue according to the writing sequence of each event message contained in the message queue as the event message to be processed;
processing the event message to be processed to obtain a response message corresponding to the event message to be processed;
and sending the response message to the game client belonging to the game room.
2. The method of claim 1, wherein writing the event message into a message queue associated with a game room to which the game client belongs comprises:
judging whether unread event messages exist in the positions pointed by the write pointers in the message queues associated with the game rooms to which the game clients belong;
and if not, writing the event message into the position pointed by the write pointer.
3. The method of claim 2, wherein after writing the event message to the location pointed to by the write pointer if not present, the method further comprises:
judging whether the position pointed by the write pointer is the last bit of the message queue;
if so, changing the position pointed by the write pointer to the first bit of the message queue;
if not, the position pointed by the write pointer is shifted backwards by one bit in the message queue.
4. The method according to any one of claims 1 to 3, wherein said reading the first written event message from the message queue as the pending event message in the order of writing the event messages contained in the message queue comprises:
judging whether an unread event message exists in the position pointed by the read pointer in the message queue;
and if the unread event message exists, reading the event message in the position pointed by the read pointer as the event message to be processed.
5. The method of claim 4, wherein after reading the event message in the location pointed by the read pointer as the pending event message if there is an unread event message, the method further comprises:
judging whether the position pointed by the read pointer is the last bit of the message queue;
if so, changing the position pointed by the read pointer to the first bit of the message queue;
if not, the position pointed by the read pointer is shifted backwards by one bit in the message queue.
6. The method of claim 4, further comprising:
if the unread event message does not exist, after waiting for a preset time, executing the step of judging whether the unread event message exists in the position pointed by the read pointer in the message queue again; alternatively, the first and second electrodes may be,
and if the unread event message does not exist, changing the position pointed by the reading pointer to the first position of the message queue of the other game room.
7. The method of any of claims 1-3 or 5-6, wherein prior to sending the response message to a game client belonging to the game room, the method further comprises:
detecting whether the time interval between the current time and the last synchronous time of the game room is greater than or equal to a preset time interval or not, wherein the last synchronous time is the time when a response message is sent to the game client belonging to the game room last time;
if not, waiting until the time interval between the current time and the last synchronization time is greater than or equal to a preset time interval, and executing the step of sending the response message to the game client belonging to the game room.
8. The method of claim 1,
the writing the event message into a message queue associated with a game room to which the game client belongs includes:
writing the event message into a message queue associated with a game room to which the game client belongs by utilizing a pre-established message dispatching thread;
the reading, according to the writing sequence of each event message included in the message queue, the event message written first from the message queue as the event message to be processed includes: reading the event message written first from the message queue by using a pre-established message consumption thread according to the writing sequence of each event message contained in the message queue, and taking the event message as a to-be-processed event message;
the processing the event message to be processed to obtain a response message corresponding to the event message to be processed includes: processing 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;
the sending the response message to the game client belonging to the game room includes: and sending the response message to the game client belonging to the game room by utilizing a pre-created message sending thread.
9. An event message processing device applied to a game server comprises:
the writing unit is used for writing the event message into a message queue associated with a 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;
a reading unit, configured to read, according to a writing order of each event message included in the message queue, an event message written first from the message queue as an event message to be processed;
the processing unit is used for processing the event message to be processed to obtain a response message corresponding to the event message to be processed;
and the sending unit is used for sending the response message to the game client belonging to the game room.
10. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any of claims 1 to 8 when executing a program stored in the memory.
11. A readable storage medium, characterized in that a computer program is stored in the readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1-8.
CN202010140390.8A 2020-03-03 2020-03-03 Event message processing method and device, electronic equipment and readable storage medium Pending CN111282263A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010140390.8A CN111282263A (en) 2020-03-03 2020-03-03 Event message processing method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010140390.8A CN111282263A (en) 2020-03-03 2020-03-03 Event message processing method and device, electronic equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN111282263A true CN111282263A (en) 2020-06-16

Family

ID=71026946

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010140390.8A Pending CN111282263A (en) 2020-03-03 2020-03-03 Event message processing method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN111282263A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111737012A (en) * 2020-07-31 2020-10-02 腾讯科技(深圳)有限公司 Data packet synchronization method, device, equipment and storage medium
CN112199215A (en) * 2020-10-13 2021-01-08 恒生电子股份有限公司 Message processing method, device, equipment and storage medium
CN116570928A (en) * 2023-04-24 2023-08-11 北京科乐园网络科技有限公司 Information processing method, device and server based on NFT

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103188245A (en) * 2011-12-31 2013-07-03 上海火瀑云计算机终端科技有限公司 Fight game server system
CN104468509A (en) * 2014-10-29 2015-03-25 北方工业大学 Method and system for transmitting mobile phone network game data and mobile phone user side
CN104821947A (en) * 2015-05-08 2015-08-05 四川天上友嘉网络科技有限公司 Network game data transmission method
CN107197015A (en) * 2017-05-23 2017-09-22 阿里巴巴集团控股有限公司 A kind of message treatment method and device based on Message Queuing system
CN107528922A (en) * 2017-09-29 2017-12-29 深圳市金立通信设备有限公司 A kind of information push method, terminal and computer-readable recording medium
CN107948051A (en) * 2017-11-14 2018-04-20 北京知行锐景科技有限公司 A kind of real-time messages method for pushing and system based on Socket technologies
CN109714409A (en) * 2018-12-21 2019-05-03 优估(上海)信息科技有限公司 A kind of management method and system of message
CN110138721A (en) * 2019-03-22 2019-08-16 福建省天奕网络科技有限公司 Decouple method, the storage medium of game services and fight service
CN110327621A (en) * 2019-04-24 2019-10-15 上海恺英网络科技有限公司 For the matched method and apparatus of network game client
CN110743163A (en) * 2019-09-25 2020-02-04 恒大智慧科技有限公司 Method and system for entering same game room based on live broadcast interface two-dimensional code

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103188245A (en) * 2011-12-31 2013-07-03 上海火瀑云计算机终端科技有限公司 Fight game server system
CN104468509A (en) * 2014-10-29 2015-03-25 北方工业大学 Method and system for transmitting mobile phone network game data and mobile phone user side
CN104821947A (en) * 2015-05-08 2015-08-05 四川天上友嘉网络科技有限公司 Network game data transmission method
CN107197015A (en) * 2017-05-23 2017-09-22 阿里巴巴集团控股有限公司 A kind of message treatment method and device based on Message Queuing system
CN107528922A (en) * 2017-09-29 2017-12-29 深圳市金立通信设备有限公司 A kind of information push method, terminal and computer-readable recording medium
CN107948051A (en) * 2017-11-14 2018-04-20 北京知行锐景科技有限公司 A kind of real-time messages method for pushing and system based on Socket technologies
CN109714409A (en) * 2018-12-21 2019-05-03 优估(上海)信息科技有限公司 A kind of management method and system of message
CN110138721A (en) * 2019-03-22 2019-08-16 福建省天奕网络科技有限公司 Decouple method, the storage medium of game services and fight service
CN110327621A (en) * 2019-04-24 2019-10-15 上海恺英网络科技有限公司 For the matched method and apparatus of network game client
CN110743163A (en) * 2019-09-25 2020-02-04 恒大智慧科技有限公司 Method and system for entering same game room based on live broadcast interface two-dimensional code

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111737012A (en) * 2020-07-31 2020-10-02 腾讯科技(深圳)有限公司 Data packet synchronization method, device, equipment and storage medium
EP4095693A4 (en) * 2020-07-31 2023-07-12 Tencent Technology (Shenzhen) Company Limited Data packet synchronization method and apparatus, device, and storage medium
CN112199215A (en) * 2020-10-13 2021-01-08 恒生电子股份有限公司 Message processing method, device, equipment and storage medium
CN112199215B (en) * 2020-10-13 2024-01-19 恒生电子股份有限公司 Message processing method, device, equipment and storage medium
CN116570928A (en) * 2023-04-24 2023-08-11 北京科乐园网络科技有限公司 Information processing method, device and server based on NFT

Similar Documents

Publication Publication Date Title
CN108848039B (en) Server, message distribution method and storage medium
US9838340B2 (en) Systems and methods for storing message data
CN108174248B (en) Video playing method, video playing control device and storage medium
US8028085B2 (en) Optimizing message transmission and delivery in a publisher-subscriber model
CN111282263A (en) Event message processing method and device, electronic equipment and readable storage medium
JP2018531465A6 (en) System and method for storing message data
US9497288B2 (en) Subscriber based priority of messages in a publisher-subscriber domain
CN110851253B (en) Remote operation and maintenance method, system, storage medium and electronic equipment
CN107341062B (en) Data pushing method, device, equipment and storage medium
CN110968586A (en) Distributed transaction processing method and device
CN109152061B (en) Channel allocation method, device, server and storage medium
CN110008041B (en) Message processing method and device
US9614646B2 (en) Method and system for robust message retransmission
CN110620681B (en) Network connection timeout time setting method, device, equipment and medium
CN111813573A (en) Communication method of management platform and robot software and related equipment thereof
CN114006946B (en) Method, device, equipment and storage medium for processing homogeneous resource request
CN110727507B (en) Message processing method and device, computer equipment and storage medium
CN112838980B (en) Message processing method, system, device, electronic equipment and storage medium
CN110515749B (en) Method, device, server and storage medium for queue scheduling of information transmission
CN112653736A (en) Parallel source returning method and device and electronic equipment
US10862908B2 (en) System and method for consensus ordering of broadcast messages
CN111984198A (en) Message queue implementation method and device and electronic equipment
CN112363980A (en) Data processing method and device for distributed system
CN111309693A (en) Data synchronization method, device and system, electronic equipment and storage medium
CN116521639A (en) Log data processing method, electronic equipment and computer readable medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination