A method, system, device, and storage medium for stress testing game servers.
By monitoring and recording the protocol operations of the game server, dynamically playback protocol instructions and generating protocol logic branches, combining with the sandbox environment to realize parallel testing of multiple robots, solving the problems of insufficient scalability, flexibility and accuracy in the existing technology, and improving the effectiveness and efficiency of stress testing of game servers.
Patent Information
- Application Number
- CN202411938732.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-04-01
AI Technical Summary
The existing stress testing methods for gaming servers are insufficient in terms of scalability, flexibility and accuracy, and it is difficult to meet the needs of large-scale user operation simulation and complex scenarios.
By listening to protocol operations between the client and the server, recording protocol operation scripts, and dynamically playback protocol instructions by parsing scripts, generating protocol logic branches, and using a sandbox environment to realize the parallel work of multiple stress test robots.
Improves the flexibility and scalability of stress testing of gaming servers, enhances the authenticity and accuracy of testing, reduces resource consumption, and supports the creation of a large number of robots for testing on a single physical device.
Smart Images

Figure CN119743416A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of server testing, and in particular relates to a game server stress testing method, system, equipment and storage medium. Background Art
[0002] With the rapid development of the online gaming industry, the performance and stability of game servers have become important factors affecting player experience and game operations. In actual game operations, the server needs to withstand a large number of player requests for online operations at the same time, which places extremely high demands on the server's concurrent processing capabilities and load balancing capabilities. Therefore, in the process of game development and operation, server stress testing is an indispensable link, the purpose of which is to discover possible performance bottlenecks or system defects in advance and ensure that the server can operate normally in high-concurrency scenarios.
[0003] At present, online game server stress testing mainly simulates player operations through stress testing scripts, initiates access to the server at the same time, and estimates the peak load that the server can bear, and locates the performance bottleneck of the server for subsequent optimization. Existing stress testing tools usually perform unit tests on various business logics or sub-logics. This type of design has the following disadvantages: after the game function is expanded, a large number of new stress testing scripts need to be written to meet the stress testing requirements; for tests run through client requests, a single physical device runs a large number of robots at the same time.
[0004] A Chinese invention patent application with publication number CN109698771A discloses a game server stress testing method and device, the method comprising the following steps: after starting a protocol monitor, performing a stress test on the game server according to a client script and a stress testing script, the client script being used to simulate a game client, and the stress testing script being used to call the client script to simulate the interaction between the game client and the game server; obtaining operation information from the protocol monitor, the operation information including the operation information of the game client and / or the operation information of the game server; and determining whether to continue the stress test of the game server according to the operation information.
[0005] This solution simulates the interaction between the game client and the server through client scripts and stress test scripts. It may be limited by the design and implementation capabilities of the client scripts. When large-scale simulation of user operations is required, the scalability is poor. Since the client scripts and stress test scripts in the solution have a fixed calling relationship, the protocol operation process cannot be adjusted dynamically, and it is difficult to meet the flexible needs in complex scenarios. In addition, the delay characteristics of user operation behavior cannot be truly reproduced, which reduces the authenticity and accuracy of the test. Summary of the invention
[0006] The present invention provides a game server stress testing method, system, device and storage medium, aiming to solve the problems of insufficient scalability, flexibility and accuracy in existing game server stress testing solutions.
[0007] In order to solve the above technical problems, the first aspect of the present invention provides a game server stress testing method, comprising the following steps:
[0008] When the game is running, listen to the protocol operations sent by the client to the server, record the protocol name and request parameters as a protocol operation script and save it;
[0009] Define the corresponding processing logic for each protocol, create a protocol processing base class and its subclasses, and encapsulate and implement the operation logic of each protocol;
[0010] According to the recorded protocol command name, find the corresponding processing class from the protocol processing class pool, establish a mapping between the command and the processing class, and generate the protocol logic;
[0011] The recorded protocol operation scripts are connected in series in the order of operation to form a complete protocol logic branch, which is used to simulate the real operation process of the player;
[0012] Start multiple stress testing robots and load the protocol logic branch to perform stress testing on the server.
[0013] Preferably, the method further performs task division before monitoring the protocol operation sent by the client to the server, specifically:
[0014] According to the different functional modules of the game, the server stress test is split into multiple different server stress test tasks, which are used to build and run different protocol logic branches for each stress test task.
[0015] Preferably, the protocol name and request parameters are recorded as a protocol operation script and saved, and the specific method is:
[0016] Create a protocol operation script file in the specified path of the stress test device;
[0017] Use the debug.sethook function in Lua to register a hook to monitor all protocol requests and responses sent by the client to the server;
[0018] After listening to the protocol request, record the protocol data, including the protocol name and request parameters;
[0019] Write the protocol data into the protocol operation script file.
[0020] Preferably, when the protocol data is written into the protocol operation script file, an additional delay record is recorded before writing, and the delay record is the time difference from the last operation to the current operation.
[0021] Preferably, the specific method of generating the protocol logic is:
[0022] Loading a protocol operation script, and parsing the operation record of the protocol operation script line by line;
[0023] By parsing the obtained protocol name, an operation processing class is instantiated, and the operation processing class is responsible for defining the protocol and the request operation required to be executed by the protocol, and initiating a request to the server according to the protocol, and the initiated request includes the request parameters in the operation record;
[0024] Each operation processing class includes at least one interaction with the server, and the interaction includes sending a request to the game server and receiving response data returned by the server.
[0025] Preferably, the method of starting multiple stress testing robots and loading the protocol logic branch to perform stress testing on the server includes the following steps:
[0026] In the game environment, construct the main sandbox environment, load the static configuration data and export it to the game environment;
[0027] Constructing a character sandbox environment in a new game environment, and passing in the static configuration data when loading;
[0028] Create a new role in the role sandbox environment, load the protocol logic branch, initiate a protocol request to the server, and delay waiting operations.
[0029] Preferably, a plurality of the role sandbox environments can be constructed, and each role sandbox environment can directly reuse the client logic code to establish a request with the server, send a protocol, and receive a response.
[0030] A second aspect of the present invention further provides a game server stress testing system, the system being used to implement a game server stress testing method as described in the first aspect of the present invention, comprising:
[0031] The task management module is used to split the server stress test task into multiple different server stress test tasks according to different functional modules of the game, and generate corresponding protocol logic branches;
[0032] The script recording module is used to record the protocol operation script in the game, monitor the protocol request and response data sent by the client to the server, and record the protocol name, request parameters and delay records to generate the protocol operation script;
[0033] The script parsing module is used to define the corresponding processing logic for each protocol, create the protocol processing base class and its subclasses, and encapsulate and implement the operation logic of each protocol;
[0034] The protocol logic generation module is used to load the protocol operation script, parse the operation record line by line, obtain the corresponding processing class from the protocol processing class pool according to the protocol name, generate the protocol logic, and connect it in series according to the operation sequence to form a protocol logic branch;
[0035] The stress test execution module is used to start multiple stress test robots, load the protocol logic branch in the sandbox environment, simulate the player's real operation process, and initiate a protocol request to the server and delay waiting operations;
[0036] The sandbox management module is used to construct the main sandbox environment and the role sandbox environment, load static configuration data and protocol logic branches, and support the reuse of client logic code to interact with the server.
[0037] According to a third aspect of the present invention, an electronic device is provided, comprising:
[0038] one or more processors;
[0039] A memory for storing executable instructions;
[0040] Network module, used to establish communication with the game server;
[0041] Wherein, when the executable instructions in the memory are executed by the processor, the electronic device can implement the game server stress testing method as described in the first aspect of the present invention.
[0042] A fourth aspect of the present invention further proposes a storage medium storing computer executable instructions, which, when executed by a processor, can enable a device to execute the game server stress testing method as described in the first aspect of the present invention.
[0043] Compared with the prior art, the present invention has the following technical effects:
[0044] 1. The game server stress testing method proposed in the present invention simplifies the construction process of the test task by monitoring the protocol operations between the client and the server, adopting the protocol recording function, and dynamically replaying the protocol instructions by parsing the script; by adopting the protocol processing class pool, the protocol and the operation logic are bound, the operation logic of the protocol can be flexibly defined and adjusted to adapt to the requirements of various test scenarios, and the flexibility of the game server stress testing can be improved.
[0045] 2. The game server stress testing method proposed in the present invention enables multiple stress testing robots to work in parallel through a sandbox environment, supports the simulation of large-scale user operations, and isolates data between sandbox environments to avoid resource competition problems. It can also support a single physical machine to start a large number of robots, thereby improving the scalability of the game server stress testing.
[0046] 3. The game server stress testing method proposed in the present invention records delay information in the protocol recording and accurately restores it during playback, truly reproducing the user's operation behavior, thereby improving the authenticity and effect of the stress test.
[0047] 4. The game server stress testing method proposed in the present invention divides the stress testing tasks according to different game functional modules through task division, and constructs and runs independent protocol logic branches respectively, thereby improving the modular management capabilities of the test.
[0048] 5. The game server stress testing method proposed in the present invention utilizes the main sandbox environment and the role sandbox environment to realize the sharing of static data and the reuse of logic code, thereby reducing resource consumption and improving the overall performance of the test system. By logically stripping the client program, only the protocol requests and data modules related to the protocol are retained, and the sandbox memory is shared for the static configuration table of hundreds of MB, a large number of robots can be created on a single physical device for simultaneous testing, so that a conventional development computer can enable thousands of robots, effectively reducing the resource requirements of stress testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 It is a flow chart of the pressure testing method of the present invention;
[0050] Figure 2 4 is a diagram comparing system resource requirements according to an embodiment of the present invention. DETAILED DESCRIPTION
[0051] In order to make the objectives, technical solutions and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in combination with specific embodiments of the present application and with reference to the accompanying drawings.
[0052] Embodiment 1
[0053] This embodiment is a game server stress testing method. Figure 1 As shown, the following steps are included:
[0054] According to the different functional modules of the game, the server stress test is divided into multiple different server stress test tasks, which are used to build and run different protocol logic branches for each stress test task. For each independent server stress test task, the following steps of saving the protocol operation script and encapsulating and implementing the operation logic of each protocol are performed.
[0055] When the game is running, listen to the protocol operations sent by the client to the server, record the protocol name and request parameters as a protocol operation script and save it.
[0056] The protocol name and request parameters are recorded as a protocol operation script and saved. The specific method is:
[0057] Create a protocol operation script file in the specified path of the stress test device;
[0058] Use the debug.sethook function in Lua to register a hook to monitor all protocol requests and responses sent by the client to the server;
[0059] After listening to the protocol request, record the protocol data, including the protocol name and request parameters;
[0060] Write the protocol data into the protocol operation script file.
[0061] In this embodiment, when the protocol data is written into the protocol operation script file, an additional delay record is recorded before writing, and the delay record is the time difference from the last operation to the current operation. That is, in addition to recording normal network requests, the script also adds a special command such as cmd('sleep',2000) to control the execution speed of the script during playback and simulate the real operation of the player.
[0062] The specific recording process is as follows:
[0063] local rawReq = NetMgr.onReq
[0064] NetMgr.onReq=function(cmd,...)
[0065] --Write protocol operation script
[0066] …
[0067] rawReq(cmd,...)
[0068] end
[0069] In the above example, the NetMgr.onReq function is redefined to monitor the protocol requests sent by the client to the server. Each time NetMgr.onReq(cmd,...) is called, in addition to executing the original NetMgr.onReq method, the protocol instructions (cmd) and parameters (...) are recorded and written into the protocol operation script. By rewriting the request processing function of the game network module, all network requests sent by the client are intercepted. For each intercepted request, its command name and parameters are recorded to form a protocol operation instruction.
[0070] Define the corresponding processing logic for each protocol, create a protocol processing base class and its subclasses, and encapsulate and implement the operation logic of each protocol.
[0071] The following is an example of how to implement this step:
[0072] local CmdBase = class () - add a new protocol processing base class
[0073] local CmdLogin = class (CmdBase) -- Add a new login protocol processing class
[0074] function CmdLogin:getCmdName()
[0075] return 'req_login'
[0076] end
[0077] function CmdLogin:req(...)
[0078] NetMgr.onReq(self:getCmdName(),...)
[0079] end
[0080] In the above example, CmdBase is the base class of all protocol processing classes, which defines some basic methods and provides a common interface, such as getCmdName for obtaining the command name. CmdLogin is a subclass implementation and is a specific protocol processing class used to process login requests. The cmd function is responsible for parsing the protocol instructions and finding the corresponding protocol processing class to execute.
[0081] According to the recorded protocol command name, find the corresponding processing class from the protocol processing class pool, establish a mapping between instructions and processing classes, and generate protocol logic. The specific method of generating protocol logic is:
[0082] Loading a protocol operation script, and parsing the operation record of the protocol operation script line by line;
[0083] By parsing the obtained protocol name, an operation processing class (protocol processing class) is instantiated. The operation processing class is responsible for defining the protocol and the request operations required by the protocol, and initiating a request to the server according to the protocol. The initiated request includes the request parameters in the operation record; the protocol processing class is responsible for repackaging the parsed protocol parameters into a network request and sending it to the game server.
[0084] Each operation processing class includes at least one interaction with the server, and the interaction includes sending a request to the game server and receiving response data returned by the server.
[0085] For example, a cmd('req_login',account,password) script generates the following protocol logic:
[0086] --Load the protocol operation script and parse out each protocol instruction
[0087] function cmd(cmd_name,args)—cmd_name is req_login
[0088] --Find the corresponding protocol processing class in the protocol pool according to cmd_name
[0089] local handler=CmdPool.find(cmd_name)
[0090] handler.req(...)
[0091] end
[0092] In the above example, the cmd function parses the protocol operation script line by line, finds the corresponding protocol processing class (handler) according to the protocol name (cmd_name), and calls its req method to initiate a protocol request. CmdPool.find is used to find whether there is a protocol processing class matching cmd_name in the protocol pool.
[0093] The recorded protocol operation scripts are connected in series in the order of operation to form a complete protocol logic branch, which is used to simulate the player's actual operation process.
[0094] The following is an example of a complete protocol logic branch:
[0095] cmd('req_login',account,password)--Login protocol, the parameters are account number and password;
[0096] cmd('sleep',2000) --wait 2000 milliseconds;
[0097] cmd('hero_upgrade_lv',10001) --Role upgrade protocol, the parameter is the character ID.
[0098] In the format example, the protocol name and its corresponding parameters are saved, sleep means waiting for a period of time, simulating the delay behavior in user operation, that is, the delay record described in this embodiment. This format records the operation sequence, operation content and time interval (delay) between protocols, thereby truly simulating user operation.
[0099] Start multiple stress testing robots and load the protocol logic branch to perform stress testing on the server.
[0100] The specific method includes the following steps:
[0101] In the game environment, construct the main sandbox environment, load the static configuration data and export it to the game environment;
[0102] Constructing a character sandbox environment in a new game environment, and passing in the static configuration data when loading;
[0103] Create a new role in the role sandbox environment, load the protocol logic branch, initiate a protocol request to the server, and delay waiting operations.
[0104] In this step, a plurality of role sandbox environments may be constructed, and each role sandbox environment may directly reuse the client logic code to establish a request with the server, send a protocol, and receive a response.
[0105] The following is an example of creating a robot:
[0106] --Construct a sandbox in the game environment
[0107] local sandbox={}
[0108] setmetatable(sandbox,{__index=_G})
[0109] --Start multiple robots
[0110] for i=1,num_robots do
[0111] local robot_env=setmetatable({},{__index=sandbox})
[0112] --Load protocol logic branch
[0113] loadProtocolLogic(robot_env)
[0114] --Simulate robot operation
[0115] startRobot(robot_env)
[0116] end
[0117] In the above example, Lua sandbox technology is used to create multiple isolated test environments, each of which shares static data but isolates dynamic data. Each sandbox environment loads a complete protocol logic branch, simulates player behavior through robots, and performs stress testing on the server.
[0118] The game server stress testing method proposed in this embodiment uses the main sandbox environment and the role sandbox environment to realize the sharing of static data and the reuse of logic code, which reduces resource consumption and improves the overall performance of the test system. By logically stripping the client program, only the protocol requests and data modules related to the protocol are retained, and the sandbox memory is shared for the static configuration table of hundreds of MB, a large number of robots can be created on a single physical device for simultaneous testing, so that a conventional development computer can enable thousands of robots, effectively reducing the resource requirements of stress testing. Figure 2 As shown, when the CPU resource usage reaches 100%, this embodiment can support 1600 test robots to perform tests simultaneously.
[0119] Embodiment 2
[0120] This embodiment is a game server stress testing system, which is used to implement the game server stress testing method as described in Embodiment 1, including:
[0121] The task management module is used to split the server stress test task into multiple different server stress test tasks according to different functional modules of the game, and generate corresponding protocol logic branches;
[0122] The script recording module is used to record the protocol operation script in the game, monitor the protocol request and response data sent by the client to the server, and record the protocol name, request parameters and delay records to generate the protocol operation script;
[0123] The script parsing module is used to define the corresponding processing logic for each protocol, create the protocol processing base class and its subclasses, and encapsulate and implement the operation logic of each protocol;
[0124] The protocol logic generation module is used to load the protocol operation script, parse the operation record line by line, obtain the corresponding processing class from the protocol processing class pool according to the protocol name, generate the protocol logic, and connect it in series according to the operation sequence to form a protocol logic branch;
[0125] The stress test execution module is used to start multiple stress test robots, load the protocol logic branch in the sandbox environment, simulate the player's real operation process, and initiate a protocol request to the server and delay waiting operations;
[0126] The sandbox management module is used to construct the main sandbox environment and the role sandbox environment, load static configuration data and protocol logic branches, and support the reuse of client logic code to interact with the server.
[0127] Embodiment 3
[0128] This embodiment is an electronic device, including:
[0129] one or more processors;
[0130] A memory for storing executable instructions;
[0131] Network module, used to establish communication with the game server;
[0132] Wherein, when the executable instructions in the memory are executed by the processor, the electronic device can implement the game server stress testing method as described in Example 1.
[0133] Embodiment 4
[0134] This embodiment is a storage medium that stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the device can execute the game server stress testing method as described in Embodiment 1.
[0135] The above is only a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several modifications and improvements without departing from the inventive concept of the present invention, which all fall within the protection scope of the present invention.
Claims
1. A game server stress testing method, characterized in that: The following steps are involved: When the game is running, listen to the protocol operations sent by the client to the server, record the protocol name and request parameters as a protocol operation script and save it; Define the corresponding processing logic for each protocol, create a protocol processing base class and its subclasses, and encapsulate and implement the operation logic of each protocol; According to the recorded protocol command name, find the corresponding processing class from the protocol processing class pool, establish a mapping between the command and the processing class, and generate the protocol logic; The recorded protocol operation scripts are connected in series in the order of operation to form a complete protocol logic branch, which is used to simulate the real operation process of the player; Start multiple stress testing robots and load the protocol logic branch to perform stress testing on the server.
2. A game server stress testing method according to claim 1, characterized in that: Before monitoring the protocol operations sent by the client to the server, the method also performs task division, specifically: According to the different functional modules of the game, the server stress test is split into multiple different server stress test tasks, which are used to build and run different protocol logic branches for each stress test task.
3. A game server stress testing method according to claim 1, characterized in that: The protocol name and request parameters are recorded as a protocol operation script and saved. The specific method is: Create a protocol operation script file in the specified path of the stress test device; Use the debug.sethook function in Lua to register a hook to monitor all protocol requests and responses sent by the client to the server; After listening to the protocol request, record the protocol data, including the protocol name and request parameters; Write the protocol data into the protocol operation script file.
4. A game server stress testing method according to claim 3, characterized in that: When the protocol data is written into the protocol operation script file, an additional delay record is recorded before writing, and the delay record is the time difference from the last operation to the current operation.
5. A game server stress testing method according to claim 1, characterized in that: The specific method of generating the protocol logic is: Loading a protocol operation script, and parsing the operation record of the protocol operation script line by line; By parsing the obtained protocol name, an operation processing class is instantiated, and the operation processing class is responsible for defining the protocol and the request operation required to be executed by the protocol, and initiating a request to the server according to the protocol, and the initiated request includes the request parameters in the operation record; Each operation processing class includes at least one interaction with the server, and the interaction includes sending a request to the game server and receiving response data returned by the server.
6. A game server stress testing method according to claim 1, characterized in that: The method of starting multiple stress test robots and loading the protocol logic branch to perform stress test on the server includes the following steps: In the game environment, construct the main sandbox environment, load the static configuration data and export it to the game environment; Constructing a character sandbox environment in a new game environment, and passing in the static configuration data when loading; Create a new role in the role sandbox environment, load the protocol logic branch, initiate a protocol request to the server, and delay waiting operations.
7. A game server stress testing method according to claim 6, characterized in that: The role sandbox environment can be constructed in multiple forms, and each role sandbox environment can directly reuse the client logic code to establish a request with the server, send a protocol, and receive a response.
8. A game server stress testing system, characterized in that: The system is used to implement the method according to any one of claims 1 to 7, comprising: The task management module is used to split the server stress test task into multiple different server stress test tasks according to different functional modules of the game, and generate corresponding protocol logic branches; The script recording module is used to record the protocol operation script in the game, monitor the protocol request and response data sent by the client to the server, and record the protocol name, request parameters and delay records to generate the protocol operation script; The script parsing module is used to define the corresponding processing logic for each protocol, create the protocol processing base class and its subclasses, and encapsulate and implement the operation logic of each protocol; The protocol logic generation module is used to load the protocol operation script, parse the operation record line by line, obtain the corresponding processing class from the protocol processing class pool according to the protocol name, generate the protocol logic, and connect it in series according to the operation sequence to form a protocol logic branch; The stress test execution module is used to start multiple stress test robots, load the protocol logic branch in the sandbox environment, simulate the player's real operation process, and initiate a protocol request to the server and delay waiting operations; The sandbox management module is used to construct the main sandbox environment and the role sandbox environment, load static configuration data and protocol logic branches, and support the reuse of client logic code to interact with the server.
9. An electronic device, characterized in that: include: one or more processors; A memory for storing executable instructions; Network module, used to establish communication with the game server; Wherein, when the executable instructions in the memory are executed by the processor, the electronic device is enabled to implement the game server stress testing method as described in any one of items 1-7.
10. A storage medium storing computer executable instructions, characterized in that: When the computer executable instructions are executed by the processor, the device can execute the game server stress testing method as described in any one of claims 1-7.
Citation Information
Patent Citations
A game server pressure testing method and device
CN109698771A
Cited By
Pressure measuring method, pressure measuring system and pressure measuring program product
CN122111867A