A traffic automatic playback method for software testing
By using multi-threshold segmentation and differentiated compression ratios, the problems of high packet loss rate and low similarity in existing traffic replay are solved, achieving higher precision software testing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGYIN CONSUMER FINANCE CO LTD
- Filing Date
- 2023-01-03
- Publication Date
- 2026-05-29
AI Technical Summary
Existing traffic replay methods suffer from high packet loss rates due to proportional compression of time intervals, and the compressed traffic data has poor similarity to the original data, affecting test accuracy.
A multi-threshold segmentation method is used to divide the time interval sequence into consistent and inconsistent regions, and different compression ratios are applied to each region. The correction coefficient is calculated using run length and data packet value to optimize the compression ratio, reduce packet loss rate, and improve similarity.
While reducing packet loss rate, it improves the similarity between compressed traffic data and original data, thereby enhancing the simulation accuracy of software testing.
Smart Images

Figure CN115729841B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer data processing, and more specifically to an automatic traffic replay method for software testing. Background Technology
[0002] For performance testing in busy network environments, traffic acceleration replay can be used to cope with surges in network traffic during peak hours. Therefore, traffic acceleration replay has high research value and broad application prospects. Existing traffic replay tools primarily accelerate replay by controlling time, which proportionally compresses the time intervals between data packets. This method leads to even higher packet density in areas where it was already high, resulting in packet loss during replay. One paper that shows the most significant improvement to this method is "A Traffic Replay Acceleration Method Based on Event Compression," which prioritizes compressing longer time intervals to achieve overall time compression. This method reduces packet loss and time interval errors during acceleration. However, it results in poor similarity between the compressed overall traffic data and the original traffic data, affecting the simulation of the actual request process, reducing simulation accuracy, and leading to significant errors in test results. Therefore, a traffic acceleration replay method is needed that can guarantee a low packet loss rate while maintaining high similarity to the original traffic data, i.e., high simulation accuracy. Summary of the Invention
[0003] This invention provides an automatic traffic replay method for software testing to solve the problems of packet loss and significant differences in traffic data before and after compression caused by proportional compression of data packet time intervals in existing methods. The specific technical solution adopted is as follows:
[0004] One embodiment of the present invention provides an automatic traffic replay method for software testing, the method comprising the following steps:
[0005] Obtain software traffic data;
[0006] The process involves acquiring data packets and time intervals from traffic data. The interval values of these time intervals form a time interval sequence. The interval values in the time interval sequence are divided into several first categories through multi-threshold segmentation. Each first category contains several interval values. The frequency of the first occurrence of each interval value in the time interval sequence is counted. The interval frequency sequence is obtained by sorting the interval frequency sequences in ascending order. The interval frequency sequence is then segmented by thresholds to obtain a first segmentation threshold. The first occurrence frequency corresponding to the first segmentation threshold is used as a second segmentation threshold. The first category, in which the number of elements in the first category is greater than the second segmentation threshold, is designated as the second category.
[0007] The mean of all interval values in each second category is used as the second representative value of each second category. The second frequency of the second representative value is counted and sorted in ascending order to obtain the representative frequency sequence. The representative frequency sequence is thresholded to obtain the third segmentation threshold. The second category with a second representative value greater than the third segmentation threshold is used as the third category. All interval values in the time interval sequence other than the third category are classified as the fourth category.
[0008] The first compression ratio of each interval is obtained based on the third frequency of occurrence and the interval value of each interval in the fourth category. The difference between the second representative value of each third category and the interval value of each interval in the fourth category is obtained. The first compression ratio of the interval with the smallest difference in the fourth category is taken as the second compression ratio of each interval in the corresponding third category.
[0009] The number of elements in the first category to which each interval belongs in the fourth category is used as the run length of each interval. The block value of each data packet in the traffic data is obtained. The correction coefficient of each interval is obtained based on the run length of each interval in the fourth category and the block values of the left and right data packets. The third compression ratio of each interval is obtained based on the correction coefficient of each interval and the first compression ratio.
[0010] The traffic data is compressed and automatically replayed based on the second compression rate for each interval in the third category and the third compression rate for each interval in the fourth category.
[0011] Optionally, the specific method for obtaining data packets and time intervals from the traffic data includes:
[0012] Software traffic data contains several data packets, each data packet being a block, and the interval between each block represents the time interval between the transmission of adjacent data packets.
[0013] Optionally, the specific method for constructing the time interval sequence includes:
[0014] The duration of each time interval is used as the interval value, and each time interval is arranged in the time order of the traffic data to obtain the time interval sequence.
[0015] Optionally, the specific method for obtaining the first compression ratio for each interval is as follows:
[0016]
[0017] in, Indicates the fourth category The first compression rate of each interval, Indicates the first The third frequency of occurrence of the interval value of each interval. Indicates the first Interval values for each interval, This represents an exponential function with the natural constant as its base.
[0018] Optionally, the specific method for obtaining the block value of each data packet in the traffic data includes:
[0019] The time length corresponding to each data packet is used as the data packet value of each data packet, and the ratio of the data packet value to the largest data packet value in the traffic data is used as the block value of the corresponding data packet.
[0020] Optionally, the specific method for obtaining the correction coefficient for each interval is as follows:
[0021]
[0022] in, Indicates the fourth category Correction factor for each interval, Indicates the first The block value of the data packet to the left of the interval. Indicates the first The block value of the data packet to the right of the interval. Indicates the first Each interval of the journey, This indicates the maximum run in the fourth category. Indicates the first The difference between the left and right packet block values at each interval. This represents the largest difference between the left and right data packet block values in the fourth category.
[0023] The beneficial effects of this invention are as follows: By using a multi-threshold segmentation method to obtain regions with low density and consistent distribution, and applying proportional compression to these regions, it helps ensure a high degree of similarity between the compressed and uncompressed regions. Simultaneously, using a first compression rate with the same interval value for non-consistent regions helps ensure consistency between consistent and non-consistent regions, thereby improving overall similarity. Calculating the first compression rate for each interval of non-consistent regions using frequency and interval helps avoid packet loss. Calculating correction coefficients using run-length and adjacent data packets ensures high similarity to the uncompressed data while avoiding packet loss, allowing for better simulation of the original request data and thus improving the reliability of software testing results. Attached Figure Description
[0024] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1 A flowchart illustrating an automatic traffic replay method for software testing, provided as an embodiment of the present invention;
[0026] Figure 2 Example graph of traffic data. Detailed Implementation
[0027] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0028] Please see Figure 1 The diagram illustrates a flowchart of an automatic traffic replay method for software testing provided by an embodiment of the present invention. The method includes the following steps:
[0029] Step S001: Obtain software traffic data;
[0030] The purpose of this embodiment is to replay traffic data. It should be noted that in traffic recording and playback, the traffic refers to all requests within a certain time period. All requests sent to application A are recorded by some means, and then these requests are forwarded to application B. The requests received by application B are then re-requested in application B. The whole process is called "traffic recording and playback".
[0031] Specifically, in order to replay traffic data, it is first necessary to capture the software's traffic data. Commonly used packet capture tools include Wireshark and Tcpdump, which can be used to capture traffic data.
[0032] Step S002: Obtain the third and fourth categories based on the interval values and distribution of the time intervals.
[0033] It should be noted that proportional compression, by reducing each time interval region proportionally, can maintain the highest similarity between the compressed data and the original traffic data intervals. While prioritizing compression of larger time intervals can reduce packet loss, it leads to lower similarity between the compressed data and the original data interval distribution. Therefore, we consider calculating the interval distribution of the actual traffic data and applying different compression methods to different regions. Proportional compression is used for the third category where adjacent intervals are relatively close, while priority compression is used for the fourth category where adjacent intervals are relatively close. However, priority compression results in lower similarity between the compressed data and the original data interval distribution. Therefore, for the fourth category with lower interval consistency, we improve the priority method to improve the similarity with the original interval distribution while maintaining a lower packet loss rate, thereby improving the simulation accuracy of the original traffic data.
[0034] Please see Figure 2 It shows the data packets and time intervals in the traffic data. Different letters A, B, C, D, E, and F represent different data packets. Each data packet is a block. The time spent sending each data packet is recorded as the data packet value of each data packet. The longer the sending time, the larger the data packet value and the larger the amount of data contained in the data packet. The interval between blocks represents the time interval between the sending of adjacent data packets. The time spent in each time interval is recorded as the interval value of each interval.
[0035] Furthermore, each time interval is arranged according to the time order in the traffic data to obtain a time interval sequence. The time interval sequence is then segmented by OTSU multi-threshold to obtain several first categories. The interval values of time intervals in the same first category are similar and continuously distributed. The interval values of different time intervals may differ significantly and are far apart in the time interval sequence.
[0036] It should be further explained that after obtaining several first categories, it is necessary to calculate the consistency regions, i.e., the third category. The consistency region refers to the area where multiple adjacent intervals are relatively similar. Because the intervals of the consistency region are close, the proportional compression method is adopted, which is equivalent to compressing each interval to the same degree, which can ensure that the similarity after compression is large compared with that before compression. Since the consistency region includes multiple intervals, the threshold for the number of intervals also needs to be calculated. At the same time, for the similarity of traffic data before and after compression, the change of large intervals can cause a greater change in similarity. Therefore, it is necessary to calculate the interval value threshold. Only those that meet the interval number threshold and the interval value threshold can be regarded as consistency regions. That is, the third category adopts the proportional compression method.
[0037] Specifically, the frequency of the first occurrence of each interval value in the time interval sequence is counted, and all interval values are rearranged in ascending order of the first occurrence frequency to obtain an interval frequency sequence. The interval frequency sequence is then segmented using the OTSU threshold to obtain a first segmentation threshold k1, which is actually an interval value. The first occurrence frequency corresponding to this interval value is used as the second segmentation threshold k2. It should be noted that if the interval value represented by the first segmentation threshold k1 exists in the interval frequency sequence, then the first occurrence frequency of that interval value is used as the second segmentation threshold. If the interval value represented by the first segmentation threshold k1 does not exist in the interval frequency sequence, then the first occurrence frequency of the interval value with the smallest difference from this interval value is used as the second segmentation threshold. If there are multiple interval values with the smallest difference, then the first occurrence frequency corresponding to the smallest interval value is selected as the second segmentation threshold. This second segmentation threshold is the desired interval quantity threshold. Based on the second segmentation threshold, the first category is filtered, and the first category with a number of elements greater than the second segmentation threshold k2 is designated as the second category. The resulting second category consists of regions with consecutive intervals that have small differences and a number of intervals greater than k2.
[0038] Furthermore, since the interval values of each interval in the same first category are only similar, not necessarily completely equal, and the interval value threshold is used to filter the second category to obtain the third category, i.e., the consistency region; therefore, firstly, the mean of the interval values of all elements in each second category is calculated, and the mean is used as the second representative value of each second category; the second occurrence frequency of each second representative value is counted among all the second representative values of the second categories, and all the second representative values are rearranged in ascending order of the second occurrence frequency to obtain the representative frequency sequence. The representative frequency sequence is segmented by the OTSU threshold to obtain the third segmentation threshold k3. The second category whose second representative value is greater than the third segmentation threshold k3 is regarded as the third category. At the same time, all intervals in the time interval sequence other than the third category are classified as the fourth category.
[0039] At this point, each third category represents a consistent region, where the time intervals are continuously distributed and differ little, while the interval values are relatively large; while the fourth category is a non-consistent region, requiring compression of each time interval separately.
[0040] Step S003: Obtain the first compression ratio for each interval in the fourth category and the second compression ratio for each interval in the third category.
[0041] It should be noted that for each interval in the fourth category, the first compression ratio of each interval is calculated by the interval value and the third occurrence frequency. In order to prevent packet loss when using proportional compression in the fourth category, the larger the interval, the higher the compression ratio should be. At the same time, in order to ensure the similarity of the interval distribution after compression and before compression, since the interval with the higher occurrence frequency has a greater impact on similarity, the interval with the higher frequency should have a smaller compression ratio.
[0042] Specifically, in the fourth category, the first Taking an interval as an example, its first compression ratio The calculation method is as follows:
[0043]
[0044] in, Indicates the first The third frequency of occurrence of the interval value of each interval. Indicates the first Interval values for each interval, This represents an exponential function with the natural constant as its base, used for normalization. It should be noted that in this embodiment, an exponential function with the natural constant as its base is used to achieve normalization and inverse proportionality; in actual implementation, other functions can be chosen to achieve the same normalization and inverse proportional relationship. Furthermore, the obtained first compression ratio may correspond to the same first compression ratio for multiple intervals with the same interval value but far apart in the time interval sequence. In this case, the third frequency of occurrence... The larger, the more The greater the impact of each interval on the similarity before and after compression, the smaller the initial compression ratio should be. The larger the value, the higher the initial compression ratio should be.
[0045] It should be further noted that, in order to ensure a high overall similarity and to avoid a large difference in compression rates between consistent and inconsistent regions for intervals with the same interval value, which would result in low similarity in the distribution of intervals before and after compression, it is necessary to obtain the second compression rate of each interval in each third category based on the first compression rate of each interval in the fourth category and perform proportional compression.
[0046] Specifically, the absolute value of the difference between the second representative value of each third category and each interval in the fourth category is calculated. The first compression rate of the interval in the fourth category with the smallest absolute value of the difference is taken as the second compression rate of each interval in the corresponding third category. At this time, the second compression rate ensures the similarity of the interval distribution before and after compression between consistent and inconsistent regions. However, the first compression rate is more dispersed because the interval values of adjacent intervals differ greatly, and the intervals with smaller differences are more dispersed. Therefore, the compression of each interval in the fourth category also needs to consider the difference in data packets on the left and right sides, which requires further analysis.
[0047] Step S004: Obtain the correction coefficient based on the number of elements in the first category to which each interval in the fourth category belongs and the data packet value of the adjacent data packets, and obtain the third compression rate.
[0048] It should be noted that, in order to ensure a low packet loss rate while maintaining a high degree of similarity in the interval distribution before and after compression, the differences in run length and data packet value changes need to be considered. The run length is the number of consecutive occurrences of intervals with small differences in interval values in the time interval sequence. The larger the run length, i.e., the more consecutive intervals occur, the greater the impact on the similarity of the interval distribution, and the lower the compression ratio should be. The larger the data packet size around a certain interval, i.e., the larger the data packet value, the more significant the change in the overall traffic data will be when compressing that interval, and the lower the compression ratio should be.
[0049] Specifically, each interval in the fourth category belongs to a certain first category in step S002, and the number of elements in the first category is used as the run length of each interval; each interval in the fourth category has left and right adjacent data packets, each data packet has a data packet value, and the ratio of the data packet value to the largest data packet value in the traffic data is used as the block value corresponding to each data packet.
[0050] Furthermore, in the fourth category, the first Taking an interval as an example, its correction factor The calculation method is as follows:
[0051]
[0052] in, Indicates the first The block value of the data packet to the left of the interval. Indicates the first The block value of the data packet to the right of the interval. Indicates the first Each interval of the journey, This indicates the maximum run in the fourth category. Indicates the first The difference between the left and right packet block values at each interval. This represents the largest difference in left and right packet block values within the fourth category. The correction coefficient is influenced by the mean of the left and right packet block values, the run length of the interval, and the difference in block values between the left and right packets. The block value is a normalized value, while the run length and the difference in block values are normalized in the formula by being compared with the maximum value. At this point, the larger the mean block value, the larger the amount of data in the left and right packets between the intervals, and the smaller the compression ratio should be. The larger the run length, the more frequently intervals with small differences in value appear consecutively, which has a greater impact on the similarity of the interval distribution, and the smaller the compression ratio should be. The larger the difference in block values, the more significant the changes in the overall traffic data will occur when compressing this interval, and the smaller the compression ratio should be.
[0053] Furthermore, the correction coefficients of each interval in the fourth category are linearly normalized to obtain the normalized values of the correction coefficients, which are denoted as the correction rate for each interval. The product of the correction rate of each interval and the first compression rate is taken as the third compression rate for each interval in the fourth category. Thus, the second compression rate for each interval in the third category (i.e., the consistent region) and the third compression rate for each interval in the fourth category (i.e., the inconsistent region) are obtained respectively, ensuring the similarity of the interval distribution before and after compression, while avoiding packet loss.
[0054] Step S005: Compress the traffic data according to the obtained compression ratio and automatically replay it.
[0055] Each interval in the time interval sequence corresponds to a compression ratio. Intervals belonging to the third category correspond to a second compression ratio, and intervals belonging to the fourth category correspond to a third compression ratio. Each time interval is compressed according to the compression ratio corresponding to each interval to obtain compressed traffic data. It should be noted that the compression ratio refers to the ratio of the difference between the compressed interval value and the uncompressed interval value to the uncompressed interval value. That is, the smaller the compression ratio, the smaller the difference between the interval values before and after compression; the larger the compression ratio, the greater the difference between the interval values before and after compression.
[0056] Automatic playback of compressed traffic data can be achieved using existing methods, such as open-source technologies like doom and RDebug, which enable automatic playback and software testing.
[0057] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for automatic traffic replay in software testing, characterized in that, The method includes the following steps: Obtain software traffic data; The process involves acquiring data packets and time intervals from traffic data. The interval values of these time intervals form a time interval sequence. The interval values in the time interval sequence are divided into several first categories through multi-threshold segmentation. Each first category contains several interval values. The frequency of the first occurrence of each interval value in the time interval sequence is counted. The interval frequency sequence is obtained by sorting the interval frequency sequences in ascending order. The interval frequency sequence is then segmented by thresholds to obtain a first segmentation threshold. The first occurrence frequency corresponding to the first segmentation threshold is used as a second segmentation threshold. The first category, in which the number of elements in the first category is greater than the second segmentation threshold, is designated as the second category. The mean of all interval values in each second category is used as the second representative value of each second category. The second frequency of the second representative value is counted and sorted in ascending order to obtain the representative frequency sequence. The representative frequency sequence is thresholded to obtain the third segmentation threshold. The second category with a second representative value greater than the third segmentation threshold is used as the third category. All interval values in the time interval sequence other than the third category are classified as the fourth category. The first compression ratio of each interval is obtained based on the third frequency of occurrence and the interval value of each interval in the fourth category. The difference between the second representative value of each third category and the interval value of each interval in the fourth category is obtained. The first compression ratio of the interval with the smallest difference in the fourth category is taken as the second compression ratio of each interval in the corresponding third category. The number of elements in the first category to which each interval belongs in the fourth category is used as the run length of each interval. The block value of each data packet in the traffic data is obtained. The correction coefficient of each interval is obtained based on the run length of each interval in the fourth category and the block values of the left and right data packets. The third compression ratio of each interval is obtained based on the correction coefficient of each interval and the first compression ratio. The traffic data is compressed and automatically replayed based on the second compression rate for each interval in the third category and the third compression rate for each interval in the fourth category.
2. The automatic traffic replay method for software testing according to claim 1, characterized in that, The specific methods for obtaining data packets and time intervals from the traffic data are as follows: Software traffic data contains several data packets, each data packet being a block, and the interval between each block represents the time interval between the transmission of adjacent data packets.
3. The automatic traffic replay method for software testing according to claim 2, characterized in that, The specific method for constructing the time interval sequence is as follows: The duration of each time interval is used as the interval value, and each time interval is arranged in the time order of the traffic data to obtain the time interval sequence.
4. The automatic traffic replay method for software testing according to claim 1, characterized in that, The specific method for obtaining the first compression ratio for each interval is as follows: in, Indicates the fourth category The first compression rate of each interval, Indicates the first The third frequency of occurrence of the interval value of each interval. Indicates the first Interval values for each interval, This represents an exponential function with the natural constant as its base.
5. The automatic traffic replay method for software testing according to claim 1, characterized in that, The specific method for obtaining the block value of each data packet in the traffic data is as follows: The time length corresponding to each data packet is used as the data packet value of each data packet, and the ratio of the data packet value to the largest data packet value in the traffic data is used as the block value of the corresponding data packet.
6. The automatic traffic replay method for software testing according to claim 1, characterized in that, The specific method for obtaining the correction coefficient for each interval is as follows: in, Indicates the fourth category Correction factor for each interval, Indicates the first The block value of the data packet to the left of the interval. Indicates the first The block value of the data packet to the right of the interval. Indicates the first Each interval of the journey, This indicates the maximum run in the fourth category. Indicates the first The difference between the left and right packet block values at each interval. This represents the largest difference between the left and right data packet block values in the fourth category.