Message transceiving performance test method and system and storage medium
The locust tool simulates the TCP message interaction between the client and the server, solves the problem of high resource consumption in high concurrency tests, realizes efficient and economical message transmission and reception tests, and provides detailed test results analysis.
Patent Information
- Application Number
- CN202510524114.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-24
- Publication Date
- 2025-07-25
AI Technical Summary
Existing load testing tools are difficult to meet the high-concurrency testing requirements in high-concurrency scenarios, resulting in huge resource consumption, high cost and poor testing results.
The locus tool is used to simulate the TCP message interaction between the client and the server, and establish a long TCP connection with the server through the first locus and the second locus respectively to reduce the overhead of connection establishment time, and use performance tools to test the message sending and receiving process to calculate the message loss rate and average delay time.
Supports larger concurrency numbers under the same resource conditions, improves message transmission and reception efficiency, saves costs, and accurately counts test results to ensure reliable communication in high concurrency scenarios.
Smart Images

Figure CN120378327A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technologies, and in particular, to a method, a system, and a storage medium for performance testing of message sending and receiving. Background Art
[0002] With the wide use of instant messaging applications, a message sending and receiving system based on TCP (Transmission Control Protocol) has important advantages in terms of reliability and real-time performance. However, before the system goes online, it needs to be comprehensively load-tested to ensure its stability and performance in high-concurrency scenarios. Although existing load testing tools also test message sending and receiving that support TCP, the concurrency is relatively low and does not meet the high-concurrency test scenarios.
[0003] Jmeter is a mainstream performance testing tool on the market at present. It creates a thread pool (group) and creates a TCP sampler to establish a long TCP connection with the server, and simulates user behavior and processes return results in the beanshell component. When doing concurrency testing, the jmeter thread pool (group) is set to implement concurrent users. Every time Jmeter establishes a user login, a thread is established. The number of effective threads that can actually be established on a single machine is limited, and a thread roughly consumes 1M of memory. Moreover, as the number of threads increases, the consumption of the CPU for switching thread contexts also increases. After exceeding a certain threshold, continuing to increase the number of threads will instead cause the machine performance to decline, resulting in a decrease in the pressure released externally. Therefore, when using Jmeter to perform stress testing in high-concurrency scenarios, it consumes huge hardware resources, and generally small and medium-sized enterprises cannot afford such high testing costs. Summary of the Invention
[0004] The main purpose of this application is to provide a method, a system, and a storage medium for performance testing of message sending and receiving, aiming to solve the technical problem of how to ensure efficient message sending and receiving in high-concurrency test scenarios.
[0005] To achieve the above object, this application proposes a method for performance testing of message sending and receiving. The method is applied to locust, and the locust includes a first locust and a second locust. The first locust and the second locust are simultaneously connected to the server through the Transmission Control Protocol (TCP). The method includes:
[0006] Transmitting a message to the server through the TCP by the first locust, so that the server sends the message to the second locust;
[0007] Receive the message sent by the server through the second locust, and use a performance tool to perform a performance test on the message sending and receiving process to obtain a test result.
[0008] In an embodiment, before the step of the first locust transmitting the message to the server through the TCP so that the server transmits the message to the second locust through the TCP, the method further includes:
[0009] Send preset login request information to the server through the first locust and the second locust, and the server returns response information to the first locust and the second locust according to the preset login request information;
[0010] Based on the response information, determine whether the TCP connections between the first locust and the second locust and the server are successfully established.
[0011] In an embodiment, the step of determining whether the TCP connections between the first locust and the second locust and the server are successfully established based on the response information includes:
[0012] If the response information returned by the server is detected within a preset time, it is determined that the TCP connections between the first locust and the second locust and the server are successfully established;
[0013] If the response information returned by the server is not detected within the preset time, it is determined that the TCP connections between the first locust and the second locust and the server are not successfully established.
[0014] In an embodiment, the step of the second locust receiving the message sent by the server and using a performance tool to perform a performance test on the message sending and receiving process to obtain a test result includes:
[0015] Receive the message sent by the server through the second locust, where the message includes a service message and a heartbeat message;
[0016] Filter the heartbeat information and retain the service message;
[0017] Calculate the message loss rate and the average message delay time of the service message, and obtain the test result based on the message loss rate and the average message delay time.
[0018] In an embodiment, the step of calculating the message loss rate and the average message delay time of the service message includes:
[0019] Calculate the total number of service messages sent by the first locust and the total number of service messages received by the second locust;
[0020] By calculating the total number of service messages sent by the first locust and the total number of service messages received by the second locust, obtain the message loss rate.
[0021] In one embodiment, the steps of calculating the message loss rate and the average message delay time of the service messages further include:
[0022] The second locust generates a message reception time according to the service message;
[0023] According to the message reception time, calculate the average message delay time of the service message.
[0024] To achieve the above object, the present application also proposes a performance test method for message sending and receiving. The method is applied to a server. The server is connected to locust through TCP. The locust includes at least a first locust and a second locust. The method includes:
[0025] Receive the message transmitted by the first locust through the TCP;
[0026] Send the message to the second locust through the TCP. The second locust receives the message sent by the server and performs a performance test on the message sending and receiving process to obtain a test result.
[0027] In one embodiment, before the step of receiving the message transmitted by the first locust through the TCP, it further includes:
[0028] Receive the preset login request information sent by the client and return a response message to the client according to the preset login request information, so that the client determines whether the TCP connections between the first locust and the second locust and the server are successfully established based on the response message.
[0029] In addition, to achieve the above object, the present application also proposes a performance test system for message sending and receiving. The performance test system for message sending and receiving includes locust and a server. The locust includes at least a first locust and a second locust;
[0030] The locust further includes:
[0031] The first sending module is used to transmit a message to the server through the TCP by the first locust, so that the server sends the message to the second locust through the TCP;
[0032] The testing module is used to receive the message sent by the server through the second locust and perform a performance test on the message sending and receiving process to obtain a test result;
[0033] The server includes:
[0034] The receiving module is used to receive the message transmitted by the first locust through the TCP;
[0035] The second sending module is used to send the message to the second locust through the TCP. The second locust receives the message sent by the server and performs a performance test on the message sending and receiving process to obtain a test result.
[0036] In addition, to achieve the above object, the present application also proposes a performance testing device for message sending and receiving. The device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor. The computer program is configured to implement the steps of the performance testing method for message sending and receiving as described above.
[0037] In addition, to achieve the above object, the present application also proposes a storage medium. The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the performance testing method for message sending and receiving as described above.
[0038] In addition, to achieve the above object, the present application also provides a computer program product. The computer program product includes a computer program. When the computer program is executed by a processor, it implements the steps of the group exercise push method as described above.
[0039] An embodiment of the present application provides a performance testing method, system, device, storage medium, and program product for message sending and receiving. This method is applied to Locust, which at least includes a first Locust and a second Locust. Among them, the first Locust and the second Locust are simultaneously connected to the server through TCP. The method includes: transmitting a message to the server through the first Locust via TCP, so that the server sends the message to the second Locust via TCP. After receiving the message sent by the server, the second Locust performs a performance test on the message sending and receiving process to obtain a test result. This solution uses the Locust tool to simulate the TCP message interaction between the client and the server, thereby realizing the high-concurrency performance test of the message sending and receiving process and improving the message sending and receiving efficiency. At the same time, this solution uses the high-concurrency feature of Locust to support a larger number of concurrent connections under the same resource conditions, realizing an efficient message sending and receiving test. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0041] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0042] Figure 1 It is a schematic flowchart provided for Embodiment 1 of the performance testing method for message sending and receiving of the present application;
[0043] Figure 2 It is a schematic flowchart provided for Embodiment 2 of the performance testing method for message sending and receiving of the present application;
[0044] Figure 3 It is a schematic flowchart provided for Embodiment 3 of the performance testing method for message sending and receiving of the present application;
[0045] Figure 4 It is a topology diagram for message sending and receiving using Locust provided for Embodiment 1 of the present application;
[0046] Figure 5 It is a schematic brief flowchart of the performance testing method for message sending and receiving provided for Embodiment 1 of the present application;
[0047] Figure 6 It is a schematic module structure diagram of the performance testing system for message sending and receiving of the embodiments of the present application;
[0048] Figure 7 This is a schematic diagram of the device structure of the hardware operating environment involved in the performance testing method for message sending and receiving in the embodiments of this application.
[0049] The implementation, functional characteristics, and advantages of this application will be further described in conjunction with embodiments and with reference to the accompanying drawings. Specific embodiments
[0050] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of this application and are not used to limit this application.
[0051] To better understand the technical solutions of this application, the following will be described in detail in conjunction with the accompanying drawings of the specification and specific embodiments.
[0052] The main solution of the embodiments of this application is: The first locust and the second locust respectively establish long connections with the server through TCP. The first locust transmits messages to the server through TCP, so that the server sends the messages to the second locust through TCP. After the second locust receives the messages sent by the server, it performs performance testing on the message sending and receiving process to obtain test results.
[0053] With the popularization of instant messaging applications, performance testing systems for message sending and receiving based on TCP have significant advantages in terms of reliability and real-time performance. However, before going online, comprehensive load testing must be carried out to ensure stability and performance in high-concurrency scenarios. Existing tools such as JMeter support TCP message sending and receiving testing, but their concurrency capabilities are limited and it is difficult to meet high-concurrency requirements.
[0054] This application provides a solution. This solution respectively establishes long connections with the server through the first locust and the second locust using the TCP protocol, reducing the time overhead of re-establishing connections during each communication and improving communication efficiency. And after the second locust receives the messages forwarded by the server, it uses a specified performance testing tool such as locus to test the messages. Relying on the characteristics of locust being lightweight in resources and high in concurrency, a single test machine can generate tens of thousands of concurrent pressures. Compared with jmeter, it can release a greater number of concurrencies when testing message sending and receiving under the same resources, and can also accurately count the number of lost messages, the loss rate, and the average delay of messages.
[0055] Technical terms involved in this embodiment:
[0056] locust: A performance testing tool developed in Python and event-based, with characteristics: lightweight in resources and high in concurrency.
[0057] jmeter: A performance testing tool written in Java.
[0058] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication, and program running functions, such as a tablet computer, a personal computer, etc., or an electronic device capable of implementing the above functions. Hereinafter, a personal computer will be taken as an example to illustrate this embodiment and the following embodiments.
[0059] Based on this, the embodiments of the present application provide a performance test method for message sending and receiving. Refer to Figure 1 , Figure 1 which is a schematic flowchart of the first embodiment of the performance test method for message sending and receiving of the present application.
[0060] In this embodiment, the performance test method for message sending and receiving includes steps S10 to S20:
[0061] Step S10: Transmit the message to the server through the TCP by the first locust, so that the server sends the message to the second locust through the TCP;
[0062] It should be noted that TCP (Transmission Control Protocol) is one of the core protocols in the Internet protocol suite, mainly used to provide reliable, connection-oriented data transmission services in an unreliable network environment.
[0063] In order to ensure that messages can be reliably and efficiently transmitted between the client and the server, and performance testing can be carried out in a high-concurrency scenario, this embodiment uses locust to simulate the TCP message interaction between the client and the server. Among them, in this embodiment, the first locust simulates client A, and the second locust simulates client B.
[0064] Specifically, first, write 2 client scripts. The function of the scripts is to define user behaviors, simulate the connection of the TCP client, and simulate the sending and receiving of messages by users. Among them, define the first locust to simulate client A sending messages, and define the second locust to simulate client B receiving messages. First, the first locust and the second locust establish a TPC long connection with the message service simultaneously through the create_connect() method. When the first locust sends a message to the second locust, the message is first processed and forwarded by the message service (i.e., the server), and then forwarded to the second locust. At the same time, the first locust records the total number of messages sent and the time of message sending.
[0065] In summary, the process of transmitting messages from the first locust to the server via TCP and then having the server forward them to the second locust not only enables efficient and reliable message delivery but also provides an infrastructure for performance testing in high-concurrency scenarios.
[0066] Step S20: Receive the messages sent by the server through the second locust, and use a performance tool to perform performance testing on the message sending and receiving process to obtain test results.
[0067] It should be noted that the test results include, but are not limited to, the number of lost messages, the message loss rate, the average message delay time, etc. Among them, the number of lost messages refers to the total number of messages that failed to be successfully transmitted from the sender to the receiver during the test; the message loss rate refers to the ratio of the number of lost messages to the total number of sent messages; the average message delay time refers to the average value of the time required for all successfully transmitted messages to be received from the time of sending.
[0068] In a feasible embodiment, step S20 further includes steps S21 to S23:
[0069] Step S21: Receive the messages sent by the server through the second locust, where the messages include service messages and heartbeat messages.
[0070] Specifically, while the second locust is waiting for messages, it keeps waiting to receive messages sent by the first locust through a loop (while = True). If a new message is detected, it calls sk.recv() to receive it. If no message is received, it keeps waiting. Among the messages received by the second locust are service messages sent by the first locust and heartbeat messages used by the server to maintain the TCP long connection.
[0071] Step S22: Filter the heartbeat information according to the message type and retain the service messages.
[0072] Since heartbeat messages are mainly used to maintain the validity and activity of the connection during network communication and do not carry actual business data, the second locust needs to effectively identify and filter out these heartbeat messages and only perform further testing on service messages.
[0073] Specifically, when writing the client script, a clear identifier will be defined for each message to distinguish its type. For example, a field (such as msg_type) can be used to represent the message type, where 0 represents a heartbeat message and 1 represents a service message.
[0074] When the second locust receives a message, it first parses the msg_type field in the message. According to the predefined rules (i.e., msg_type = 0 is a heartbeat message and msg_type = 1 is a business message), it decides whether to further process the message. If it is a heartbeat message (msg_type = 0), it is directly ignored or discarded after recording statistical information; if it is a business message (msg_type = 1), it enters the next processing flow.
[0075] Step S23, calculate the message loss rate and the average message delay time of the business message, and based on the message loss rate and the average message delay time, obtain the test result.
[0076] Specifically, when the second locust receives the business message sent by the first locust, it counts the received business messages, that is, it counts one business message each time it receives a business message until the end of receiving business messages, and obtains the total number of finally received business messages. Then, these business messages are stored in the account variable. On the one hand, it is used to display to the user, and on the other hand, it is used to calculate the message loss rate and the average message delay time.
[0077] To ensure the reliability of an instant messaging system or other performance testing systems for TCP-based message sending and receiving, calculating the message loss rate and the average message delay time are both one of the key performance indicators.
[0078] For the calculation of the message loss rate, first, client A records each successfully sent business message and synchronizes the number of successfully sent business messages to the first locust. Similarly, client B records each successfully received business message and synchronizes the number of successfully received business messages to the second locust. Among them, the locust's event system is used to capture data updates from the client. Then, the first locust calculates the total number of message sends, and the second locust calculates the total number of message receives, and the total number of message losses is obtained by subtracting the total number of message receives from the total number of message sends. Subsequently, the message loss rate is calculated through the total number of message sends and the total number of message receives. The calculation formula is: message loss rate = total number of message losses / total number of message sends * 100%.
[0079] For the calculation of the average message delay time, first add a field start_time representing the message sending time when defining the message format in the client script. When the second locust receives the business message sent by the first locust, record the current business message reception time rec_time. Then the locust obtains start_time and rec_time respectively. Next, define the total message delay time as total_time in the locust, and total_time = rec_time - start_time. Finally, the locust calls the internal method events.request_success.fire(request_type = "tcpsocket", name = "Receive Message", response_time = total_time, response_length = 0), and passes the calculated total_time as the response time to the event trigger of the locust. The average business message delay time when there are more than 1 message is calculated through the event trigger of the locust. Among them, the calculation formula for the average message delay time is average message delay time = total message time / total number of messages.
[0080] Also, while the locust calls the internal method events.request_success.fire(request_type = "tcpsocket", name = "Receive Message", response_time = total_time, response_length = 0) to calculate the message loss rate and the average message delay time, these results are also passed to the internal display module for display.
[0081] In addition, place the two written client scripts in any directories under two different locust root directories respectively. Then, in the locust directory, run the command "locust -f client script.py --master --headless -u 20000 -r 10 -t 2h" in a distributed manner to start two sets of locust for stress testing. Wait until the stress testing is over and check the test results in the locust background. Performing performance testing by running Locust in a distributed manner ensures the load capacity in high-concurrency scenarios and provides detailed test result analysis.
[0082] In summary, by filtering out the heartbeat messages and ensuring that only business messages are subjected to performance testing, the accuracy and relevance of the test results are improved. Calculating the message loss rate and the average message delay time helps identify potential problems in the system and ensures reliable communication in high-concurrency scenarios.
[0083] Through the method of the above embodiments, the first locust transmits a message to the server through the TCP, so that the server sends the message to the second locust through the TCP; the second locust receives the message sent by the server, and uses a performance tool to perform a performance test on the message sending and receiving process to obtain a test result. This method uses locust to simulate a client to establish a connection with the server through TCP to implement message sending and receiving tests based on TCP, improving the message sending and receiving efficiency. And using a specified performance tool to perform a performance test on the message can not only support large-scale concurrent tests to simulate high-load situations in the real world, saving the message sending and receiving cost, but also accurately analyze and statistically obtain the test result of the message.
[0084] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar content as in the above-mentioned embodiment one can be referred to the above introduction and will not be repeated hereinafter. On this basis, please refer to Figure 2 , before step S10, the performance test method for message sending and receiving further includes steps S01 to S02:
[0085] Step S01, the first locust and the second locust send preset login request information to the server, and the server returns response information to the first locust and the second locust according to the preset login request information;
[0086] Step S02, based on the response information, determine whether the TCP connections between the first locust and the second locust and the server are successfully established.
[0087] Specifically, first, at the beginning of the test, the first locust (simulating client A) and the second locust (simulating client B) send preset login request information to the server by calling the custom-created method login_send(). It should be noted that before sending the login request, the login_send() method binds specific user information according to the configuration or user input to ensure that each locust has a unique identity during the connection process.
[0088] Then, after the client sends the login request, it enters a waiting state and is ready to receive the response information from the server. Among them, the response information includes the processing result of the login request and possible status codes or other metadata.
[0089] After the server receives the preset login request information sent by the client, it generates corresponding response information based on the request and returns it to the client.
[0090] If the client receives the response message returned by the server within the specified time, and the message indicates that the login request has been successfully processed (for example, contains a status code confirming successful login), it can be considered that the TCP long connection has been successfully established. At this time, the client can further initialize the interaction logic with the server according to other information in the response (such as session token, user permissions, etc.). If the client still does not receive any response message from the server after continuously waiting for 3 minutes, it is considered that the TCP long connection has not been successfully established.
[0091] Through the method of the above embodiments, it is ensured that locust only considers the TCP long connection to be successfully established after receiving a valid server response, avoiding misjudgment caused by network latency or temporary failures.
[0092] Based on the first embodiment of the present application, in the third embodiment of the present application, the same or similar content as in the above-mentioned first embodiment can be referred to the above introduction and will not be elaborated hereinafter. On this basis, please refer to Figure 3 , in this embodiment, the performance test method for message sending and receiving includes steps S30 to S40:
[0093] Step S30, receiving the message transmitted by the first locust through the TCP;
[0094] This embodiment is applied to the service. In this embodiment, the server is responsible for processing and forwarding messages. It establishes connections with the first locust and the second locust respectively through the TCP protocol to ensure that messages can be reliably transmitted between the two. When the first locust sends a message, the server receives these messages and performs necessary parsing to determine the content and type of the message (such as business message or heartbeat message).
[0095] Step S40, sending the message to the second locust through the TCP, and the second locust receives the message sent by the server and performs a performance test on the message sending and receiving process to obtain a test result.
[0096] Specifically, the server forwards the message received from the first locust to the second locust through the TCP protocol. So that the second locust receives the message sent by the first locust and performs a performance test on the message receiving process, including but not limited to calculating the number of lost messages, the message loss rate, and the average delay time of the message disappearance, etc.
[0097] In addition, it should be noted that during the process of the server forwarding the message received from the first locust to the second locust through the TCP protocol, the server is also responsible for maintaining the TCP long connections with the two clients to ensure that the connections will not be interrupted due to long-term lack of data exchange.
[0098] Through the method of the above embodiments, the first locust transmits a message to the server through TCP, so that the server sends the message to the second locust through TCP; the second locust receives the message sent by the server and performs a performance test on the message sending and receiving process to obtain a test result. This method uses the locust tool to simulate the TCP message interaction between the client and the server, thereby realizing the high-concurrency performance test of the message sending and receiving process and improving the message sending and receiving efficiency. And by using the high-concurrency feature of locust, it can support a larger number of concurrencies under the same resource conditions, realizing an efficient message sending and receiving test.
[0099] Exemplarily, to help understand the implementation process of the performance test method for message sending and receiving obtained by combining the above embodiments with the first embodiment, please refer to Figure 4 , Figure 4 A topology diagram for using locust to send and receive messages in a performance test method for message sending and receiving is provided. Specifically:
[0100] When using traditional performance testing tools (such as Jmeter) to perform stress testing in high-concurrency scenarios, it consumes huge hardware resources and has a high construction cost. Therefore, in view of the deficiencies of the current Jmeter in testing the function of TCP protocol message sending and receiving in high-concurrency scenarios, this embodiment provides a solution for using locust to achieve high-concurrency testing of TCP protocol message sending and receiving.
[0101] Specifically, locust1 and locust2 respectively represent the first locust and the second locust. Locust1 and locust2 respectively establish TCP long connections with the message service (server) first. After that, when locust1 sends a message to locust2, locust1 needs to go through the message service and then forward it to locust2. At the same time, locust1 records the total number of messages sent and the message sending time. After receiving the message, locust2 also needs to go through the message service and then reply to locust1. At the same time, locust2 counts the number of received messages and the message receiving time.
[0102] Finally, at the end of the test, locust1 and locust2 automatically calculate the total number of lost messages, the message loss rate, and the message delay.
[0103] In summary, the system for message sending and receiving based on the TCP protocol in this embodiment has good reusability and high receiving efficiency. And by virtue of the characteristics of locust with light resources and high concurrency, a single test machine can generate tens of thousands of concurrent pressures. Compared with Jmeter, it can release a larger number of concurrencies when testing message sending and receiving under the same resources.
[0104] Exemplarily, to help understand the implementation process of the message sending and receiving performance testing method obtained by combining this embodiment with the above-mentioned Embodiment 1, please refer to FIG. 5. Figure 5 A brief flow schematic diagram of a message sending and receiving performance testing method is provided. Specifically:
[0105] This embodiment includes two major parts. One is to write a client script, and the other is to upgrade and transform locust so that it can implement message sending and receiving tests based on TCP. Then, the client script + the transformed locust are used to implement high-concurrency testing of messages.
[0106] Specifically, first, two client scripts (Client A and Client B) are written to define the user behaviors of locust. These two scripts respectively simulate the connection and message sending and receiving operations of a TCP client: among them, the first locust instance is responsible for sending messages, and the second locust instance is responsible for receiving messages. In this way, the simulation of the user's message sending and receiving behaviors is realized.
[0107] When the first locust and the second locust establish TCP connections with the server simultaneously, it can be judged whether the TCP long connection is successfully established by whether the server returns a response message. Specifically, if the client receives a response message from the server, it means that the TCP long connection has been successfully established. On the contrary, if the client does not receive any response message from the server after continuously waiting for 3 minutes, it is considered that the TCP connection establishment fails. This expression is more fluent and clear.
[0108] On the basis of detecting that the TCP long connection is successfully established, if the first locust sends a message to the second locust, the first locust will call the sentmsg() method to send the message. During this period, the second locust loops (while=True) and keeps waiting to receive the message sent by the first locust. If a new message is detected, it will call sk.recv() to receive it. If no information is received, it will keep waiting.
[0109] Furthermore, transform locust so that it can receive the message data sent by Client A and the message data received by Client B, perform statistics, calculate the test data, and display it. The specific implementation solution is as follows:
[0110] When the message received by Client B includes the service message and heartbeat message sent by Client A, first filter out the heartbeat type messages and only retain the service information. Pass the filtered service messages to the second locust (simulating Client B). The second locust performs statistics on these service information to obtain the final number of received messages and stores it in the account variable.
[0111] Meanwhile, Client A synchronizes the total number of messages it sends to the first locust (simulating Client A), while Client B synchronizes the total number of messages it receives to the second locust. The message loss rate is calculated by the first locust and the second locust, and the calculation formula is as follows:
[0112] Message loss rate = (Total number of messages sent - Total number of messages received) / Total number of messages sent * 100%
[0113] Through this calculation, the loss situation during the message transmission process can be quantified to evaluate the reliability of the system.
[0114] Meanwhile, when defining the message format in the client script, add a field start_time for the message sending time. When Client B receives the message sent by Client A, record the current receiving time rec_time. Then, the first locust and the second locust respectively obtain start_time and rec_time, and calculate the delay time of each message:
[0115] total_time = rec_time – start_time
[0116] Among them, total_time represents the delay time of each message, rec_time represents the current receiving time, and start_time represents the field of the message sending time. Then, in locust, call the internal method events.request_success.fire to calculate the average delay time when there are more than 1 message. The formula is as follows: Average message delay time = Total message time / Total number of messages.
[0117] Subsequently, when calculating the test results by calling the internal method events.request_success.fire(request_type = "tcpsocket", name = "Receive message", response_time = total_time, response_length = 0) through locust, the results will also be passed to the internal display module for display.
[0118] Finally, place the two written scripts in any directories under two different Locust root directories respectively. Then, go to the locust directory and run the command "locust -f client_script.py --master --headless -u 20000 -r 10 -t 2h" in a distributed manner to start the first Locust and the second Locust for stress testing. Wait for the stress testing to end and view the test results in the Locust background. Among them, -u 20000 means simulating 20000 users, -r 10 means starting 10 users per second, and -t 2h means the test duration is 2 hours.
[0119] Through the method of the above embodiments, the first Locust and the second Locust simulate clients to establish TCP long connections with the server respectively. This method reduces the time overhead of re - establishing connections during each communication, thus significantly improving the communication efficiency. At the same time, taking advantage of the light resource consumption and high - concurrency processing of Locust, a single test machine can generate tens of thousands of concurrent pressures. Compared with traditional methods, under the same resource conditions, Locust can release a larger concurrency volume, and can accurately count the number of lost messages, calculate the loss rate, and evaluate the average delay time of messages. This ability not only improves the accuracy and efficiency of testing, but also provides more refined data support for system performance analysis.
[0120] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the performance testing method for message sending and receiving of this application. Based on this technical concept, more forms of simple transformations are within the protection scope of this application.
[0121] This application also provides a performance testing system for message sending and receiving. Please refer to Figure 6 The performance testing system for message sending and receiving includes Locust and a server. The Locust includes at least a first Locust and a second Locust;
[0122] The Locust further includes:
[0123] A first sending module 10, configured to transmit a message to the server through the TCP by the first Locust, so that the server sends the message to the second Locust through the TCP;
[0124] A testing module 20, configured to receive the message sent by the server through the second Locust and perform performance testing on the message sending and receiving process to obtain a test result;
[0125] The server includes:
[0126] A receiving module 30, configured to receive the message transmitted by the first locust through TCP;
[0127] A second sending module 40, configured to send the message to the second locust through the TCP, so that the second locust receives the message sent by the server, and perform a performance test on the message sending and receiving process to obtain a test result.
[0128] The performance test system for message sending and receiving provided by the present application adopts the performance test method for message sending and receiving in the above embodiment, and can solve the technical problem of how to ensure efficient, stable and cost-saving message sending and receiving in a high-concurrency test scenario. Compared with the prior art, the beneficial effects of the performance test system for message sending and receiving provided by the present application are the same as those of the performance test method for message sending and receiving provided by the above embodiment, and other technical features in the performance test system for message sending and receiving are the same as the features disclosed in the method of the above embodiment, which will not be elaborated here.
[0129] The present application provides a performance test device for message sending and receiving. The performance test device for message sending and receiving includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the performance test method for message sending and receiving in the first embodiment above.
[0130] Next, refer to Figure 7 , which shows a schematic structural diagram of a performance test device for message sending and receiving suitable for implementing the embodiments of the present application. The performance test device for message sending and receiving in the embodiments of the present application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The performance test device for message sending and receiving shown is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present application.
[0131] As Figure 7As shown, the message sending and receiving performance testing device may include a processing system 1001 (such as a central processing unit, a graphics processing unit, etc.), which may perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage system 1003 into a random access memory (RAM: Random Access Memory) 1004. In the RAM 1004, various programs and data required for the operation of the message sending and receiving performance testing device are also stored. The processing system 1001, the ROM 1002, and the RAM 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems may be connected to the I / O interface 1006: an input system 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output system 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage system 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication system 1009. The communication system 1009 may allow the message sending and receiving performance testing device to communicate with other devices wirelessly or wiredly to exchange data. Although the figure shows a message sending and receiving performance testing device having various systems, it should be understood that it is not required to implement or have all the shown systems. More or fewer systems may be implemented or had alternatively.
[0132] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network through the communication system, or installed from the storage system 1003, or installed from the ROM 1002. When the computer program is executed by the processing system 1001, the above-mentioned functions defined in the methods of the embodiments disclosed in the present application are executed.
[0133] The message sending and receiving performance testing device provided by the present application adopts the message sending and receiving performance testing method in the above-mentioned embodiment, and can solve the technical problem of how to ensure efficient, stable and cost-saving message sending and receiving in a high-concurrency test scenario. Compared with the prior art, the beneficial effects of the message sending and receiving performance testing device provided by the present application are the same as those of the message sending and receiving performance testing method provided by the above-mentioned embodiment, and other technical features in the message sending and receiving performance testing device are the same as those disclosed in the method of the previous embodiment, and will not be elaborated here.
[0134] It should be understood that each part disclosed in this application can be implemented by hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in a suitable manner in any one or more embodiments or examples.
[0135] As described above, the above are only specific embodiments of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in this application, and all should be covered by the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.
[0136] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., computer programs) stored thereon, and the computer-readable program instructions are used to execute the message sending and receiving performance testing method in the above embodiments.
[0137] The computer-readable storage medium provided by this application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM) or flash memory, optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this embodiment, the computer-readable storage medium can be any tangible medium that contains or stores a program, and the program can be used by or combined with an instruction execution system, device, or device. The program code contained on the computer-readable storage medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0138] The above computer-readable storage medium can be included in the message sending and receiving performance testing device; it can also exist separately without being assembled into the message sending and receiving performance testing device.
[0139] The above computer-readable storage medium carries one or more programs, which, when executed by a message transceiver performance testing device, cause the message transceiver performance testing device to: transmit messages to a server through TCP by a first locust, so that the server sends the messages to a second locust through TCP, and after receiving the messages sent by the server, the second locust performs performance testing on the message transceiver process to obtain a test result.
[0140] Computer program code for performing the operations of this application can be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, and C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, by using an Internet service provider to connect through the Internet).
[0141] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and this module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0142] The modules described in the embodiments of this application can be implemented in software or in hardware. Among them, the name of the module does not constitute a limitation on the unit itself in some cases.
[0143] The readable storage medium provided by this application is a computer-readable storage medium. The computer-readable storage medium stores computer-readable program instructions (i.e., computer programs) for executing the performance testing method for message sending and receiving as described above, and can solve the technical problems of message sending and receiving. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by this application are the same as those of the performance testing method for message sending and receiving provided by the above embodiments, and will not be elaborated here.
[0144] This application also provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the steps of the performance testing method for message sending and receiving as described above.
[0145] The computer program product provided by this application can solve the technical problem of how to ensure efficient, stable and cost-saving message sending and receiving in a high-concurrency test scenario. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as those of the performance testing method for message sending and receiving provided by the above embodiments, and will not be elaborated here.
[0146] The above are only some embodiments of this application, and do not limit the patent scope of this application. Any equivalent structural transformation made by using the content of the specification and drawings of this application under the technical concept of this application, or direct / indirect application in other related technical fields, is included in the patent protection scope of this application.
Claims
1. A performance testing method for message sending and receiving, characterized in that, The method is applied to the performance testing tool locust, where locust at least includes a first locust and a second locust. The first locust and the second locust are simultaneously connected to the server through the Transmission Control Protocol (TCP). The method includes: The first locust transmits a message to the server through the TCP, so that the server sends the message to the second locust through the TCP; The second locust receives the message sent by the server and performs a performance test on the message sending and receiving process to obtain a test result.
2. The method according to claim 1, wherein Before the step of the first locust transmitting a message to the server through the TCP, so that the server sends the message to the second locust through the TCP, it further includes: The first locust and the second locust send preset login request information to the server, and the server returns response information to the first locust and the second locust according to the preset login request information; Based on the response information, determine whether the TCP connections between the first locust and the second locust and the server are successfully established.
3. The method according to claim 2, wherein The step of determining whether the TCP connections between the first locust and the second locust and the server are successfully established based on the response information includes: If the response information returned by the server is detected within a preset time, it is determined that the TCP connections between the first locust and the second locust and the server are successfully established; If the response information returned by the server is not detected within the preset time, it is determined that the TCP connections between the first locust and the second locust and the server are failed to be established.
4. The method according to claim 1, wherein The step of the second locust receiving the message sent by the server and performing a performance test on the message sending and receiving process to obtain a test result includes: The second locust receives the message sent by the server, where the message includes a service message and a heartbeat message; Filter the heartbeat information and retain the service message; Calculate the message loss rate and the average message delay time of the service message, and based on the message loss rate and the average message delay time, obtain the test result.
5. The method according to claim 4, characterized in that The step of calculating the message loss rate and the average message delay time of the service message includes: Calculate the total number of service messages sent by the first locust and the total number of service messages received by the second locust; Obtain the message loss rate by calculating the total number of service messages sent by the first locust and the total number of service messages received by the second locust.
6. The method according to claim 4, wherein The step of calculating the message loss rate and the average message delay time of the service message further includes: The second locust generates a message reception time according to the service message; Calculate the average message delay time of the service message according to the message reception time.
7. A performance testing method for message sending and receiving, characterized in that, The method is applied to a server, the server is connected to locust through TCP, the locust includes a first locust and a second locust, and the method includes: Receive the message transmitted by the first locust through the TCP. Send the message to the second locust through the TCP, and the second locust receives the message sent by the server and performs a performance test on the message sending and receiving process to obtain a test result.
8. The method according to claim 7, wherein Before the step of receiving the message transmitted by the first locust through the TCP, it further includes: Receive the preset login request information sent by the client, and return a response message to the client according to the preset login request information, so that the client determines whether the TCP connections between the first locust and the second locust and the server are successfully established based on the response message.
9. A performance testing system for message sending and receiving, characterized in that, The system includes a locust and a server, and the locust includes at least a first locust and a second locust; The locust further includes: A first sending module, configured to transmit a message to the server through the first locust through the TCP, so that the server sends the message to the second locust through the TCP; A test module, configured to receive the message sent by the server through the second locust, and perform a performance test on the message sending and receiving process by using a performance tool to obtain a test result; The server includes: A receiving module, configured to receive the message transmitted by the first locust through TCP; A second sending module, configured to send the message to the second locust through the TCP, and the second locust receives the message sent by the server and performs a performance test on the message sending and receiving process to obtain the test result.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the performance test method for message sending and receiving according to any one of claims 1 to 8 are implemented.