Code detection method, device, terminal device and readable storage medium
By comparing the performance indicators of the reference server and the server to be detected, errors in the second version of the code are automatically detected, which solves the problem of test accuracy and low efficiency, and achieves efficient and accurate code testing.
Patent Information
- Application Number
- CN202210487141.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-06
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2042-05-06
AI Technical Summary
In the code testing, it is difficult for the existing technology to take into account the accuracy and testing efficiency of the test results. Full testing cannot simulate the online situation. However, if the number of servers is large when deploying new versions of code, it is easy to affect the user and the testing efficiency is low.
By obtaining the performance indicator comparison between the reference server and the server to be detected, determine the number of inconsistent performance indicators. If it is greater than the preset number, it is determined that there is an error code in the second version of the code.
Automatic testing of software code is realized, testing efficiency and accuracy are improved, code problems can be quickly discovered, and the impact on users is reduced.
Smart Images

Figure CN114968767B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data processing, and particularly to a code detection method, device, terminal device, and readable storage medium. Background Art
[0002] In the field of code testing, after obtaining a new version of code, the following two methods are usually adopted to detect whether the new version of code will affect the stable operation of the server: First, full testing, including regression testing of online functions, stress testing, copy online traffic testing, etc. Second, select some servers among the servers running in the real business environment to deploy the new version of code, and then obtain the performance metrics of all servers. If the number of inconsistent performance metrics exceeds the specified value, developers troubleshoot the faults based on experience. For the first solution, since it is impossible to fully simulate the online situation, no matter how well prepared, it is impossible to avoid all faults. For the second solution, when adopting this solution, if the number of servers deploying the new version of code is small, it is difficult to discover the existing faults in time; if the number of servers deploying the new version of code is large, when there are faults, it has already affected a large number of users. Therefore, the testing efficiency is low. Therefore, how to balance the accuracy and efficiency of the test results in code testing has become an urgent problem to be solved. Summary of the Invention
[0003] The present application provides a code detection method, device, terminal device, and readable storage medium. On the one hand, this solution realizes the automatic testing of software code and improves the code testing efficiency; on the other hand, the performance metrics to be tested can be arbitrarily set, and the software code can be tested more comprehensively, improving the accuracy of the test results. The specific technical solutions are as follows:
[0004] In the first aspect of the embodiments of the present application, first, a code detection method is provided. The method includes:
[0005] Obtain the performance metrics of the reference server when running the first version of software code within a preset time period;
[0006] Obtain the performance metrics of the server to be detected when running the second version of software code within a preset time period, where the hardware configurations and software running environments of the reference server and the server to be detected are the same;
[0007] Compare each performance metric of the server to be detected with the corresponding performance metric of the reference server, and determine the number of inconsistent performance metrics;
[0008] When the number of inconsistent performance metrics is greater than the preset number, determine that there is an error code in the second version of software code.
[0009] Optionally, comparing each performance metric of the server to be detected with the corresponding performance metric of the reference server includes:
[0010] For each performance metric, comparing the average value of the metric values corresponding to each server to be detected with the average value of the metric values corresponding to each reference server.
[0011] Optionally, comparing each performance metric of the server to be detected with the corresponding performance metric of the reference server includes:
[0012] Comparing each performance metric of the operating system of the server to be detected with the corresponding performance metric of the operating system of the reference server; and / or
[0013] Comparing each performance metric of the application running on the server to be detected with the corresponding performance metric of the application running on the reference server.
[0014] Optionally, comparing each performance metric of the operating system of the server to be detected with the corresponding performance metric of the operating system of the reference server includes:
[0015] Comparing one or more of the CPU utilization rate, network IO data volume, disk utilization rate, disk IO utilization rate, and memory utilization rate of the operating system of the server to be detected with the corresponding performance metrics of the operating system of the reference server;
[0016] Comparing each performance metric of the application running on the server to be detected with the corresponding performance metric of the application running on the reference server includes:
[0017] Comparing one or more of the interface latency time, the number of interface status codes, and the number of error logs of the application running on the server to be detected with the corresponding performance metrics of the application running on the reference server.
[0018] Optionally, before obtaining the performance metrics of the reference server during normal operation within a preset time period, the method further includes:
[0019] Selecting a first number of servers from among multiple servers running in a real business environment and adding them to the reference server group, and selecting a first number of servers and adding them to the server group to be detected, where the software code currently running on the servers running in the real business environment is the first version of the software code;
[0020] Replacing the software code currently running on each server in the server group to be detected with the second version of the software code;
[0021] Obtain the performance metrics of the reference server when running the software code of the first version within a preset time period, including:
[0022] Obtain the performance metrics of each server in the reference server group when running the software code of the first version within a preset time period;
[0023] Obtain the performance metrics of the server to be detected when running the software code of the second version within a preset time period, including:
[0024] Obtain the performance metrics of each server in the server group to be detected when running the software code of the second version within a preset time period.
[0025] Optionally, if there is no error code in the software code of the second version, the method further includes:
[0026] Determine the proportion of the first quantity to the quantity of servers running in the real business environment;
[0027] When the proportion is not greater than the preset proportion, re-determine the second quantity of reference servers and the second quantity of servers to be detected in multiple servers running in the real business environment, where the second quantity is greater than the first quantity;
[0028] Repeat the code detection method until the proportion is greater than the preset proportion.
[0029] Optionally, when it is determined that there is an error code in the software code of the second version, the method further includes:
[0030] Replace the software code of the second version currently running on the server to be detected with the software code of the first version.
[0031] Optionally, when it is determined that there is an error code in the software code of the second version, the method further includes:
[0032] Send a notification message to the terminal device used by the target object, so that the target object can correct the error code in the software code of the second version.
[0033] In the second aspect of the embodiments of the present application, there is also provided a code detection device, and the device includes:
[0034] A first obtaining module, configured to obtain the performance metrics of the reference server when running the software code of the first version within a preset time period;
[0035] A second obtaining module, configured to obtain the performance metrics of the server to be detected when running the software code of the second version within a preset time period, where the hardware configurations and software running environments of the reference server and the server to be detected are the same;
[0036] A comparison module, configured to compare each performance metric of the server to be detected with the corresponding performance metric of the reference server respectively, and determine the number of inconsistent performance metrics;
[0037] A first determination module, configured to determine that there is an error code in the software code of the second version when the number of inconsistent performance metrics is greater than a preset number.
[0038] Optionally, the comparison module includes:
[0039] A first comparison sub-module, configured to compare the average value of the metric values corresponding to each server to be detected with the average value of the metric values corresponding to each reference server for each performance metric.
[0040] Optionally, the comparison module includes:
[0041] A second comparison sub-module, configured to compare each performance metric of the operating system of the server to be detected with the corresponding performance metric of the operating system of the reference server respectively; and / or
[0042] A third comparison sub-module, configured to compare each performance metric of the application running on the server to be detected with the corresponding performance metric of the application running on the reference server respectively.
[0043] Optionally, the second comparison sub-module includes:
[0044] A fourth comparison sub-module, configured to compare one or more of the CPU utilization rate, network IO data volume, disk utilization rate, disk IO utilization rate, and memory utilization rate of the operating system of the server to be detected with the corresponding performance metrics of the operating system of the reference server respectively;
[0045] The third comparison sub-module includes:
[0046] A fifth comparison sub-module, configured to compare one or more of the interface delay time, the number of interface status codes, and the number of error logs of the application running on the server to be detected with the corresponding performance metrics of the application running on the reference server respectively.
[0047] Optionally, the apparatus further includes:
[0048] A selection module, configured to select a first number of servers from multiple servers running in a real business environment and add them to the reference server group, and select a first number of servers and add them to the server group to be detected. The software code currently running on the servers running in the real business environment is the software code of the first version;
[0049] A first replacement module, configured to replace the software code currently running on each server in the server group to be detected with the software code of the second version;
[0050] The first acquisition module includes:
[0051] A first acquisition sub-module, configured to acquire the performance metrics of each server in the reference server group when running the software code of the first version within a preset time period;
[0052] The second acquisition module includes:
[0053] A second acquisition sub-module, configured to acquire the performance metrics of each server in the server group to be detected when running the software code of the second version within a preset time period.
[0054] Optionally, the apparatus further includes:
[0055] A second determination module, configured to determine the proportion of the first quantity to the quantity of multiple servers running in the real business environment;
[0056] A third determination module, configured to re-determine a second quantity of reference servers and a second quantity of servers to be detected among multiple servers running in the real business environment when the proportion is not greater than a preset proportion, where the second quantity is greater than the first quantity;
[0057] An execution module, configured to repeatedly execute the code detection method until the proportion is greater than the preset proportion.
[0058] Optionally, the apparatus further includes:
[0059] A second replacement module, configured to replace the software code of the second version currently running on the server to be detected with the software code of the first version.
[0060] Optionally, the apparatus further includes:
[0061] A sending module, configured to send a notification message to the terminal device used by the target object, so that the target object corrects the error code in the software code of the second version.
[0062] In the third aspect of the embodiments of the present application, an electronic device is further provided, including: 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 steps in the code detection method described in the first aspect of the embodiments of the present application.
[0063] In a fourth aspect of the embodiments of the present application, a non-transitory computer-readable storage medium storing computer instructions is further provided, wherein the computer instructions are used to cause the computer to execute the steps in the code detection method described in the first aspect of the embodiments of the present application.
[0064] In a fifth aspect of the embodiments of the present application, a computer program product is further provided, including a computer program, and the computer program implements the code detection method described in the first aspect of the embodiments of the present application when executed by a processor.
[0065] By using the code detection method of the present application, first, performance metrics of a reference server when running the software code of the first version within a preset time period are obtained, and then performance metrics of a server to be detected when running the software code of the second version within the preset time period are obtained. The reference server and the server to be detected have the same hardware configuration and software running environment. Then, each performance metric of the server to be detected is respectively compared with the corresponding performance metric of the reference server to determine the number of inconsistent performance metrics. If the number of inconsistent performance metrics is greater than a preset number, it is determined that there are error codes in the software code of the second version, which will affect the stable operation of the server. The code detection method of the present application has the following multiple effects:
[0066] First, by comparing the performance metrics of the reference server running stable code (the software code of the first version) with the performance metrics of the server to be detected running the code to be detected (the software code of the second version), automatic testing of the software code of the second version is realized, which helps to quickly discover problems in the code and improves the code testing efficiency.
[0067] Second, when comparing the performance metrics of the reference server with those of the server to be detected, the performance metrics to be tested can be set arbitrarily, enabling a more comprehensive test of the software code of the second version and improving the accuracy of the test results. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art.
[0069] Figure 1 is a flowchart of a code detection method shown in an embodiment of the present application;
[0070] Figure 2 is a schematic diagram of a code detection system shown in an embodiment of the present application;
[0071] Figure 3 is a complete flowchart diagram of a code detection method shown in an embodiment of the present application;
[0072] Figure 4 It is a structural block diagram of a code detection device shown in an embodiment of the present application. Specific embodiments
[0073] Next, the technical solutions in the embodiments of the present application will be described with reference to the accompanying drawings in the embodiments of the present application.
[0074] To solve the problems in the related art, the present application provides a code detection method, which can not only achieve automatic testing and improve testing efficiency, but also comprehensively test various performance indicators of the server after running the new version of the code, thereby improving the testing accuracy.
[0075] Figure 1 It is a flowchart of a code detection method shown in an embodiment of the present application. Referring to Figure 1 , the code detection method of the present application can specifically include the following steps:
[0076] Step S11: Obtain the performance indicators of the reference server when running the software code of the first version within a preset time period.
[0077] In this embodiment, the software code of the first version refers to the code that can make the server run stably and the failure rate is lower than the preset probability.
[0078] The software code can be the code of any application program, and the present embodiment does not specifically limit the type of the software code.
[0079] The performance indicators can be any type of indicators of the server, such as interface delay time, operating system resource utilization rate, the number of error logs, etc. The present embodiment does not specifically limit the type of the performance indicators.
[0080] Step S12: Obtain the performance indicators of the server to be detected when running the software code of the second version within a preset time period, where the hardware configurations and software running environments of the reference server and the server to be detected are the same.
[0081] In this embodiment, the software code of the second version refers to the code with an uncertain failure rate that needs to be tested, such as the new version of the code developed by development engineers.
[0082] The hardware configurations and software running environments of the reference server and the server to be detected are exactly the same, and both the reference server and the server to be detected are servers running in the real business environment (that is, when the reference server and the server to be detected fail, it will affect the use of online users). The only difference is that the reference server is currently running the software code of the first version, and the server to be detected is currently running the software code of the second version.
[0083] Step S13: Compare each performance metric of the server to be detected with the corresponding performance metric of the reference server, and determine the number of inconsistent performance metrics.
[0084] In this embodiment, multiple performance metrics of the server to be detected and multiple performance metrics of the reference server can be obtained. Then, each performance metric of the server to be detected is compared with the corresponding performance metric of the reference server. For example, the number of error logs of the server to be detected is compared with the number of error logs of the reference server, and the interface latency time of the server to be detected is compared with the interface latency time of the reference server, so as to determine the number of inconsistent performance metrics.
[0085] Step S14: When the number of inconsistent performance metrics is greater than a preset number, determine that there is an error code in the software code of the second version.
[0086] In this embodiment, after obtaining the number of inconsistent performance metrics between the server to be detected and the reference server, then determine whether the number of inconsistent performance metrics is greater than a preset number. If it is greater than the preset number, it means that there is an error code in the software code of the second version, which will affect the stable operation of the server. If it is not greater than the preset number, it means that there is no error code in the software code of the second version and it will not affect the stable operation of the server.
[0087] In this embodiment, first, two sets of servers are determined as comparison servers, namely the reference server and the server to be detected. Then, control the reference server to run the software code of the first version for a period of time, and control the server to be detected to run the software code of the second version for a period of time. After the reference server and the server to be detected run simultaneously for a period of time, obtain the performance metrics of the reference server and the performance metrics of the server to be detected. The type of performance metrics can be set according to actual needs. Then, each performance metric of the server to be detected is compared with the corresponding performance metric of the reference server to determine the number of inconsistent performance metrics. If the number of inconsistent performance metrics is greater than a preset number, it can be determined that there is an error code in the software code of the second version, which will affect the stable operation of the server and troubleshooting is required.
[0088] By adopting the code detection method of the present application, first, obtain the performance metrics of the reference server when running the software code of the first version within a preset time period, and then obtain the performance metrics of the server to be detected when running the software code of the second version within the preset time period. The hardware configurations and software running environments of the reference server and the server to be detected are the same. Next, compare each performance metric of the server to be detected with the corresponding performance metric of the reference server, and determine the number of inconsistent performance metrics. If the number of inconsistent performance metrics is greater than the preset number, it is determined that there are error codes in the software code of the second version, which will affect the stable operation of the server. The code detection method of the present application has the following multiple effects:
[0089] First, by comparing the performance metrics of the reference server running stable code (the software code of the first version) with the performance metrics of the server to be detected running the code to be detected (the software code of the second version), the automatic testing of the software code of the second version is realized, which helps to quickly discover problems in the code and improves the code testing efficiency.
[0090] Second, when comparing the performance metrics of the reference server with those of the server to be detected, the performance metrics to be tested can be set arbitrarily, which can comprehensively test the software code of the second version and improve the accuracy of the test results.
[0091] Combined with the above embodiments, in one implementation manner, comparing each performance metric of the server to be detected with the corresponding performance metric of the reference server may specifically include:
[0092] For each performance metric, compare the mean value of the corresponding metric values of each server to be detected with the mean value of the corresponding metric values of each reference server.
[0093] In this embodiment, there can be multiple reference servers and multiple servers to be detected. When the number of reference servers is multiple, for a certain performance metric, multiple metric values can be obtained. At this time, the mean value of the multiple metric values can be used as the final metric value corresponding to the reference server. Similarly, when the number of servers to be detected is multiple, for a certain performance metric, the mean value of the metric values of multiple servers to be detected can be used as the final metric value corresponding to the server to be detected.
[0094] Exemplarily, the reference servers include reference server 1, reference server 2, and reference server 3, and the servers to be detected include server to be detected 1 and server to be detected 2. The performance metrics include: the number of error logs and the interface latency time. Then, for the metric of the number of error logs, the number of error logs of reference server 1, reference server 2, and reference server 3 can be obtained respectively, and the mean value can be calculated. At the same time, the number of error logs of server to be detected 1 and server to be detected 2 can be obtained respectively, and the mean value can be calculated. Then, the mean value of the number of error logs of reference server 1, reference server 2, and reference server 3 is compared with the mean value of the number of error logs of server to be detected 1 and server to be detected 2 to check whether they are consistent (for each performance metric, if the difference between the mean value of the metric values corresponding to each server to be detected and the mean value of the metric values corresponding to each reference server is within the preset range, it is considered that the two are consistent; if the difference is not within the preset range, it is considered that the two are inconsistent, where the preset range can be set according to actual needs). Similarly, for the metric of the interface latency time, the interface latency times of reference server 1, reference server 2, and reference server 3 can be obtained respectively, and the mean value can be calculated. At the same time, the interface latency times of server to be detected 1 and server to be detected 2 can be obtained respectively, and the mean value can be calculated. Then, the mean value of the interface latency times of reference server 1, reference server 2, and reference server 3 is compared with the mean value of the interface latency times of server to be detected 1 and server to be detected 2 to check whether they are consistent.
[0095] In this embodiment, the number of reference servers can be the same as the number of servers to be detected, or can be different from the number of detection servers, which can be specifically set according to actual needs.
[0096] In this embodiment, the number of reference servers and the number of servers to be detected can both be set to multiple. For a single metric, the mean value of the metric values corresponding to each server to be detected is used as the final metric value, so that the final metric value is more in line with the actual operating conditions of the servers to be detected. The mean value of the metric values corresponding to each reference server is used as the final metric value, so that the final metric value is more in line with the actual operating conditions of the reference servers. In this way, the accuracy of the comparison result of the performance metrics between the servers to be detected and the reference servers can be improved, and further the accuracy of the detection result of the software code can be improved.
[0097] Combined with the above embodiments, in one implementation, comparing each performance metric of the server to be detected with the corresponding performance metric of the reference server may specifically include:
[0098] Comparing each performance metric of the operating system of the server to be detected with the corresponding performance metrics of the operating system of the reference server; and / or
[0099] Compare each performance metric of the application running on the server to be detected with the corresponding performance metric of the application running on the reference server respectively.
[0100] In this embodiment, the performance metric can be the performance metric of the operating system of the server. In this way, each performance metric of the operating system of the server to be detected can be compared with the corresponding performance metric of the operating system of the reference server respectively to determine whether there is an error code in the software code of the second version.
[0101] In this embodiment, the performance metric can be the performance metric of the application running on the server. In this way, each performance metric of the application running on the server to be detected can be compared with the corresponding performance metric of the application running on the reference server respectively to determine whether there is an error code in the software code of the second version.
[0102] Among them, the performance metric of the operating system of the server and the performance metric of the application running on the server can be set according to actual needs, and this embodiment does not make specific restrictions on this.
[0103] Of course, in actual implementation, it is possible to only compare the performance metrics of the operating system of the server, or only compare the performance metrics of the application running on the server, or also compare the performance metrics of the operating system of the server and the performance metrics of the application running on the server at the same time. This embodiment does not make specific restrictions on this.
[0104] In this embodiment, it is possible to arbitrarily select to compare each performance metric of the operating system of the server to be detected and / or each performance metric of the application running on the server. This can not only improve the flexibility of the test, but also more comprehensively test the software code and improve the accuracy of the test results.
[0105] Combined with the above embodiments, in one implementation manner, comparing each performance metric of the operating system of the server to be detected with the corresponding performance metric of the operating system of the reference server specifically may include:
[0106] Compare one or more of the CPU utilization rate, network IO data volume, disk utilization rate, disk IO utilization rate, and memory utilization rate of the operating system of the server to be detected with the corresponding performance metrics of the operating system of the reference server respectively.
[0107] In this embodiment, the performance metrics of the operating system may include: CPU utilization, network IO data volume, disk utilization, disk IO utilization, and memory utilization. When making a comparison, one or more of the above-mentioned metrics can be selected for comparison. Of course, the performance metrics of the operating system can also be other types of performance metrics, and this embodiment does not make specific limitations in this regard.
[0108] Correspondingly, comparing each performance metric of the application running on the server to be detected with the corresponding performance metric of the application running on the reference server may specifically include:
[0109] Comparing one or more of the interface latency time, the number of interface status codes, and the number of error logs of the application running on the server to be detected with the corresponding performance metrics of the application running on the reference server, respectively.
[0110] In this embodiment, the performance metrics of the application running on the server may include: interface latency time, the number of interface status codes, the number of error logs, etc. When making a comparison, one or more of the above-mentioned metrics can be selected for comparison. Of course, the performance metrics of the application can also be other types of performance metrics, and this embodiment does not make specific limitations in this regard.
[0111] In this embodiment, on the one hand, the performance metrics of the operating system and the performance metrics of the application running on the server can be set according to actual needs, so as to more comprehensively test the software code of the second version, thereby improving the accuracy of the test results. On the other hand, by comparing various performance metrics, the performance degradation problems introduced in the software code of the second version can be discovered in a timely manner.
[0112] Combining the above embodiments, in one implementation, before obtaining the performance metrics of the reference server during normal operation within a preset time period, the code detection method of the present application may further include the following steps:
[0113] Selecting a first number of servers from multiple servers running in a real business environment and adding them to the reference server group, and selecting a first number of servers and adding them to the server group to be detected. The software code currently running on the servers running in the real business environment is the software code of the first version;
[0114] Replacing the software code currently running on each server in the server group to be detected with the software code of the second version.
[0115] In this embodiment, before obtaining the performance metrics, a reference server group and a server group to be detected may be first created. Then, a first number of servers are selected from all the servers running in the real business environment and added to the reference server group, and a first number of servers are selected and added to the detection server group. The same server cannot be added to both the reference server group and the server group to be detected at the same time.
[0116] In this embodiment, the software code currently running on each server running in the real business environment is the software code of the first version. Therefore, after adding a first number of servers to the reference server group and adding a first number of servers to the detection server group, it is necessary to keep the software code currently running on each server in the reference server group unchanged as the software code of the first version, and at the same time replace the software code currently running on each server in the server group to be detected with the software code of the second version.
[0117] On this basis, obtaining the performance metrics when the reference server runs the software code of the first version within a preset time period may include:
[0118] Obtaining the performance metrics of each server in the reference server group when running the software code of the first version within a preset time period.
[0119] Obtaining the performance metrics when the server to be detected runs the software code of the second version within a preset time period may include:
[0120] Obtaining the performance metrics of each server in the server group to be detected when running the software code of the second version within a preset time period.
[0121] In this embodiment, two groups of servers with exactly the same configuration are selected. One group is used to deploy the stable code (the software code of the first version) that is currently running online, named the reference server group, and the other group deploys the code to be detected (the software code of the second version), named the server group to be detected. By comparing the performance metrics of the two groups of servers, automatic testing of the software code of the second version is achieved, without the need for manual troubleshooting one by one, which helps to quickly discover problems in the code and improve the code testing efficiency.
[0122] Combined with the above embodiments, in one implementation, if there is no error code in the software code of the second version, the code detection method of the present application may further include:
[0123] Determining the proportion of the first number to the number of all servers running in the real business environment;
[0124] When the ratio is not greater than the preset ratio, re-determining a second number of reference servers and a second number of servers to be detected from a plurality of servers operating in a real business environment, where the second number is greater than the first number;
[0125] The code detection method is repeatedly executed until the ratio is greater than a preset ratio.
[0126] In this embodiment, when the number of servers to be detected is the first number, if there is no error code in the second version of the software code, the number of servers to be detected can be further increased, or the ratio of the number of servers to be detected to the number of servers running in a real business environment can be increased, and then the second version of the software code is detected to see if there is an error code, and this step is repeated until the ratio of the number of servers to be detected to the number of servers running in a real business environment is greater than a preset ratio. If there is no error code in the second version of the software code during the process of gradually increasing the number of servers to be detected (the process of more and more servers in a real business environment changing the currently running software code to the second version of the software code), then it can be determined that the second version of the software code will not affect the stable operation of the server, that is, the second version of the software code can be applied in a real business scenario.
[0127] When the code detection method is first executed, the first number can be set arbitrarily, and the preset ratio can be determined based on experience gained from multiple tests.
[0128] In this embodiment, the ratio of the number of servers to be tested to the number of servers running in a real business environment is gradually increased, and the second version of the software code is simultaneously tested for errors. Compared to the related art method of directly selecting a larger ratio of servers to be tested and deploying the second version of the software code, this method can avoid the impact of code errors on a large number of users. Secondly, if, after a certain code test is correct, it is determined that the ratio of the number of servers to be tested to the number of servers running in a real business environment is greater than a preset ratio, it indicates that the second version of the software code can be directly applied to real business scenarios. At this time, all remaining servers that have not deployed the second version of the software code can be deployed with the second version of the software code, achieving a smooth deployment of the second version of the software code.
[0129] For example, if there are 30 servers running in a real business environment, first select 5 servers and add them to the reference server group, select 5 servers and add them to the server group to be detected. Keep the software code currently running on each server in the reference server group unchanged as the software code of the first version, replace the software code currently running on each server in the server group to be detected with the software code of the second version, and then execute steps S11 - S14 to determine whether there are error codes in the software code of the second version.
[0130] If there are no errors, continue to select 6 servers and add them to the reference server group, select 6 servers and add them to the server group to be detected, and execute steps S11 - S14 again to determine whether there are error codes in the software code of the second version.
[0131] Repeat the above steps, gradually increasing the number of servers in the server group to be detected. If when the proportion of the number of servers in the server group to be detected in all the servers (30 servers) is greater than the preset proportion (for example, 50%), it is still determined that there are no error codes in the software code of the second version, then it can be determined that the software code of the second version will not affect the stable operation of the servers, and the software code currently running on the remaining servers except the servers to be detected in all the servers can be replaced with the software code of the second version.
[0132] In the above process, the number of servers in the server group to be detected and the number of servers in the reference server group are not necessarily exactly the same, and can be specifically set according to actual needs.
[0133] Combined with the above embodiments, in one implementation, when it is determined that there are error codes in the software code of the second version, the code detection method of the present application may further include:
[0134] Replace the software code of the second version currently running on the server to be detected with the software code of the first version.
[0135] In this embodiment, since the server to be detected is a server running in a real business environment, if there are error codes in the software code of the second version, it will affect the normal response of the server to the business requests of users. Therefore, to avoid affecting the use of users, when it is determined that there are error codes in the software code of the second version, the software code of the second version currently running on the server to be detected can be replaced with the stable software code of the first version.
[0136] In this embodiment, when it is determined that there are error codes in the software code of the second version, promptly replacing the software code of the second version currently running on the server to be detected with the software code of the first version can avoid affecting the use of users and ensure the user experience.
[0137] In combination with the above embodiments, in one implementation, when it is determined that there is an error code in the software code of the second version, the code detection method of the present application may further include:
[0138] Sending a notification message to the terminal device used by the target object, so that the target object can correct the error code in the software code of the second version.
[0139] In this embodiment, the target object refers to the engineer who corrects the error code. Sending a notification message to the terminal device used by the target object can timely notify the target object to correct the error code in the software code of the second version.
[0140] Specifically, sending a notification message to the terminal device used by the target object may include:
[0141] Sending a notification message to the terminal device used by the target object by one or more of text messages, emails, and phone calls.
[0142] In this embodiment, sending a notification message to the terminal device used by the target object can enable the target object to timely correct the error code in the software code of the second version.
[0143] Figure 2 It is a schematic diagram of a code detection system shown in an embodiment of the present application. The code detection system may include: a code release controller, a monitoring agent, a monitoring service module, and an alarm service module. Among them, the code release controller is responsible for selecting a reference server group and a server group to be detected, increasing the proportion of the server to be detected in all servers, rolling back the code version when there is an error in the code, etc. The monitoring agent is deployed on the server and is responsible for collecting performance metrics of the server's operating system, performance metrics of the applications running on the server, and reporting the collected performance information to the monitoring service module in real time. The monitoring service module is responsible for grouping the performance information reported by the monitoring agent according to the grouping rules of the code release controller, comparing the performance metrics of the reference server group and the server group to be detected respectively, and notifying the code release controller to execute different instructions according to the comparison results. The alarm service module is responsible for timely notifying the target object when a code error is found.
[0144] The code detection method of the present application can be applied to Figure 2 the code detection system shown. Figure 3 It is a complete flow schematic diagram of a code detection method shown in an embodiment of the present application. Next, in combination with Figure 3 , a specific embodiment (see the following steps 1-step 11) will be used to describe the code detection method of the present application in detail.
[0145] Step 1: The development engineer completes the development of the new version of the code (the software code of the second version).
[0146] Step 2: The QA engineer completes the testing of the new version of the code.
[0147] Step 3: The operation and maintenance engineer uses the code release controller to start the release process of the new version of the code.
[0148] Step 4: The code release controller sets up a reference server group and a server group to be detected. It selects a first number of servers from the servers running in the real business environment (the servers currently running the stable version of the code (the software code of the first version)) and adds them to the reference server group, and selects a first number of servers and adds them to the server group to be detected. And it replaces the stable version of the code currently running on each server in the server group to be detected with the new version of the code.
[0149] Among them, the hardware configurations and software running environments of each server in the server group to be detected and the reference server group are exactly the same.
[0150] Step 5: Keep each server in the server group to be detected and each server in the reference server group running for a period of time.
[0151] Step 6: After running for a period of time, the monitoring agent collects the performance metrics of the operating systems of each server in the reference server group, the performance metrics of the applications running on the servers, and the performance metrics of the operating systems of each server in the server group to be detected, and the performance metrics of the applications running on the servers. The monitoring agent sends the collected performance metric information to the monitoring service module.
[0152] Step 7: For each performance metric, the monitoring service module compares the mean value of the metric values corresponding to each server to be detected with the mean value of the metric values corresponding to each reference server, and determines the number of inconsistent performance metrics.
[0153] Step 8: Determine whether the number of inconsistent performance metrics is greater than the preset number. If the number of inconsistent performance metrics is greater than the preset number, it means that there are error codes in the new version of the code, and go to Step 9. If the number of inconsistent performance metrics is not greater than the preset number, it means that there are no error codes in the new version of the code, and go to Step 10.
[0154] Step 9: The code release controller rolls back the code currently running on each server to be detected to the stable version of the code (the software code of the first version), notifies the operation and maintenance engineer (the target object) to troubleshoot the new version of the code through the alarm service module, and then returns to Step 3 to execute again.
[0155] Step 10: The code release controller determines the proportion of the number of servers to be detected in the total number of all servers, and determines whether it exceeds a preset proportion.
[0156] When it exceeds the preset proportion, go to Step 11; otherwise, go to Step 12. Re-select the second number of reference servers and the second number of servers to be detected, and return to Step 5 to execute again.
[0157] Step 11: The code release controller cancels the grouping configuration of the reference server group and the server group to be detected, and deploys the new version of the code to all servers that have not deployed the new version of the code.
[0158] Step 12: Re-select the second number of reference servers and the second number of servers to be detected, and return to Step 5 to execute again.
[0159] Step 13: The release process ends.
[0160] In this embodiment, two groups of servers with exactly the same configuration are selected. One group is used to deploy the stable code (the software code of the first version) that is currently running online, named the reference server group, and the other group deploys the code to be detected (the software code of the second version), named the server group to be detected. By comparing the performance metrics of the two groups of servers, code detection is achieved. This code detection solution has the following effects:
[0161] First, it realizes the automatic testing of software code, which helps to quickly discover problems in the code and improves the code testing efficiency.
[0162] Second, the performance metrics can be set arbitrarily, which improves the accuracy of the test results and helps to timely discover the performance degradation problems introduced by the software code.
[0163] Third, there is no need for manual checking one by one, which reduces the labor cost.
[0164] It should be noted that for the method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the embodiments of the present application are not limited by the described action sequence, because according to the embodiments of the present application, some steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present application.
[0165] Based on the same inventive concept, an embodiment of the present application provides a code detection device 400. Refer to Figure 4 , Figure 4 is the structural block diagram of a code detection device shown in an embodiment of the present application. As Figure 4 shown, the device 400 includes:
[0166] The first acquisition module 401 is configured to acquire performance metrics of the reference server when running the software code of the first version within a preset time period;
[0167] The second acquisition module 402 is configured to acquire performance metrics of the server to be detected when running the software code of the second version within a preset time period, where the hardware configurations and software running environments of the reference server and the server to be detected are the same;
[0168] The comparison module 403 is configured to compare each performance metric of the server to be detected with the corresponding performance metric of the reference server respectively, and determine the number of inconsistent performance metrics;
[0169] The first determination module 404 is configured to determine that there is an error code in the software code of the second version when the number of inconsistent performance metrics is greater than a preset number.
[0170] Optionally, the comparison module 403 includes:
[0171] The first comparison sub-module is configured to compare, for each performance metric, the mean value of the metric values corresponding to each server to be detected with the mean value of the metric values corresponding to each reference server.
[0172] Optionally, the comparison module 403 includes:
[0173] The second comparison sub-module is configured to compare each performance metric of the operating system of the server to be detected with the corresponding performance metric of the operating system of the reference server respectively; and / or
[0174] The third comparison sub-module is configured to compare each performance metric of the application running on the server to be detected with the corresponding performance metric of the application running on the reference server respectively.
[0175] Optionally, the second comparison sub-module includes:
[0176] The fourth comparison sub-module is configured to compare one or more of the CPU utilization rate, network IO data volume, disk utilization rate, disk IO utilization rate, and memory utilization rate of the operating system of the server to be detected with the corresponding performance metrics of the operating system of the reference server respectively;
[0177] The third comparison sub-module includes:
[0178] The fifth comparison sub-module is configured to compare one or more of the interface latency time, the number of interface status codes, and the number of error logs of the application running on the server to be detected with the corresponding performance metrics of the application running on the reference server respectively.
[0179] Optionally, the apparatus 400 further includes:
[0180] A selection module, configured to select a first number of servers from multiple servers running in a real business environment and add them to a reference server group, and select a first number of servers and add them to a to-be-detected server group. The software code currently running on the servers running in the real business environment is the software code of the first version;
[0181] A first replacement module, configured to replace the software code currently running on each server in the to-be-detected server group with the software code of the second version;
[0182] The first obtaining module includes:
[0183] A first obtaining sub-module, configured to obtain the performance metrics of each server in the reference server group when running the software code of the first version within a preset time period;
[0184] The second obtaining module includes:
[0185] A second obtaining sub-module, configured to obtain the performance metrics of each server in the to-be-detected server group when running the software code of the second version within a preset time period.
[0186] Optionally, the apparatus 400 further includes:
[0187] A second determination module, configured to determine the proportion of the first number in the number of multiple servers running in the real business environment;
[0188] A third determination module, configured to, when the proportion is not greater than a preset proportion, re-determine a second number of reference servers and a second number of to-be-detected servers from multiple servers running in the real business environment, where the second number is greater than the first number;
[0189] An execution module, configured to repeatedly execute the code detection method until the proportion is greater than the preset proportion.
[0190] Optionally, the apparatus 400 further includes:
[0191] A second replacement module, configured to replace the software code of the second version currently running on the to-be-detected server with the software code of the first version.
[0192] Optionally, the apparatus 400 further includes:
[0193] A sending module, configured to send a notification message to the terminal device used by the target object, so that the target object corrects the error code in the software code of the second version.
[0194] In another embodiment provided by the present application, an electronic device is further provided, including: 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 to enable the at least one processor to execute the code detection method described in any of the above embodiments of the present application.
[0195] In another embodiment provided by the present application, a non-transitory computer-readable storage medium storing computer instructions is further provided, wherein the computer instructions are used to cause the computer to execute the code detection method described in any of the above embodiments of the present application.
[0196] In another embodiment provided by the present application, a computer program product is further provided, including a computer program, and the computer program implements the code detection method described in any of the above embodiments of the present application when executed by a processor.
[0197] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium accessible by a computer or a data storage device such as a server, data center, etc. that includes one or more integrated available media. The available medium may be a magnetic medium (such as a floppy disk, hard disk, magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)).
[0198] It should be noted that in this text, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprising", "including" or any other variant thereof are intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements not only includes those elements but also includes other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising said element.
[0199] Each embodiment in this specification is described in a related manner. For the identical and similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for the relevant parts, reference can be made to the partial description of the method embodiment.
[0200] The above are only the preferred embodiments of the present application and are not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are all included in the protection scope of the present application.
Claims
1. A code detection method, characterized in that, Including: Obtaining performance metrics of a reference server when running the software code of the first version within a preset time period; Obtaining performance metrics of a server to be detected when running the software code of the second version within a preset time period, where the hardware configurations and software running environments of the reference server and the server to be detected are the same; Comparing each performance metric of the server to be detected with the corresponding performance metric of the reference server respectively to determine the number of inconsistent performance metrics; When the number of inconsistent performance metrics is greater than a preset number, determining that there is an error code in the software code of the second version; Before obtaining the performance metrics of the reference server when running normally within a preset time period, the method further includes: Selecting a first number of servers from multiple servers running in a real business environment and adding them to the reference server group, and selecting a first number of servers and adding them to the server group to be detected. The software code currently running on the servers running in the real business environment is the software code of the first version; Replacing the software code currently running on each server in the server group to be detected with the software code of the second version; The method further includes: If there is no error code in the software code of the second version, determining the proportion of the first number to the number of multiple servers running in the real business environment; When the proportion is not greater than a preset proportion, re-determining a second number of reference servers and a second number of servers to be detected from multiple servers running in the real business environment, where the second number is greater than the first number; Repeatedly executing the code detection method until the proportion is greater than the preset proportion.
2. The method according to claim 1, wherein Comparing each performance metric of the server to be detected with the corresponding performance metric of the reference server respectively includes: For each performance metric, comparing the mean value of the metric values corresponding to each server to be detected with the mean value of the metric values corresponding to each reference server.
3. The method according to claim 1 or 2, characterized in that, Comparing each performance metric of the server to be detected with the corresponding performance metric of the reference server respectively includes: Comparing each performance metric of the operating system of the server to be detected with the corresponding performance metrics of the operating system of the reference server respectively; and / or Comparing each performance metric of the application running on the server to be detected with the corresponding performance metrics of the application running on the reference server respectively.
4. The method according to claim 3, wherein Comparing each performance metric of the operating system of the server to be detected with the corresponding performance metrics of the operating system of the reference server respectively includes: Comparing one or more of the CPU utilization rate, network IO data volume, disk utilization rate, disk IO utilization rate, and memory utilization rate of the operating system of the server to be detected with the corresponding performance metrics of the operating system of the reference server respectively; Comparing each performance metric of the application running on the server to be detected with the corresponding performance metrics of the application running on the reference server respectively includes: Compare one or more of the interface latency time, the number of interface status codes, and the number of error logs of the application running on the server to be detected with the corresponding performance metrics of the application running on the reference server, respectively.
5. The method according to claim 1, wherein: Obtain the performance metrics of the reference server when running the software code of the first version within a preset time period, including: Obtain the performance metrics of each server in the reference server group when running the software code of the first version within a preset time period; Obtain the performance metrics of the server to be detected when running the software code of the second version within a preset time period, including: Obtain the performance metrics of each server in the server group to be detected when running the software code of the second version within a preset time period.
6. The method according to claim 5, characterized in that When it is determined that there is an error code in the software code of the second version, the method further includes: Replace the software code of the second version currently running on the server to be detected with the software code of the first version.
7. The method according to claim 1, wherein When it is determined that there is an error code in the software code of the second version, the method further includes: Send a notification message to the terminal device used by the target object, so that the target object corrects the error code in the software code of the second version.
8. A code detection device, characterized in that, including: A first obtaining module, configured to obtain the performance metrics of the reference server when running the software code of the first version within a preset time period; A second obtaining module, configured to obtain the performance metrics of the server to be detected when running the software code of the second version within a preset time period, where the hardware configurations and software running environments of the reference server and the server to be detected are the same; A comparison module, configured to compare each performance metric of the server to be detected with the corresponding performance metric of the reference server respectively, and determine the number of inconsistent performance metrics; A first determination module, configured to determine that there is an error code in the software code of the second version when the number of inconsistent performance metrics is greater than a preset number; Before obtaining the performance metrics of the reference server when running normally within a preset time period, the device is further configured to: Select a first number of servers from multiple servers running in a real business environment and add them to the reference server group, and select a first number of servers and add them to the server group to be detected. The software code currently running on the servers running in the real business environment is the software code of the first version; Replace the software code currently running on each server in the server group to be detected with the software code of the second version; The device is further configured to: If there is no error code in the software code of the second version, determine the proportion of the first number to the number of multiple servers running in a real business environment; When the proportion is not greater than a preset proportion, re-determine a second number of reference servers and a second number of servers to be detected from multiple servers running in a real business environment, where the second number is greater than the first number; Repeat the code detection method until the proportion is greater than the preset proportion.
9. An electronic device, including: 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 when the instructions are executed by the at least one processor, the at least one processor is enabled to execute the method according to any one of claims 1-7.
10. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are for causing the computer to execute the method according to any one of claims 1-7.
11. A computer program product, comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-7.
Citation Information
Patent Citations
Code performance evaluation method and device, electronic equipment and storage medium
CN111858287A