TCP server test method and system, computer equipment and storage medium
By building a simulation client group of multiple simulation scenarios and simulating complex communication environments, the problem that existing TCP server testing methods cannot effectively simulate complex communication environments is solved, and effective testing and optimization of TCP server performance is achieved.
Patent Information
- Application Number
- CN202411921140.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-05-06
AI Technical Summary
The existing TCP server testing method cannot effectively simulate complex communication environments, resulting in communication exceptions in the actual interactive environment.
By constructing a simulation client group based on different simulation scenarios, the simulation client includes multiple simulation threads, which drive the simulation thread to send data packets to the TCP server according to the corresponding simulation scenarios, simulate random delay, packet loss, interruption, processing time and third-party device attacks, in order to optimize the performance of the TCP server.
This method can effectively test and optimize the performance of TCP server and improve its working stability in complex communication environments.
Smart Images

Figure CN119945937A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of communication testing, and in particular to a TCP server testing method, system, computer equipment and storage medium. Background Art
[0002] The current display monitoring system establishes TCP connections with multiple display terminals through a TCP server, sends corresponding commands to query the status information of the display terminals, and presents it on the website system. Depending on the scale of different customers, a monitoring system generally requires a TCP server to support hundreds or even thousands of display terminals. However, in the design, development, and testing phases of the monitoring system, it is not possible to directly use a large number of actual devices for testing, which will cause the equipment to occupy too much space and be too costly. Therefore, we need to write a test TCP client to simulate many display terminals to establish connections with the server to send and receive commands.
[0003] At present, a simulated client is generally built through a TCP client test program. The simulated client is used to establish a connection with the server, simulate the functional interface of the actual display terminal, and implement the sending and receiving of all commands, thereby verifying the stability of the server in this test environment to obtain a highly stable TCP server.
[0004] However, when the above-mentioned TCP server is running in an actual interactive environment, various complex problems may occur, resulting in abnormal communication. The reason is that the above-mentioned test method is to communicate in a local area network, so the network delay is very low and the probability of data packet loss is extremely low; at the same time, because it is an interface command of a simulated display terminal, all simulated clients use some pre-prepared test data as a return, resulting in a very short processing time. When the actual processing time exceeds the preset time, communication abnormalities and other problems are prone to occur. Therefore, there is an urgent need for a TCP server testing method, system, computer equipment and storage medium that can simulate different complex situations and perform tests to improve the stability of the TCP server. Summary of the invention
[0005] The technical problem to be solved by the present invention is to provide a TCP server testing method, system, computer equipment and storage medium, which can simulate different communication scenarios to test and optimize the performance of the TCP server, improve the working stability of the TCP server, and adapt to various complex communication environments.
[0006] In order to solve the above technical problems, the present invention provides a TCP server testing method, comprising: constructing a simulation client group based on different simulation scenarios, the simulation client group includes at least one simulation client, the simulation client includes multiple simulation threads, the simulation threads correspond to the simulation scenarios one by one, and the simulation scenarios are used to simulate the communication problems between the display terminal and the TCP server in an actual environment; establishing communication between the simulation client group and the TCP server; driving the simulation threads to send data packets to the TCP server according to the corresponding simulation scenarios to execute the corresponding simulation scenarios; optimizing the TCP server according to the execution results of the simulation scenarios.
[0007] As an improvement of the above-mentioned scheme, when the simulation scenario is a simulated random delay scenario, a delay value is set on the data packet corresponding to the simulated random delay scenario; or when the simulation scenario is a simulated random packet loss scenario, a packet loss probability value is set on the data packet corresponding to the simulated random packet loss scenario; or when the simulation scenario is a simulated random interruption scenario, reconnection access data is set on the data packet corresponding to the simulated random interruption scenario; or when the simulation scenario is a simulated random processing time scenario, a command processing time value is set on the data packet corresponding to the simulated random processing time scenario; or when the simulation scenario is a simulated third-party device attack scenario, a third-party device value is set on the data packet corresponding to the simulated third-party device attack scenario.
[0008] As an improvement of the above-mentioned scheme, the simulation scenario includes a simulated random delay scenario, and the step of optimizing the TCP server according to the execution result of the simulation scenario includes: within the specified communication time, the TCP server calculates the average delay value of all sent and received data packets communicating with the simulated client group; the TCP server determines whether the average delay value is within a first preset threshold range, and when it is judged as yes, it indicates that the scenario state under the simulated random delay scenario is stable, and when it is judged as no, it indicates that the scenario state under the simulated random delay scenario is unstable, and the TCP server is controlled to use the M part value of the average delay value as the new timeout time, wherein M is a constant.
[0009] As an improvement of the above-mentioned scheme, the simulation scenario includes a simulated random packet loss scenario, and the step of optimizing the TCP server according to the execution result of the simulation scenario includes: within a specified communication time, the TCP server calculates the average delay value of all sent and received data packets communicating with the simulated client group; the TCP server determines whether the average delay value is within a second preset threshold range, and when it is judged as yes, it indicates that the scenario state under the simulated random packet loss scenario is stable, and when it is judged as no, it indicates that the scenario state under the simulated random packet loss scenario is unstable, and the TCP server is controlled to use the M part value of the average delay value as the new timeout time, wherein M is a constant.
[0010] As an improvement of the above-mentioned scheme, the simulation scenario includes a simulated random interruption scenario, and the step of optimizing the TCP server according to the execution result of the simulation scenario includes: the TCP server periodically detects the current number of terminal connections and the current number of normal terminal connections; the TCP server calculates the terminal number difference between the current number of terminal connections and the current number of normal terminal connections, and determines whether the ratio of the terminal number difference to the current number of terminal connections is greater than or equal to a preset ratio. When the judgment is yes, it indicates that the scenario state under the simulated random interruption scenario is stable; when the judgment is no, it indicates that the scenario state under the simulated random interruption scenario is unstable, and the TCP server is controlled to self-check and close the communication connection of the simulated client terminal in the abnormal connection state.
[0011] As an improvement of the above-mentioned scheme, the simulation scenario includes a simulated random processing time scenario, and the step of optimizing the TCP server according to the execution result of the simulation scenario includes: the TCP server calculates the processing feedback time of each simulated client executing different commands; the TCP server determines whether the processing feedback time is less than a preset time threshold, and when it is judged as yes, it indicates that the scenario state under the simulated random processing time scenario is stable, and when it is judged as no, it indicates that the scenario state under the simulated random processing time scenario is unstable, and the TCP server is controlled to process commands that exceed the preset time threshold, and heartbeat packets are periodically sent to the corresponding simulated client at a preset interval to query the command processing status, until the command processing status received by the TCP server is the preset command processing end status or command feedback data is received.
[0012] As an improvement of the above-mentioned scheme, the simulation scenario includes a simulated third-party device attack scenario, and the step of optimizing the TCP server according to the execution result of the simulation scenario includes: the TCP server calculates the number of connections and the number of attacks of each simulated client within a preset time; the TCP server determines whether the number of connections or the number of attacks is less than or equal to the preset number, and when the judgment is yes, it indicates that the scenario state under the simulated third-party device attack scenario is stable, and when the judgment is no, it indicates that the scenario state under the simulated third-party device attack scenario is unstable, and the TCP server is controlled to prohibit the communication connection of the corresponding simulated client.
[0013] Correspondingly, the present invention also provides a TCP server testing system, comprising: a construction module, used to construct a simulated client group based on different simulation scenarios, the simulated client group includes at least one simulated client, the simulated client includes multiple simulation threads, the simulation threads correspond to the simulation scenarios one by one, and the simulation scenarios are used to simulate the communication problems between the display terminal and the TCP server in an actual environment; a communication module, used to establish communication between the simulated client group and the TCP server; a control module, used to drive the simulation threads to send data packets to the TCP server according to the corresponding simulation scenarios to execute the corresponding simulation scenarios; an optimization module, used to optimize the TCP server according to the execution results of the simulation scenarios.
[0014] Correspondingly, the present invention further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0015] Accordingly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0016] The beneficial effects of implementing the present invention are:
[0017] The present invention can construct a plurality of simulated client groups with different simulated scenarios to serve as complex communication situations of display screen terminals in different scenarios. By performing test communication work of a plurality of simulated scenarios between the simulated client and the TCP server, the performance of the TCP server can be tested and optimized, thereby improving the working stability of the TCP server to adapt to various complex communication environments. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a flow chart of the TCP server testing method of the present invention;
[0019] Figure 2 It is a schematic diagram of the structure of the TCP server testing system of the present invention;
[0020] Figure 3 is a schematic diagram of the structure of the control module of the present invention;
[0021] Figure 4 It is a structural schematic diagram of the optimization module of the present invention. DETAILED DESCRIPTION
[0022] In order to make the objectives, technical solutions and advantages of the present invention more clear, the present invention will be further described in detail below with reference to the accompanying drawings.
[0023] like Figure 1 As shown, a specific embodiment of the present invention provides a TCP server testing method, including:
[0024] S101, constructing a simulation client group based on different simulation scenarios, wherein the simulation client group includes at least one simulation client, and the simulation client includes multiple simulation threads, and the simulation threads correspond to the simulation scenarios one by one, and the simulation scenarios are used to simulate the communication problem between the display terminal and the TCP server in the actual environment;
[0025] S102, establishing communication between the simulated client group and the TCP server;
[0026] It should be noted that the different simulation scenarios include but are not limited to simulated random delay scenarios, simulated random packet loss scenarios, simulated random interruption scenarios, simulated random processing time scenarios and simulated third-party device attack scenarios; these actual scenarios are simulated to test the working stability of the TCP server in multiple different scenarios.
[0027] S103, driving the simulation threads to send data packets to the TCP server according to the corresponding simulation scenarios to execute the corresponding simulation scenarios;
[0028] It should be noted that by constructing the above-mentioned different simulation scenarios as the complex communication situations of the actual display terminal in different scenarios, the working stability of the TCP server in multiple scenarios is accurately tested by controlling the simulated client groups of multiple simulation scenarios to obtain the test results, i.e., the execution results, in different simulation scenarios.
[0029] S104: Optimize the TCP server according to the execution result of the simulation scenario.
[0030] It should be noted that when the execution result of any simulation scenario is that the scenario state is unstable, the TCP server can be optimized according to the corresponding scenario optimization means to improve the working stability of the TCP server in the corresponding scenario, thereby improving the adaptability of the TCP server in various actual complex communication environments.
[0031] Specifically, the simulation tests and optimization situations under different simulation scenarios are described one by one as follows:
[0032] 1. Simulating random delay scenarios
[0033] When the simulation scenario is a simulated random delay scenario, a delay value is set on the data packet corresponding to the simulated random delay scenario so that the simulated client under the simulation scenario adds different delay values when sending and receiving data packets; wherein the delay value preferably ranges from 0.5 to 10s, but is not limited thereto.
[0034] During the specified communication time, the TCP server calculates the average delay value of all sent and received data packets communicating with the simulated client group;
[0035] The TCP server determines whether the average delay value is within a first preset threshold range,
[0036] If the judgment is yes, it means that the situation state is stable under the simulated random delay scenario.
[0037] When the judgment is no, it indicates that the scenario state under the simulated random delay scenario is unstable, and the TCP server is controlled to use the M-part value of the average delay value as the new timeout time, where M is a constant.
[0038] It should be noted that in the simulated random delay scenario, multiple simulated clients in the scenario can be controlled to add different delay values to the sent or received data packets to simulate the communication test between the display terminal and the TCP server in the actual random delay scenario. For example, in reality, the display terminal accesses the Internet through a phone card. Due to the signal strength of the location, the network speed of the operator and the distance from the server, the communication timeliness will be affected, resulting in different communication delay processing situations, affecting the working stability of the TCP server.
[0039] Within the specified communication time, if the average delay value calculated by the TCP server is within the first preset threshold range, it means that the scenario state of the TCP server in the simulated random delay scenario is stable; if the average delay value calculated by the TCP server is not within the first preset threshold range, it means that the scenario state of the TCP server in the simulated random delay scenario is unstable, and the TCP server cannot work effectively and stably, and is prone to abnormalities. In response to the unstable execution result of the scenario state, the TCP server can be controlled to use the M part of the value of the average delay value as the new timeout time, so as to dynamically and adaptively increase or decrease the timeout time of the TCP server, so as to adapt to the situation where the average delay of the overall data packet is too long or too short, and improve the timeout waiting processing performance of the TCP server, thereby ensuring the communication timeliness and improving the working stability of the TCP server.
[0040] Preferably, the first preset threshold range A is preferably (B*C%)≤A<(B*D%), wherein B is the current timeout time, B is preferably 10s, C is preferably 30, and D is preferably 70, but is not limited thereto.
[0041] Accordingly, the current first preset threshold range A is 3s≤A<7s. When the average delay value is greater than 7S, it means that the overall network delay of the server is at risk of exceeding the currently set timeout time, and there is an unstable communication situation. At this time, the TCP server is in an unstable state in this scenario and needs to be optimized; when the average delay value is 2S, it means that the network delay is much less than the current timeout time, and there is no need to wait for such a long timeout time, which is easy to reduce the communication timeliness, causing data congestion or accumulation, and there is an unstable communication risk. At this time, the TCP server is also in an unstable state in this scenario. When the average delay value is in the first preset threshold range A, it means that the TCP server is in a stable state in this scenario and does not need to be optimized.
[0042] Preferably, M is preferably 2, but not limited thereto. For the unstable execution result of the scenario state, for example, when the average delay value is greater than 7S, the new timeout time in the TCP server is 14s, and the first preset threshold range A is 4.2s≤A<9.8s, so as to reduce the risk that the network delay will exceed the currently set timeout time, improve data processing stability, and thus improve the working stability of the TCP server; for example, when the average delay value is 2S, the new timeout time in the TCP server is 4s, and the first preset threshold range A is 1.2s≤A<2.8s, so as to improve the data communication timeliness, thereby improving the working stability of the TCP server.
[0043] 2. Simulate random packet loss scenario
[0044] When the simulation scenario is a simulated random packet loss scenario, a packet loss probability value is set on the data packet corresponding to the simulated random packet loss scenario, so that the simulated client in the simulation scenario ignores a corresponding proportion of data packets in some sent data packets or some received data packets according to the corresponding packet loss probability value. For example, if the packet loss probability value is 20%, when 5 data packets are sent, one data packet is ignored, or when 5 data packets are received, one data packet is ignored.
[0045] During the specified communication time, the TCP server calculates the average delay value of all sent and received data packets communicating with the simulated client group;
[0046] The TCP server determines whether the average delay value is within a second preset threshold range,
[0047] If the judgment is yes, it means that the scenario state is stable under the simulated random packet loss scenario.
[0048] When the judgment is no, it indicates that the scenario state under the simulated random packet loss scenario is unstable, and the TCP server is controlled to use the M-part value of the average delay value as the new timeout time, where M is a constant.
[0049] It should be noted that, in the simulated random packet loss scenario, multiple simulated clients in the scenario can be controlled to ignore a corresponding proportion of packets on some of the sent or received packets, so as to simulate the communication test between the display terminal and the TCP server in the actual random packet loss scenario. Within the specified communication time, if the average delay value calculated by the TCP server is within the second preset threshold range, it means that in the case of packet loss, the overall network delay is also within the timeout time that the TCP server can withstand, and the TCP server can work stably. At this time, the scenario state of the TCP server in the simulated random packet loss scenario is stable; if the average delay value calculated by the TCP server is not within the second preset threshold range, it means that the overall network delay may exceed or has exceeded the timeout time that the TCP server can withstand, and the TCP server cannot work stably and is prone to abnormalities. At this time, the scenario state of the TCP server in the simulated random packet loss scenario is unstable. In response to the unstable execution result of this scenario, the TCP server can be controlled to use the M part of the average delay value as the new timeout time, so as to dynamically and adaptively increase or decrease the timeout time of the TCP server to adapt to the situation where the average delay of the overall data packet is too long or too short, and improve the timeout waiting processing performance of the TCP server, thereby ensuring the communication timeliness and improving the working stability of the TCP server.
[0050] Preferably, the second preset threshold range is the same as the first preset threshold range mentioned above, and will not be described in detail here.
[0051] 3. Simulating random outage scenarios
[0052] When the simulated scenario is a simulated random interruption scenario, reconnection access data is set on a data packet corresponding to the simulated random interruption scenario.
[0053] The TCP server periodically detects the current number of terminal connections and the current number of normal terminal connections;
[0054] The TCP server calculates a terminal quantity difference between the current terminal quantity and the current normal terminal quantity, and determines whether a ratio of the terminal quantity difference to the current terminal quantity is greater than or equal to a preset ratio.
[0055] If the judgment is yes, it means that the situation state is stable under the simulated random interruption scenario.
[0056] When the judgment is no, it indicates that the scenario state in the simulated random interruption scenario is unstable, and the TCP server is controlled to self-check and close the communication connection of the simulated client terminal in the abnormal connection state.
[0057] It should be noted that in the simulated random interruption scenario, multiple simulated clients in the scenario can be controlled to send reconnection data packets to the TCP server after an unexpected or normal interruption, so as to simulate the communication test between the display terminal and the TCP server in the actual random interruption scenario. For example, in some normal actual business logic, some display terminals need to actively disconnect the TCP connection and reconnect; if the display terminal suddenly loses power, the TCP connection currently maintained by the server may not be discovered immediately. When the display terminal that has accidentally lost power reconnects, it may cause network connection blockage, affecting the working stability of the TCP server.
[0058] In the simulation test, the TCP server can periodically detect the current number of terminal connections and the current number of normal terminal connections and calculate the difference in the number of terminals between the current number of terminal connections and the current number of normal terminal connections. If the ratio of the difference in the number of terminals to the current number of terminal connections is greater than or equal to the preset ratio, it means that the current TCP connection state of the TCP server is normal and the communication is stable. At this time, the scenario state of the TCP server in the simulated random interruption scenario is stable; if the ratio of the difference in the number of terminals to the current number of terminal connections is less than or equal to the preset ratio, it means that the current TCP connection state of the TCP server is abnormal, there are more abnormal connection terminals or inactive connection terminals, occupying more server resources and connection channels, which will affect other normal and active terminal connections. At this time, the scenario state of the TCP server in the simulated random interruption scenario is unstable. In view of the unstable execution result of the scenario state, the TCP server can be controlled to self-check the simulated client terminals or inactive simulated client terminals that are abnormally connected to it and close the communication connections of these simulated client terminals to release resources, ensure that they will not always occupy the total number of connections of the TCP server, so that the TCP server can provide more idle communication connection channels and resources for the normal simulated client terminals, i.e., the display screen terminals, thereby improving the working stability of the TCP server.
[0059] Preferably, the timing time is preferably 10 minutes, but is not limited thereto.
[0060] Preferably, the preset ratio is preferably 95%, but is not limited thereto.
[0061] 4. Simulating random processing time scenarios
[0062] When the simulation scenario is a simulation random processing time scenario, a command processing time value is set on a data packet corresponding to the simulation random processing time scenario.
[0063] The TCP server calculates the processing feedback time of each simulated client executing different commands;
[0064] The TCP server determines whether the processing feedback time is less than a preset time threshold,
[0065] If the judgment is yes, it means that the situation state is stable under the simulated random processing time scenario.
[0066] When the judgment is no, it means that the scenario state under the simulated random processing time scenario is unstable, and the TCP server is controlled to process commands that exceed the preset time threshold, and heartbeat packets are periodically sent to the corresponding simulated client at a preset interval to query the command processing status until the command processing status received by the TCP server is the preset command processing end state or command feedback data is received.
[0067] It should be noted that in the simulated random interruption scenario, the simulated client in this scenario can be controlled to add different command processing time values according to different command data packets to simulate different command processing times for different commands of the display terminal, thereby simulating the communication test between the display terminal and the TCP server in different actual command processing time scenarios. For example, if the actual display terminal has different command processing times, the display terminal may have different processing times when processing different business interfaces. Command A may take 1s to process, while command B may take 20s to process. The difference is relatively large, which affects the TCP server's judgment of the terminal command timeout time, thereby affecting the working stability of the TCP server.
[0068] In the simulation test, if the processing feedback time of the corresponding command calculated by the TCP server is less than the preset time threshold, it means that some regular or simple control commands of the TCP server can be executed normally and work stably. At this time, the scenario state of the TCP server in the simulated random processing time scenario is stable; otherwise, it means that the TCP server may have abnormal risks. At this time, the scenario state of the TCP server in the simulated random processing time scenario is unstable. Special processing is required for other complex commands to determine whether the complex instructions are executed normally or need to be resent due to abnormalities, so as to ensure the working stability of the TCP server. For example, the processing time of a regular or simple control command is 0.2s, the current timeout is 10s, and the processing feedback time is 10.2s, which meets the requirements; if a complex command, such as upgrading the motherboard, is expected to take 30s to process, that is, the total timeout of this command is 40s, then this command needs to be specially monitored to determine whether the complex instruction is executed normally or needs to be resent due to abnormalities.
[0069] The processing feedback time includes the command processing time of the simulated client + the current timeout time. The timeout time is updated synchronously with the timeout time of other scenarios mentioned above.
[0070] In response to the unstable execution result of this scenario, the TCP server can be controlled to process commands that exceed the preset time threshold, and send heartbeat packets to the corresponding simulated client at preset intervals to query the command processing status, until the command processing status received by the TCP server is the preset command processing end status or command feedback data is received, so as to timely know the execution status of the command processing by the simulated client, such as whether the execution has been completed normally or needs to be resent due to an exception, etc., to ensure that the execution of all functional commands can be monitored to ensure the accurate execution of functional commands and improve the working stability of the TCP server.
[0071] Preferably, the preset interval time is preferably 5 minutes, but not limited thereto.
[0072] 5. Simulate third-party device attack scenarios
[0073] When the simulation scenario is a simulation of a third-party device attack scenario, a third-party device value is set on a data packet corresponding to the simulation of the third-party device attack scenario.
[0074] The TCP server calculates the number of connections and the number of attacks of each simulated client within a preset time;
[0075] The TCP server determines whether the number of connections or the number of attacks is less than or equal to a preset number,
[0076] If the answer is yes, it means that the scenario status is stable under the simulated third-party device attack scenario.
[0077] When the judgment is no, it indicates that the scenario state in the simulated third-party device attack scenario is unstable, and the TCP server is controlled to prohibit the communication connection of the corresponding simulated client.
[0078] Preferably, the preset time is 1 minute, but is not limited thereto.
[0079] Preferably, the preset number of times is 3 times, but is not limited thereto.
[0080] It should be noted that in the simulated third-party device attack scenario, the third-party device value, i.e., the third-party device ID, can be set on the data packet of the simulated client in the scenario to simulate the communication test between the third-party display terminal and the TCP server in the actual third-party device attack scenario. Among them, one part of the simulated client requests a communication connection from the TCP server as a third-party device, and the other part of the simulated client sends junk data to the TCP server as a third-party device to attack the TCP server, so as to simulate the illegal connection and illegal attack of other terminals in reality, so as to test the pressure resistance and working stability of the TCP server when it is illegally connected and attacked by other terminals.
[0081] In the simulation test, if the number of connections or attacks calculated by the TCP server is less than the preset number, it means that it is within the normal stress resistance range of the TCP server, and the TCP server is working stably. At this time, the scenario state of the TCP server in the simulated third-party device attack scenario is stable; if the number of connections or attacks calculated by the TCP server is greater than or equal to the preset number, it means that it has exceeded the normal stress resistance range of the TCP server, and there is an abnormal risk, which will affect the normal operation of the TCP server and may cause the server to crash. At this time, the scenario state of the TCP server in the simulated third-party device attack scenario is unstable.
[0082] In response to the unstable execution result of this scenario, the TCP server can be controlled to prohibit the communication connection of the corresponding simulated client, that is, if the connection or attack requested by the same simulated client with the same IP exceeds 3 times within 1 minute, it will be judged as an illegal device. This IP will be disabled within a specified time (such as 1 hour or 3 hours, etc.) to prevent it from communicating, thereby alleviating the pressure on the TCP server and improving the pressure resistance of the TCP server's network communication, thereby improving the working stability of the TCP server.
[0083] like Figure 2 As shown, the present invention also provides a TCP server testing system, comprising:
[0084] Construction module 1, used to construct a simulation client group based on different simulation scenarios, the simulation client group includes at least one simulation client, the simulation client includes multiple simulation threads, the simulation threads correspond to the simulation scenarios one by one, and the simulation scenarios are used to simulate the communication problem between the display screen and the TCP server in the actual environment;
[0085] Communication module 2, used to establish communication between the simulated client group and the TCP server;
[0086] It should be noted that the different simulation scenarios include but are not limited to simulated random delay scenarios, simulated random packet loss scenarios, simulated random interruption scenarios, simulated random processing time scenarios and simulated third-party device attack scenarios; these actual scenarios are simulated to test the working stability of the TCP server in multiple different scenarios.
[0087] Control module 3, used for driving the simulation threads to send data packets to the TCP server according to the corresponding simulation scenarios to execute the corresponding simulation scenarios;
[0088] It should be noted that by constructing the above-mentioned different simulation scenarios as the complex communication situations of the actual display terminal in different scenarios, the working stability of the TCP server in multiple scenarios is accurately tested by controlling the simulated client groups of multiple simulation scenarios to obtain the test results, i.e., the execution results, in different simulation scenarios.
[0089] The optimization module 4 is used to optimize the TCP server according to the execution result of the simulation scenario.
[0090] It should be noted that when the execution result of any simulation scenario is that the scenario state is unstable, the TCP server can be optimized according to the corresponding scenario optimization means to improve the working stability of the TCP server in the corresponding scenario, thereby improving the adaptability of the TCP server in various actual complex communication environments.
[0091] Specifically, Figures 3 to 4 As shown, the control module 3 includes a first scenario control unit 31, a second scenario control unit 32, a third scenario control unit 33, a fourth scenario control unit 34 and a fifth scenario control unit 35; the optimization module 4 includes a first scenario optimization unit 41, a second scenario optimization unit 42, a third scenario optimization unit 43, a fourth scenario optimization unit 44 and a fifth scenario optimization unit 45. The working principles of the scenario control units and scenario optimization units under different simulation scenarios are described one by one as follows:
[0092] 1. Simulating random delay scenarios
[0093] The first scenario control unit 31 is used to control the simulated client to set a delay value on the data packet corresponding to the simulated random delay scenario when the simulated scenario is a simulated random delay scenario, so that the simulated client under the simulated scenario adds different delay values when sending and receiving data packets; wherein the delay value preferably ranges from 0.5 to 10s, but is not limited thereto.
[0094] The first scenario optimization unit 41 is used to control the TCP server to calculate the average delay value of all sent and received data packets communicating with the simulated client group within the specified communication time, and determine whether the average delay value is within a first preset threshold range. When it is determined to be yes, it indicates that the scenario state under the simulated random delay scenario is stable; when it is determined to be no, it indicates that the scenario state under the simulated random delay scenario is unstable, and the TCP server is controlled to use the M-part value of the average delay value as the new timeout time, wherein M is a constant.
[0095] It should be noted that in the simulated random delay scenario, multiple simulated clients in the scenario can be controlled to add different delay values to the sent or received data packets to simulate the communication test between the display terminal and the TCP server in the actual random delay scenario. For example, in reality, the display terminal accesses the Internet through a phone card. Due to the signal strength of the location, the network speed of the operator and the distance from the server, the communication timeliness will be affected, resulting in different communication delay processing situations, affecting the working stability of the TCP server.
[0096] Within the specified communication time, if the average delay value calculated by the TCP server is within the first preset threshold range, it means that the scenario state of the TCP server in the simulated random delay scenario is stable; if the average delay value calculated by the TCP server is not within the first preset threshold range, it means that the scenario state of the TCP server in the simulated random delay scenario is unstable, and the TCP server cannot work effectively and stably, and is prone to abnormalities. In response to the unstable execution result of the scenario state, the TCP server can be controlled to use the M part of the value of the average delay value as the new timeout time, so as to dynamically and adaptively increase or decrease the timeout time of the TCP server, so as to adapt to the situation where the average delay of the overall data packet is too long or too short, and improve the timeout waiting processing performance of the TCP server, thereby ensuring the communication timeliness and improving the working stability of the TCP server.
[0097] Preferably, the first preset threshold range A is preferably (B*C%)≤A<(B*D%), wherein B is the current timeout time, B is preferably 10s, C is preferably 30, and D is preferably 70, but is not limited thereto.
[0098] Accordingly, the current first preset threshold range A is 3s≤A<7s. When the average delay value is greater than 7S, it means that the overall network delay of the server is at risk of exceeding the currently set timeout time, and there is an unstable communication situation. At this time, the TCP server is in an unstable state in this scenario and needs to be optimized; when the average delay value is 2S, it means that the network delay is much less than the current timeout time, and there is no need to wait for such a long timeout time, which is easy to reduce the communication timeliness, causing data congestion or accumulation, and there is an unstable communication risk. At this time, the TCP server is also in an unstable state in this scenario. When the average delay value is in the first preset threshold range A, it means that the TCP server is in a stable state in this scenario and does not need to be optimized.
[0099] Preferably, M is preferably 2, but not limited thereto. For the unstable execution result of the scenario state, for example, when the average delay value is greater than 7S, the new timeout time in the TCP server is 14s, and the first preset threshold range A is 4.2s≤A<9.8s, so as to reduce the risk that the network delay will exceed the currently set timeout time, improve data processing stability, and thus improve the working stability of the TCP server; for example, when the average delay value is 2S, the new timeout time in the TCP server is 4s, and the first preset threshold range A is 1.2s≤A<2.8s, so as to improve the data communication timeliness, thereby improving the working stability of the TCP server.
[0100] 2. Simulate random packet loss scenario
[0101] The second scenario control unit 32 is used to control the simulated client to set a packet loss probability value on the data packet corresponding to the simulated random packet loss scenario when the simulated scenario is a simulated random packet loss scenario, so that the simulated client in the simulated scenario ignores a corresponding proportion of data packets in some sent data packets or some received data packets according to the corresponding packet loss probability value. For example, if the packet loss probability value is 20%, when sending 5 data packets, one data packet is ignored, or when receiving 5 data packets, one data packet is ignored.
[0102] The second scenario optimization unit 42 is used to control the TCP server to calculate the average delay value of all sent and received data packets communicating with the simulated client group within the specified communication time, and determine whether the average delay value is within a second preset threshold range. When it is determined to be yes, it indicates that the scenario state under the simulated random packet loss scenario is stable. When it is determined to be no, it indicates that the scenario state under the simulated random packet loss scenario is unstable. The TCP server is controlled to use the M-part value of the average delay value as the new timeout time, wherein M is a constant.
[0103] It should be noted that, in the simulated random packet loss scenario, multiple simulated clients in the scenario can be controlled to ignore a corresponding proportion of packets on some of the sent or received packets, so as to simulate the communication test between the display terminal and the TCP server in the actual random packet loss scenario. Within the specified communication time, if the average delay value calculated by the TCP server is within the second preset threshold range, it means that in the case of packet loss, the overall network delay is also within the timeout time that the TCP server can withstand, and the TCP server can work stably. At this time, the scenario state of the TCP server in the simulated random packet loss scenario is stable; if the average delay value calculated by the TCP server is not within the second preset threshold range, it means that the overall network delay may exceed or has exceeded the timeout time that the TCP server can withstand, and the TCP server cannot work stably and is prone to abnormalities. At this time, the scenario state of the TCP server in the simulated random packet loss scenario is unstable. In response to the unstable execution result of this scenario, the TCP server can be controlled to use the M part of the average delay value as the new timeout time, so as to dynamically and adaptively increase or decrease the timeout time of the TCP server to adapt to the situation where the average delay of the overall data packet is too long or too short, and improve the timeout waiting processing performance of the TCP server, thereby ensuring the communication timeliness and improving the working stability of the TCP server.
[0104] Preferably, the second preset threshold range is the same as the first preset threshold range mentioned above, and will not be described in detail here.
[0105] 3. Simulating random outage scenarios
[0106] The third scenario control unit 33 controls the simulated client to set reconnection access data on a data packet corresponding to the simulated random interruption scenario when the simulated scenario is a simulated random interruption scenario.
[0107] The third scenario optimization unit 43 is used to control the TCP server to periodically detect the current number of terminal connections and the current number of normal terminal connections, calculate the terminal number difference between the current number of terminal connections and the current number of normal terminal connections, and determine whether the ratio of the terminal number difference to the current number of terminal connections is greater than or equal to a preset ratio. When it is determined to be yes, it indicates that the scenario state under the simulated random interruption scenario is stable. When it is determined to be no, it indicates that the scenario state under the simulated random interruption scenario is unstable. The TCP server is controlled to self-check and close the communication connection of the simulated client terminal in the abnormal connection state.
[0108] It should be noted that in the simulated random interruption scenario, multiple simulated clients in the scenario can be controlled to send reconnection data packets to the TCP server after an unexpected or normal interruption, so as to simulate the communication test between the display terminal and the TCP server in the actual random interruption scenario. For example, in some normal actual business logic, some display terminals need to actively disconnect the TCP connection and reconnect; if the display terminal suddenly loses power, the TCP connection currently maintained by the server may not be discovered immediately. When the display terminal that has accidentally lost power reconnects, it may cause network connection blockage, affecting the working stability of the TCP server.
[0109] In the simulation test, the TCP server can periodically detect the current number of terminal connections and the current number of normal terminal connections and calculate the difference in the number of terminals between the current number of terminal connections and the current number of normal terminal connections. If the ratio of the difference in the number of terminals to the current number of terminal connections is greater than or equal to the preset ratio, it means that the current TCP connection state of the TCP server is normal and the communication is stable. At this time, the scenario state of the TCP server in the simulated random interruption scenario is stable; if the ratio of the difference in the number of terminals to the current number of terminal connections is less than or equal to the preset ratio, it means that the current TCP connection state of the TCP server is abnormal, there are more abnormal connection terminals or inactive connection terminals, occupying more server resources and connection channels, which will affect other normal and active terminal connections. At this time, the scenario state of the TCP server in the simulated random interruption scenario is unstable. In view of the unstable execution result of the scenario state, the TCP server can be controlled to self-check the simulated client terminals or inactive simulated client terminals that are abnormally connected to it and close the communication connections of these simulated client terminals to release resources, ensure that they will not always occupy the total number of connections of the TCP server, so that the TCP server can provide more idle communication connection channels and resources for the normal simulated client terminals, i.e., the display screen terminals, thereby improving the working stability of the TCP server.
[0110] Preferably, the timing time is preferably 10 minutes, but is not limited thereto.
[0111] Preferably, the preset ratio is preferably 95%, but is not limited thereto.
[0112] 4. Simulating random processing time scenarios
[0113] The fourth scenario control unit 34 is used to control the simulated client to set the command processing time value on the data packet corresponding to the simulated random processing time scenario when the simulated scenario is a simulated random processing time scenario.
[0114] The fourth scenario optimization unit 44 is used to control the TCP server to calculate the processing feedback time of each simulated client executing different commands, and to determine whether the processing feedback time is less than a preset time threshold. When it is determined to be yes, it indicates that the scenario state under the simulated random processing time scenario is stable; when it is determined to be no, it indicates that the scenario state under the simulated random processing time scenario is unstable. The TCP server is controlled to process commands that exceed the preset time threshold, and to periodically send heartbeat packets to the corresponding simulated client at preset intervals to query the command processing status until the command processing status received by the TCP server is the preset command processing end status or command feedback data is received.
[0115] It should be noted that in the simulated random interruption scenario, the simulated client in this scenario can be controlled to add different command processing time values according to different command data packets to simulate different command processing times for different commands of the display terminal, thereby simulating the communication test between the display terminal and the TCP server in different actual command processing time scenarios. For example, if the actual display terminal has different command processing times, the display terminal may have different processing times when processing different business interfaces. Command A may take 1s to process, while command B may take 20s to process. The difference is relatively large, which affects the TCP server's judgment of the terminal command timeout time, thereby affecting the working stability of the TCP server.
[0116] In the simulation test, if the processing feedback time of the corresponding command calculated by the TCP server is less than the preset time threshold, it means that some regular or simple control commands of the TCP server can be executed normally and work stably. At this time, the scenario state of the TCP server in the simulated random processing time scenario is stable; otherwise, it means that the TCP server may have abnormal risks. At this time, the scenario state of the TCP server in the simulated random processing time scenario is unstable. Special processing is required for other complex commands to determine whether the complex instructions are executed normally or need to be resent due to abnormalities, so as to ensure the working stability of the TCP server. For example, the processing time of a regular or simple control command is 0.2s, the current timeout is 10s, and the processing feedback time is 10.2s, which meets the requirements; if a complex command, such as upgrading the motherboard, is expected to take 30s to process, that is, the total timeout of this command is 40s, then this command needs to be specially monitored to determine whether the complex instruction is executed normally or needs to be resent due to abnormalities.
[0117] The processing feedback time includes the command processing time of the simulated client + the current timeout time. The timeout time is updated synchronously with the timeout time of other scenarios mentioned above.
[0118] In response to the unstable execution result of this scenario, the TCP server can be controlled to process commands that exceed the preset time threshold, and send heartbeat packets to the corresponding simulated client at preset intervals to query the command processing status, until the command processing status received by the TCP server is the preset command processing end status or command feedback data is received, so as to timely know the execution status of the command processing by the simulated client, such as whether the execution has been completed normally or needs to be resent due to an exception, etc., to ensure that the execution of all functional commands can be monitored to ensure the accurate execution of functional commands and improve the working stability of the TCP server.
[0119] Preferably, the preset interval time is preferably 5 minutes, but not limited thereto.
[0120] 5. Simulate third-party device attack scenarios
[0121] The fifth scenario control unit 35 controls the simulation client to set a third-party device value on a data packet corresponding to the simulated third-party device attack scenario when the simulated scenario is a simulated third-party device attack scenario.
[0122] The fifth scenario optimization unit 45 is used to control the TCP server to calculate the number of connections and the number of attacks of each simulated client within a preset time; the TCP server determines whether the number of connections or the number of attacks is less than or equal to the preset number. When it is judged as yes, it means that the scenario state under the simulated third-party device attack scenario is stable; when it is judged as no, it means that the scenario state under the simulated third-party device attack scenario is unstable, and the TCP server is controlled to prohibit the communication connection of the corresponding simulated client.
[0123] Preferably, the preset time is 1 minute, but is not limited thereto.
[0124] Preferably, the preset number of times is 3 times, but is not limited thereto.
[0125] It should be noted that in the simulated third-party device attack scenario, the third-party device value, i.e., the third-party device ID, can be set on the data packet of the simulated client in the scenario to simulate the communication test between the third-party display terminal and the TCP server in the actual third-party device attack scenario. Among them, one part of the simulated client requests a communication connection from the TCP server as a third-party device, and the other part of the simulated client sends junk data to the TCP server as a third-party device to attack the TCP server, so as to simulate the illegal connection and illegal attack of other terminals in reality, so as to test the pressure resistance and working stability of the TCP server when it is illegally connected and attacked by other terminals.
[0126] In the simulation test, if the number of connections or attacks calculated by the TCP server is less than the preset number, it means that it is within the normal stress resistance range of the TCP server, and the TCP server is working stably. At this time, the scenario state of the TCP server in the simulated third-party device attack scenario is stable; if the number of connections or attacks calculated by the TCP server is greater than or equal to the preset number, it means that it has exceeded the normal stress resistance range of the TCP server, and there is an abnormal risk, which will affect the normal operation of the TCP server and may cause the server to crash. At this time, the scenario state of the TCP server in the simulated third-party device attack scenario is unstable.
[0127] In response to the unstable execution result of this scenario, the TCP server can be controlled to prohibit the communication connection of the corresponding simulated client, that is, if the connection or attack requested by the same simulated client with the same IP exceeds 3 times within 1 minute, it will be judged as an illegal device. This IP will be disabled within a specified time (such as 1 hour or 3 hours, etc.) to prevent it from communicating, thereby alleviating the pressure on the TCP server and improving the pressure resistance of the TCP server's network communication, thereby improving the working stability of the TCP server.
[0128] Correspondingly, the present invention further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0129] Accordingly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0130] To sum up, the present invention can construct a plurality of simulated client groups with different simulation scenarios to serve as complex communication situations of display screen terminals in different scenarios. By simulating the client and the TCP server to perform test communications in a plurality of simulation scenarios, the TCP server performance can be tested and optimized, thereby improving the working stability of the TCP server to adapt to various complex communication environments.
[0131] The above is a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several improvements and modifications without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A TCP server testing method, characterized in that: include: Constructing a simulation client group based on different simulation scenarios, wherein the simulation client group includes at least one simulation client, and the simulation client includes multiple simulation threads, and the simulation threads correspond to the simulation scenarios one by one, and the simulation scenarios are used to simulate the communication problem between the display terminal and the TCP server in the actual environment; Establishing communication between the simulated client group and the TCP server; Driving the simulation threads to send data packets to the TCP server according to the corresponding simulation scenarios to execute the corresponding simulation scenarios; The TCP server is optimized according to the execution result of the simulation scenario.
2. The TCP server testing method according to claim 1, characterized in that: When the simulation scenario is a simulated random delay scenario, setting a delay value on a data packet corresponding to the simulated random delay scenario; or When the simulation scenario is a simulated random packet loss scenario, setting a packet loss probability value on a data packet corresponding to the simulated random packet loss scenario; or When the simulated scenario is a simulated random interruption scenario, setting reconnection access data on a data packet corresponding to the simulated random interruption scenario; or When the simulation scenario is a simulated random processing time scenario, setting a command processing time value on a data packet corresponding to the simulated random processing time scenario; or When the simulation scenario is a simulation of a third-party device attack scenario, a third-party device value is set on a data packet corresponding to the simulation of the third-party device attack scenario.
3. The TCP server testing method according to claim 2, characterized in that: The simulation scenario includes a simulation random delay scenario, and the step of optimizing the TCP server according to the execution result of the simulation scenario includes: During the specified communication time, the TCP server calculates the average delay value of all sent and received data packets communicating with the simulated client group; The TCP server determines whether the average delay value is within a first preset threshold range, If the judgment is yes, it means that the situation state is stable under the simulated random delay scenario. When the judgment is no, it indicates that the scenario state under the simulated random delay scenario is unstable, and the TCP server is controlled to use the M-part value of the average delay value as the new timeout time, where M is a constant.
4. The TCP server testing method according to claim 2, characterized in that: The simulation scenario includes simulating a random packet loss scenario, and the step of optimizing the TCP server according to the execution result of the simulation scenario includes: During the specified communication time, the TCP server calculates the average delay value of all sent and received data packets communicating with the simulated client group; The TCP server determines whether the average delay value is within a second preset threshold range, If the judgment is yes, it means that the scenario state is stable under the simulated random packet loss scenario. When the judgment is no, it indicates that the scenario state under the simulated random packet loss scenario is unstable, and the TCP server is controlled to use the M-part value of the average delay value as the new timeout time, where M is a constant.
5. The TCP server testing method according to claim 2, characterized in that: The simulation scenario includes a simulation of a random interruption scenario, and the step of optimizing the TCP server according to the execution result of the simulation scenario includes: The TCP server periodically detects the current number of terminal connections and the current number of normal terminal connections; The TCP server calculates a terminal quantity difference between the current terminal quantity and the current normal terminal quantity, and determines whether a ratio of the terminal quantity difference to the current terminal quantity is greater than or equal to a preset ratio. If the judgment is yes, it means that the situation state is stable under the simulated random interruption scenario. When the judgment is no, it indicates that the scenario state in the simulated random interruption scenario is unstable, and the TCP server is controlled to self-check and close the communication connection of the simulated client terminal in the abnormal connection state.
6. The TCP server testing method according to claim 2, characterized in that: The simulation scenario includes a simulation random processing time scenario, and the step of optimizing the TCP server according to the execution result of the simulation scenario includes: The TCP server calculates the processing feedback time of each simulated client executing different commands; The TCP server determines whether the processing feedback time is less than a preset time threshold, If the judgment is yes, it means that the situation state is stable under the simulated random processing time scenario. When the judgment is no, it means that the scenario state under the simulated random processing time scenario is unstable, and the TCP server is controlled to process commands that exceed the preset time threshold, and heartbeat packets are periodically sent to the corresponding simulated client at a preset interval to query the command processing status until the command processing status received by the TCP server is the preset command processing end state or command feedback data is received.
7. The TCP server testing method according to claim 2, characterized in that: The simulation scenario includes simulating a third-party device attack scenario, and the step of optimizing the TCP server according to the execution result of the simulation scenario includes: The TCP server calculates the number of connections and the number of attacks of each simulated client within a preset time; The TCP server determines whether the number of connections or the number of attacks is less than or equal to a preset number, If the answer is yes, it means that the scenario status is stable under the simulated third-party device attack scenario. When the judgment is no, it indicates that the scenario state in the simulated third-party device attack scenario is unstable, and the TCP server is controlled to prohibit the communication connection of the corresponding simulated client.
8. A TCP server testing system, characterized in that: include: A construction module, used to construct a simulation client group based on different simulation scenarios, wherein the simulation client group includes at least one simulation client, and the simulation client includes multiple simulation threads, wherein the simulation threads correspond to the simulation scenarios one by one, and the simulation scenarios are used to simulate the communication problem between the display terminal and the TCP server in the actual environment; A communication module, used to establish communication between the simulated client group and the TCP server; A control module, used for driving the simulation threads to send data packets to the TCP server according to corresponding simulation scenarios to execute corresponding simulation scenarios; An optimization module is used to optimize the TCP server according to the execution result of the simulation scenario.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.