Asynchronous data writing method and device of game server
By introducing an asynchronous data writing method in the game server, the data writing operation is separated from the request processing operation, and the server response delay problem caused by synchronous data writing in the prior art is solved, and the server response speed and user experience are improved.
Patent Information
- Application Number
- CN202311106488.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-30
- Publication Date
- 2025-02-28
AI Technical Summary
The data writing operations of the existing game server system are synchronous, resulting in an increase in server response delay in high concurrency, affecting the gaming experience.
A asynchronous data writing method for game servers is proposed, which separates data writing operations from request processing operations, and executes data writing tasks through background task queues to improve server response speed.
Through the asynchronous data writing method, the server's response speed and concurrent processing capabilities are improved, the user's gaming experience is improved, and the server's response delay is reduced.
Smart Images

Figure CN119524392A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to an asynchronous data writing method for a game server and an asynchronous data writing device for a game server. Background Art
[0002] In the related art, data writing in existing game server systems is usually a synchronous operation; that is, when the server receives a game request from a client, it needs to process the request first, then write the data, and finally start processing the next request; this synchronous operation method can ensure data consistency, but will reduce the response speed of the server, especially in high concurrency situations, which may cause increased server response delays. Summary of the invention
[0003] The present application aims to solve at least one of the technical problems in the above-mentioned technology to a certain extent. To this end, one purpose of the present application is to propose an asynchronous data writing method for a game server, which can separate the data writing operation from the request processing operation, thereby improving the response speed of the server so as to respond to new game requests more quickly.
[0004] The second objective of the present application is to provide an asynchronous data writing device for a game server.
[0005] To achieve the above-mentioned purpose, the first aspect embodiment of the present application proposes an asynchronous data writing method for a game server, comprising the following steps: receiving a game request sent by a client, and processing the game request to obtain a processing result; generating a corresponding data writing task according to the processing result, and storing the data writing task in a background task queue so that the background task queue executes the data writing task.
[0006] According to the asynchronous data writing method of the game server in the embodiment of the present application, first, the game server receives the game request sent by the client, and processes the game request to obtain a processing result; then, a corresponding data writing task is generated according to the processing result, and the data writing task is stored in the background task queue so that the background task queue executes the data writing task; thereby, the data writing operation can be separated from the request processing operation, thereby improving the response speed of the server so as to respond to new game requests more quickly.
[0007] In addition, the asynchronous data writing method of the game server proposed in the above embodiment of the present application may also have the following additional technical features:
[0008] Optionally, processing the game request includes: obtaining a corresponding processing task according to the game request; verifying the legitimacy of the processing task, and processing the game request according to the processing task when the processing task is legal.
[0009] Optionally, the data writing task includes data to be written and a corresponding writing position.
[0010] Optionally, the data writing task is stored in a background task queue, and the background task queue executes the data writing task, including: building a task queue in the background; storing the data writing task as an independent task in the background task queue, so that the background task queue executes each data writing task in the task queue through multi-threading.
[0011] Optionally, when the background task queue fails to execute the data writing task, a transaction rollback technology is used to undo all previous operations.
[0012] To achieve the above-mentioned purpose, the second aspect embodiment of the present application proposes an asynchronous data writing device for a game server, including: a request processing module, used to receive a game request sent by a client, and process the game request to obtain a processing result; an asynchronous data writing module, used to generate a corresponding data writing task according to the processing result, and store the data writing task in a background task queue so that the background task queue executes the data writing task.
[0013] According to the asynchronous data writing device of the game server of the embodiment of the present application, the game request sent by the client is received through the request processing module, and the game request is processed to obtain a processing result; the asynchronous data writing module generates a corresponding data writing task according to the processing result, and stores the data writing task in the background task queue so that the background task queue executes the data writing task; thereby, the data writing operation can be separated from the request processing operation, thereby improving the response speed of the server so as to respond to new game requests more quickly.
[0014] In addition, the asynchronous data writing device of the game server proposed in the above embodiment of the present application may also have the following additional technical features:
[0015] Optionally, the request processing module is further used to obtain a corresponding processing task according to the game request; verify the legitimacy of the processing task, and process the game request according to the processing task when the processing task is legal.
[0016] Optionally, the data writing task includes data to be written and a corresponding writing position.
[0017] Optionally, the asynchronous data writing module is also used to build a task queue in the background; store the data writing task as an independent task in the background task queue, so that the background task queue executes each data writing task in the task queue through multi-threading.
[0018] Optionally, when the background task queue fails to execute the data writing task, a transaction rollback technology is used to undo all previous operations. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 Schematic diagram of a flow chart of an asynchronous data writing method of a game server according to an embodiment of the present application;
[0020] Figure 2 The present invention is a block diagram of an asynchronous data writing device of a game server according to an embodiment of the present application. DETAILED DESCRIPTION
[0021] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.
[0022] In order to better understand the above technical solution, exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0023] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0024] Figure 1 Schematic diagram of the process of the asynchronous data writing method of the game server according to the embodiment of the present application; Figure 1 As shown, the asynchronous data writing method of the game server of the embodiment of the present application includes the following steps:
[0025] S101, receiving a game request sent by a client, and processing the game request to obtain a processing result.
[0026] That is, when the game server receives a game request sent by a client, the game server processes the game request to obtain a processing result.
[0027] As an embodiment, processing a game request includes: obtaining a corresponding processing task according to the game request; verifying the legitimacy of the processing task, and processing the game request according to the processing task when the processing task is legitimate.
[0028] It should be noted that the processing task includes the relevant game logic to be executed.
[0029] As a specific embodiment, in an online combat game, the processing task corresponding to the client's game request may be an action of the player, such as moving or attacking, and the game server needs to verify whether the action is legal and update the game status after determining that it is legal.
[0030] S102, generating a corresponding data writing task according to the processing result, and storing the data writing task in a background task queue so that the background task queue executes the data writing task.
[0031] That is to say, after processing the game request of the client, the game server puts the related data writing task as an independent task into the task queue pre-built in the background, that is, this task queue is used to store the data writing tasks to be processed.
[0032] As an embodiment, the data writing task includes data to be written and a corresponding writing position.
[0033] That is, each data writing task in the task queue includes the data to be written and the corresponding writing position.
[0034] As an embodiment, the data writing task is stored in a background task queue, and the background task queue executes the data writing task, including: building a task queue in the background; storing the data writing task as an independent task in the background task queue, so that the background task queue executes each data writing task in the task queue through multi-threading.
[0035] That is to say, there are one or more dedicated threads in the background responsible for processing the data writing tasks in this task queue. These threads will take out tasks from the task queue and execute them in a certain order, such as first-in-first-out; since this process is carried out in the background, it will not affect the game server's processing of new game requests.
[0036] As a specific example, suppose in a large-scale online multiplayer game, a player completes a task and needs to write the task completion status to the database; in a traditional server system, the server needs to process the request first, then write the data, and finally process the next request; but in the system of the present application, after the server processes the request, it will immediately put the write operation in the background, and then immediately start processing the next request; this method can greatly improve the response speed of the server.
[0037] As an embodiment, when the background task queue fails to execute the data writing task, the transaction rollback technology is used to undo all previous operations.
[0038] It should be noted that in order to deal with possible errors, such as network failures, disk failures, etc., an error recovery mechanism is designed; this mechanism can restore the system to a consistent state when an error occurs. For example, if data writing fails, transaction rollback technology can be used to undo all previous operations to ensure data consistency.
[0039] To summarize, according to the asynchronous data writing method of the game server of the embodiment of the present application, by moving the data writing operation to the background, the server can immediately start processing new requests without waiting for the data writing to be completed; this is especially important in a high concurrency environment, and can effectively improve server performance; and through the error recovery mechanism, the system can be restored to a consistent state when an error occurs; this ensures the consistency and integrity of the data when facing possible network failures, hardware failures and other problems; that is, by improving the server response speed and concurrent processing capabilities, the user's gaming experience can be greatly improved; players no longer need to wait for a long time for the server to respond, and the fluency and real-time performance of the game are greatly improved.
[0040] Figure 2 FIG. 1 is a block diagram of an asynchronous data writing device of a game server according to an embodiment of the present application. Figure 2 As shown, the asynchronous data writing device of the game server includes: a request processing module 10 and an asynchronous data writing module 20;
[0041] Among them, the request processing module is used to receive the game request sent by the client and process the game request to obtain the processing result; the asynchronous data writing module is used to generate the corresponding data writing task according to the processing result, and store the data writing task in the background task queue so that the background task queue executes the data writing task.
[0042] As an embodiment, the request processing module 10 is further used to obtain a corresponding processing task according to a game request; verify the legitimacy of the processing task, and process the game request according to the processing task when the processing task is legitimate.
[0043] As an embodiment, the data writing task includes data to be written and a corresponding writing position.
[0044] As an embodiment, the asynchronous data writing module 20 is also used to construct a task queue in the background; store the data writing task as an independent task in the background task queue, so that the background task queue executes each data writing task in the task queue through multi-threading.
[0045] It should be noted that the above explanations of the embodiment of the asynchronous data writing method for the game server are also applicable to the asynchronous data writing device for the game server of this embodiment, and will not be repeated here.
[0046] To summarize, according to the asynchronous data writing device of the game server of the embodiment of the present application, the game request sent by the client is received through the request processing module, and the game request is processed to obtain a processing result; the asynchronous data writing module generates a corresponding data writing task according to the processing result, and stores the data writing task in the background task queue, so that the background task queue executes the data writing task; thereby, the data writing operation can be separated from the request processing operation, thereby improving the response speed of the server, so as to respond to new game requests more quickly.
[0047] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0048] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0049] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0050] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0051] It should be noted that in the claims, any reference signs placed between brackets shall not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claims. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The present application may be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third etc. does not indicate any order. These words may be interpreted as names.
[0052] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0053] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
[0054] In the description of the present application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the feature. In the description of the present application, "plurality" means two or more, unless otherwise clearly and specifically defined.
[0055] In this application, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.
[0056] In the present application, unless otherwise clearly specified and limited, a first feature being “above” or “below” a second feature may mean that the first and second features are in direct contact, or the first and second features are in indirect contact through an intermediate medium. Moreover, a first feature being “above”, “above”, and “above” a second feature may mean that the first feature is directly above or obliquely above the second feature, or simply means that the first feature is higher in level than the second feature. A first feature being “below”, “below”, and “below” a second feature may mean that the first feature is directly below or obliquely below the second feature, or simply means that the first feature is lower in level than the second feature.
[0057] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms should not be understood as necessarily being directed to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.
[0058] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A method for writing asynchronous data to a game server, characterized in that: The following steps are involved: Receive a game request sent by a client, and process the game request to obtain a processing result; A corresponding data writing task is generated according to the processing result, and the data writing task is stored in a background task queue so that the background task queue executes the data writing task.
2. The asynchronous data writing method of the game server according to claim 1, characterized in that: Processing the game request includes: Acquire a corresponding processing task according to the game request; Verify the legitimacy of the processing task, and if the processing task is legitimate, process the game request according to the processing task.
3. The asynchronous data writing method of the game server according to claim 2, characterized in that: The data writing task includes data to be written and a corresponding writing position.
4. The asynchronous data writing method of the game server according to claim 3, characterized in that: The data writing task is stored in a background task queue, and the background task queue executes the data writing task, including: Build a task queue in the background; The data writing task is stored as an independent task in the background task queue, so that the background task queue executes each data writing task in the task queue through multi-threading.
5. The asynchronous data writing method of the game server as claimed in claim 4, characterized in that: When the background task queue fails to execute the data writing task, a transaction rollback technique is used to undo all previous operations.
6. An asynchronous data writing device for a game server, characterized in that: include: A request processing module, used for receiving a game request sent by a client, and processing the game request to obtain a processing result; The asynchronous data writing module is used to generate a corresponding data writing task according to the processing result, and store the data writing task in a background task queue so that the background task queue executes the data writing task.
7. The asynchronous data writing device of the game server according to claim 6, characterized in that: The request processing module is also used to obtain a corresponding processing task according to the game request; verify the legality of the processing task, and process the game request according to the processing task when the processing task is legal.
8. The asynchronous data writing device of the game server according to claim 7, characterized in that: The data writing task includes data to be written and a corresponding writing position.
9. The asynchronous data writing device of the game server according to claim 8, characterized in that: The asynchronous data writing module is also used to construct a task queue in the background; store the data writing task as an independent task in the background task queue, so that the background task queue executes each data writing task in the task queue through multi-threading.
10. The asynchronous data writing device of the game server according to claim 9, characterized in that: When the background task queue fails to execute the data writing task, a transaction rollback technique is used to undo all previous operations.