Database stress testing method and apparatus, electronic device, and readable storage medium
By acquiring historical database operation commands and dynamically adjusting stress values in the stress testing environment, the problem of low efficiency and high cost of existing tools is solved, achieving efficient, flexible, and accurate database stress testing.
Patent Information
- Application Number
- CN202310296814.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-23
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-03-23
AI Technical Summary
Existing database stress testing tools are inadequate in terms of efficiency, flexibility, and cost. They cannot quickly and accurately assess the read and write performance capacity of a database, and they consume a lot of manpower and resources.
By acquiring historical operation commands from the database, simulating the production environment, conducting stress tests in a stress testing environment, dynamically adjusting the pressure value, and combining pressurization and depressurization strategies, the standard pressure value of the database is determined.
It enables efficient and flexible database stress testing, reduces manpower and resource costs, shortens the testing cycle, and accurately covers the complexity of database command access.
Smart Images

Figure CN116431452B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of big data technology, and in particular to a method, apparatus, electronic device, and computer-readable storage medium for stress testing a database. Background Technology
[0002] For most application systems, the bottleneck is often the database. Other factors in the application system, such as network bandwidth, load balancers, application servers (including CPU, memory, hard disk space, and connection count), and caching, can easily be improved through horizontal scaling (adding more machines). However, due to data consistency requirements, databases cannot distribute the pressure from read / write operations by rapidly adding more machines, as this requires data synchronization, a lengthy process. While front-end caching such as Redis, read / write splitting, or database sharding can alleviate the pressure, these methods are significantly more limited compared to the horizontal scaling of other application system components. Therefore, to ensure a smooth launch of a mature business system or successful event evaluation, it's necessary to initiate database expansion in advance. Knowing the database's read / write performance capacity is therefore essential, leading to the development of various database stress testing tools. Summary of the Invention
[0003] In view of this, this application provides a database stress testing method, apparatus, electronic device, and computer-readable storage medium that is efficient, flexible, can fully cover the complexity of database command access, achieves accurate testing, consumes less manpower and resource costs, and has a short stress testing cycle.
[0004] One aspect of this application provides a database stress testing method, comprising: Step 1, acquiring historical operation instructions of the database; Step 2, determining the stress testing environment corresponding to the database based on the database's production environment; Step 3, injecting the historical operation instructions into the stress testing environment according to a pressure value, wherein the pressure value is m historical operation instructions injected into the stress testing environment per second, and m is an integer greater than 1; Step 4, checking the pressure index of the stress testing environment every t seconds, wherein t is an integer greater than or equal to 1; Step 5, when the pressure index is normal, adjusting the pressure value according to a pressure increase strategy, repeating Step 3 and Step 4 until the pressure index is abnormal; and Step 6, when the pressure index is abnormal, adjusting the pressure value according to a pressure decrease strategy, repeating Step 3 and Step 4 until the pressure index checked for n consecutive t seconds is normal, and determining the current pressure value as the standard pressure value of the database, wherein n is an integer greater than or equal to 1.
[0005] According to the database stress testing method of this application embodiment, by injecting historical operation instructions into the stress testing environment, the execution of operation instructions in the actual production environment can be simulated. By adjusting or maintaining the stress value and checking the stress indicators of the stress testing environment every t seconds, the standard stress value of the database can be determined, thereby completing the stress test of the database. Compared with the prior art, the stress value of this application can be controlled and adjusted. Testers can dynamically adjust the stress value according to the stress indicators, thereby improving the efficiency and flexibility of stress testing. Moreover, the historical operation instructions of this application are historical operation instructions in the production environment, which are completely consistent with the actual situation and can fully cover the complexity of database instruction access, achieving accurate testing. In addition, this application only requires the reproduction of the production environment to obtain the stress testing environment, which is easy to implement, consumes less manpower and resource costs, and has a shorter stress testing cycle.
[0006] In some embodiments, when step three is executed for the first time, the pressure value is an initial pressure value, which is determined based on the number of historical operation instructions obtained during the test period, wherein the test period is s minutes, the number of historical operation instructions obtained during the s minutes is r, the initial pressure value is greater than r / 60s, s is greater than or equal to 1, and r is an integer greater than or equal to 100.
[0007] In some embodiments, the database includes a master database and a slave database, the master database is used for writing data, the slave database is used for reading data, the stress test includes write performance test and / or read performance test, when the stress test includes write performance test, the historical operation instructions include write operation historical operation instructions, and when the stress test includes read performance test, the historical operation instructions include read operation historical operation instructions.
[0008] In some embodiments, when the stress test includes a write performance test, the stress metric includes latency and / or a first average response time. When the stress metric includes the latency, an abnormal stress metric includes the latency being greater than or equal to a first threshold. When the stress metric includes the first average response time, an abnormal stress metric includes the first average response time being greater than or equal to a second threshold. The latency is the time difference between writing data to the master database and synchronizing it to the slave database, and the first average response time is the first average response time for writing data to the master database. When the stress test includes a read performance test, the stress metric includes the number of concurrently running instructions and / or a second average response time. When the stress metric includes the number of concurrently running instructions, an abnormal stress metric includes the number of concurrently running instructions being greater than or equal to a third threshold. When the stress metric includes the second average response time, an abnormal stress metric includes the second average response time being greater than or equal to a fourth threshold. The number of concurrently running instructions is the number of historical read operation instructions running simultaneously in the slave database, and the second average response time is the second average response time for reading data from the slave database.
[0009] In some embodiments, the pressurization strategy is to increase the pressure by a factor of 1 each time, and the depressurization strategy is to depress the pressure by q% of the initial pressure each time, wherein q is greater than or equal to 1 and less than or equal to 80.
[0010] In some embodiments, when the stress test includes a write performance test, the stress test environment corresponding to the database is determined according to the production environment of the database, including: configuring a mirror environment of the main database of the database on a mirror server; and using the mirror environment of the main database as the stress test environment.
[0011] When the stress test includes read performance testing, the stress test environment corresponding to the database is determined according to the production environment of the database, including: replicating the database as a slave database; and using the replicated slave database as the stress test environment.
[0012] When the stress test includes write performance testing and read performance testing, the stress test environment corresponding to the database is determined according to the production environment of the database, including: configuring the mirror environment of the database on the mirror server, wherein the mirror environment of the database includes the mirror environments of the master database and the slave database; and using the mirror environment of the database as the stress test environment.
[0013] In some embodiments, injecting the historical operation instructions into the stress test environment according to the stress value includes: caching the historical operation instructions into memory according to the stress value, wherein the cached historical operation instructions are greater than or equal to the stress value each time; and retrieving the historical operation instructions from the memory and injecting them into the stress test environment.
[0014] Another aspect of this application provides a database stress testing device, comprising: an acquisition module, which performs step one, acquiring historical operation instructions of the database; a determination module, which performs step two, determining the stress testing environment corresponding to the database based on the database's production environment; an injection module, which performs step three, injecting the historical operation instructions into the stress testing environment according to a pressure value, wherein the pressure value is m historical operation instructions injected into the stress testing environment per second, and m is an integer greater than 1; and a checking module, which performs step four, injecting the historical operation instructions into the stress testing environment every t seconds. The pressure indicators of the pressure test environment are checked once, where t is an integer greater than or equal to 1; a first adjustment module is used to execute step five, when the pressure indicators are normal, the pressure value is adjusted according to the pressurization strategy, and steps three and four are repeated until the pressure indicators are abnormal; and a second adjustment module is used to execute step six, when the pressure indicators are abnormal, the pressure value is adjusted according to the depressurization strategy, and steps three and four are repeated until the pressure indicators checked for n consecutive t seconds are all normal, and the current pressure value is determined as the standard pressure value of the database, where n is an integer greater than or equal to 1.
[0015] Another aspect of this application provides an electronic device including one or more processors and one or more memories, wherein the memories are used to store executable instructions that, when executed by the processor, implement the method described above.
[0016] Another aspect of this application provides a computer-readable storage medium storing computer-executable instructions that, when executed, are used to implement the method described above. Attached Figure Description
[0017] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:
[0018] Figure 1 A flowchart illustrating a database stress testing method according to some embodiments of this application is shown schematically;
[0019] Figure 2This schematically illustrates a flowchart of determining the stress testing environment corresponding to the database based on the production environment of the database, according to some embodiments of this application;
[0020] Figure 3 This schematically illustrates a flowchart of determining the stress testing environment corresponding to the database based on the production environment of the database, according to other embodiments of this application;
[0021] Figure 4 This schematically illustrates a flowchart of determining the stress testing environment corresponding to the database based on the production environment of the database, according to some embodiments of the present application.
[0022] Figure 5 This schematically illustrates a flowchart of injecting historical operating instructions into a pressure testing environment based on pressure values, according to some embodiments of this application.
[0023] Figure 6 This illustration schematically shows a database access architecture diagram of dbproxy according to some embodiments of this application;
[0024] Figure 7 This schematically illustrates a flow playback write load test structure according to some embodiments of this application;
[0025] Figure 8 This schematically illustrates a read load testing architecture diagram according to some embodiments of this application;
[0026] Figure 9 This schematic diagram illustrates a structural block diagram of a database stress testing apparatus according to some embodiments of this application;
[0027] Figure 10 The schematic diagram illustrates a structural block diagram of an electronic device according to some embodiments of this application. Detailed Implementation
[0028] The embodiments of this application will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of this application. In the following detailed description, numerous specific details are set forth to provide a comprehensive understanding of the embodiments of this application for ease of explanation. However, it is apparent that one or more embodiments may be implemented without these specific details. Furthermore, descriptions of well-known structures and technologies are omitted in the following description to avoid unnecessarily obscuring the concepts of this application. In the technical solutions of this application, the acquisition, storage, and application of user personal information, etc., all comply with the provisions of relevant laws and regulations, necessary confidentiality measures have been taken, and they do not violate public order and good morals.
[0029] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application. The terms “comprising,” “including,” etc., as used herein indicate the presence of the stated features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0030] For most application systems, the bottleneck is often the database. Other factors in the application system, such as network bandwidth, load balancers, application servers (including CPU, memory, hard disk space, and connection count), and caching, can easily be improved through horizontal scaling (adding more machines). However, due to data consistency requirements, databases cannot distribute the pressure from read / write operations by rapidly adding more machines, as this requires data synchronization, a lengthy process. While front-end caching such as Redis, read / write splitting, or database sharding can alleviate the pressure, these methods are significantly more limited compared to the horizontal scaling of other application system components. Therefore, to ensure a smooth launch of a mature business system or successful event evaluation, it's necessary to initiate database expansion in advance. Knowing the database's read / write performance capacity is therefore essential, leading to the development of various database stress testing tools.
[0031] In related technologies, database stress testing tools include mysqlslap, sysbench, and online API calls. mysqlslap can simulate concurrent database performance testing, but it cannot specify the data size used for testing, and testers cannot dynamically adjust the testing process, affecting the efficiency and flexibility of stress testing. Sysbench simulates concurrency and can perform performance tests on CPU, memory, threads, I / O, and database aspects; however, due to network issues, testing is very slow, and the table structures and database test commands created are relatively simple, failing to fully cover the complexity of database command access. Online API calls can completely simulate online access, using only online API calls. However, online API calls require strict environment configuration; the business server, database server, and actual data must be completely consistent with the online environment to obtain a relatively accurate stress assessment. Therefore, online API calls consume significant manpower and resource costs, and the stress testing cycle is long.
[0032] The following is for reference. Figures 1-10 This application describes a database stress testing method, apparatus, electronic device, computer-readable storage medium, and computer program product according to embodiments of the present application.
[0033] Figure 1 A flowchart illustrating a database stress testing method according to an embodiment of this application is shown schematically.
[0034] like Figure 1 As shown, the database stress testing method of this embodiment includes operations S210 to S270.
[0035] In operation S210, step one is to obtain the historical operation instructions from the database.
[0036] As one possible approach, operation S210 to retrieve historical operation instructions from the database may include operations S211 and S212.
[0037] In operation S211, log information is retrieved from the production environment of the database.
[0038] In operation S212, log information is parsed into historical operation commands. It's understood that the log information can include at least one historical operation command; the specific number of historical operation commands can be determined based on the actual parsing situation, and is not specifically limited here. Operations S211 and S212 facilitate the retrieval of historical operation commands from the database.
[0039] In operating S220, step two involves determining the corresponding stress testing environment for the database based on its production environment. It's understood that the stress testing environment is a reproduction of the production environment, and there are various ways to reproduce the production environment. The following section will provide a detailed explanation of how to determine the appropriate stress testing environment based on the production environment.
[0040] In operation S230, step three, historical operation commands are injected into the pressure test environment according to the pressure value, where the pressure value is m historical operation commands injected into the pressure test environment per second, and m is an integer greater than 1.
[0041] In operation S240, step four, check the pressure index of the stress test environment every t seconds, where t is an integer greater than or equal to 1.
[0042] When operating S250, in step five, when the pressure indicator is normal, adjust the pressure value according to the pressurization strategy, and repeat steps three and four until the pressure indicator becomes abnormal.
[0043] In operation S260, step six, when the pressure index is abnormal, adjust the pressure value according to the pressure reduction strategy, and repeat steps three and four.
[0044] During operation S270, until all pressure indicators checked for n consecutive t seconds are normal, the current pressure value is determined as the standard pressure value in the database, where n is an integer greater than or equal to 1.
[0045] According to the database stress testing method of this application embodiment, by injecting historical operation instructions into the stress testing environment, the execution of operation instructions in the actual production environment can be simulated. By adjusting or maintaining the stress value and checking the stress indicators of the stress testing environment every t seconds, the standard stress value of the database can be determined, thereby completing the stress test of the database. Compared with the prior art, the stress value of this application can be controlled and adjusted. Testers can dynamically adjust the stress value according to the stress indicators, thereby improving the efficiency and flexibility of stress testing. Moreover, the historical operation instructions of this application are historical operation instructions in the production environment, which are completely consistent with the actual situation and can fully cover the complexity of database instruction access, achieving accurate testing. In addition, this application only requires the reproduction of the production environment to obtain the stress testing environment, which is easy to implement, consumes less manpower and resource costs, and has a shorter stress testing cycle.
[0046] According to some embodiments of this application, when step three is executed for the first time, the pressure value is an initial pressure value. The initial pressure value is determined based on the number of historical operation instructions acquired during the test period, where the test period is s minutes, the number of historical operation instructions acquired in s minutes is r, the initial pressure value is greater than r / 60s, s is greater than or equal to 1, and r is an integer greater than or equal to 100. It is understood that when step three is executed for the first time, an initial pressure value needs to be set. Since the initial pressure value is used to measure the maximum number of operation instructions that the database can currently execute per second, the initial pressure value needs to be greater than r / 60s.
[0047] As an feasible approach, for example, the number of historical operation commands (r) within a test period of s minutes can be compressed to execute over u minutes, where u is less than s. Therefore, the initial stress value is determined to be approximately r / 60u. Further, for example, one hour's worth of database log information can be obtained. After parsing the log information, 100,000 historical operation commands are obtained. These 10,000 historical operation commands are then compressed to execute over 5 minutes, thus determining the initial stress value to be 330. Therefore, the initial stress value can be easily determined by using the test period and the number of historical operation commands obtained during the test period. The initial stress value, in turn, facilitates the determination of the standard stress value for the database.
[0048] In some embodiments of this application, the database includes a master database and a slave database. The master database is used for writing data, and the slave database is used for reading data. The stress test includes write performance testing and / or read performance testing. When the stress test includes write performance testing, the historical operation instructions include historical write operation instructions; when the stress test includes read performance testing, the historical operation instructions include historical read operation instructions. Therefore, the method of this application can only test the write performance of the database; it can only test the read performance of the database; or it can simultaneously test both the write and read performance of the database.
[0049] Existing stress testing tools like tpcc-mysql can test the overall performance of a database, but they cannot test read or write performance separately, making them unsuitable for performance testing of applications that are primarily query-based or write-only. Compared to tpcc-mysql, the method in this application has wider applicability and a broader testing scope.
[0050] According to some embodiments of this application, when the stress test includes a write performance test, the stress indicators include latency time and / or a first average response time, wherein the latency time is the time difference between writing data to the master database and synchronizing to the slave database, and the first average response time is the first average response time for writing data to the master database.
[0051] When the stress indicator includes delay time, an abnormal stress indicator is defined as a delay time greater than or equal to a first threshold, and a normal stress indicator is defined as a delay time less than the first threshold. For example, the first threshold can be 10 seconds. When the delay time is greater than or equal to 10 seconds, the stress indicator is determined to be abnormal. When the delay time is less than 10 seconds, the stress indicator is determined to be normal. Of course, the first threshold of 10 seconds is only an example and should not be construed as a limitation of this application.
[0052] When the stress indicator includes a first average response time, an abnormal stress indicator is defined as a first average response time greater than or equal to a second threshold, and a normal stress indicator is defined as a first average response time less than the second threshold. For example, the second threshold could be W milliseconds. When the first average response time is greater than or equal to W milliseconds, the stress indicator is determined to be abnormal. When the first average response time is less than W milliseconds, the stress indicator is determined to be normal. Of course, the second threshold of W milliseconds is merely an example and should not be construed as a limitation of this application.
[0053] When stress testing includes read performance testing, stress metrics include the number of concurrently running instructions and / or the second average response time, where the number of concurrently running instructions is the number of historical read operation instructions running simultaneously from the database, and the second average response time is the second average response time for reading data from the database.
[0054] When the stress metric includes the number of concurrently running instructions, an abnormal stress metric is defined as the number of concurrently running instructions being greater than or equal to a third threshold, while a normal stress metric is defined as the number of concurrently running instructions being less than the third threshold. For example, the third threshold could be the number of CPU cores. When the number of concurrently running instructions is greater than or equal to the number of CPU cores, the stress metric is considered abnormal. When the number of concurrently running instructions is less than the number of CPU cores, the stress metric is considered normal. Of course, using the number of CPU cores as the third threshold is merely an example and should not be construed as a limitation of this application.
[0055] When the stress indicator includes a second average response time, an abnormal stress indicator is defined as a second average response time greater than or equal to a fourth threshold, and a normal stress indicator is defined as a second average response time less than the fourth threshold. For example, the fourth threshold could be X milliseconds. When the second average response time is greater than or equal to X milliseconds, the stress indicator is considered abnormal. When the second average response time is less than X milliseconds, the stress indicator is considered normal. Of course, the fourth threshold of X milliseconds is merely an example and should not be construed as a limitation of this application.
[0056] Therefore, when stress testing includes write performance testing, latency and / or the first average response time can easily determine whether stress indicators are abnormal; when stress testing includes read performance testing, the number of concurrent commands and / or the second average response time can easily determine whether stress indicators are abnormal. This, in turn, facilitates determining whether to adjust the stress value, thereby establishing the standard stress value for the database.
[0057] In some embodiments of this application, the pressurization strategy can be twice the initial pressure value for each pressurization, and the depressurization strategy can be q% of the initial pressure value for each depressurization, where q is greater than or equal to 1 and less than or equal to 80. Therefore, the pressurization and depressurization strategies facilitate the adjustment of pressure values, thereby determining the standard pressure values for the database. The above pressurization and depressurization strategies are merely illustrative examples; other pressure value adjustment strategies are also possible, which will not be listed here. The above pressurization and depressurization strategies should not be construed as limiting this application.
[0058] In some embodiments, the decompression strategy can be 10% of the initial pressure value for each decompression.
[0059] In some embodiments, the decompression strategy can be 20% of the initial pressure value for each decompression.
[0060] In some embodiments, the decompression strategy can be 30% of the initial pressure value for each decompression.
[0061] In some embodiments, the decompression strategy can be 40% of the initial pressure value for each decompression.
[0062] In some embodiments, the decompression strategy can be 50% of the initial pressure value for each decompression.
[0063] In some embodiments, the decompression strategy can be 60% of the initial pressure value for each decompression.
[0064] In some embodiments, the decompression strategy can be 70% of the initial pressure value for each decompression.
[0065] In some embodiments of this application, when the stress test includes a write performance test, such as Figure 2 As shown, operation S220 determines the stress test environment corresponding to the database based on the database's production environment, including operations S221 and S222.
[0066] In operation S221, configure the mirror environment of the primary database on the mirror server.
[0067] In operation S222, the mirror environment of the main database is used as the stress test environment.
[0068] By operating S221 and S222, it is easy to determine the corresponding stress test environment for the database based on the database's production environment when performing stress tests, including write performance tests.
[0069] When stress testing includes read performance testing, such as Figure 3 As shown, operation S220 determines the stress test environment corresponding to the database based on the database's production environment, including operations S223 and S224.
[0070] In operation S223, the slave database of the database is copied.
[0071] In operation S224, the replicated database is used as a stress test environment.
[0072] By operating S223 and S224, it is easy to determine the corresponding stress test environment for the database based on the database's production environment during stress testing, including read performance testing.
[0073] When stress testing includes both write performance testing and read performance testing, such as Figure 4 As shown, operation S220 determines the stress test environment corresponding to the database based on the database's production environment, including operations S225 and S226.
[0074] When operating S225, configure the database mirroring environment on the mirror server. The database mirroring environment includes mirroring environments for the master database and slave database.
[0075] In operation S226, the database mirror environment is used as the stress test environment.
[0076] By operating S225 and S226, it is easy to determine the corresponding stress test environment for the database based on the database's production environment when performing stress tests, including write performance tests and read performance tests.
[0077] According to some embodiments of this application, such as Figure 5 As shown, operation S230 injects historical operation commands into the pressure test environment according to the pressure value, including operation S231 and operation S232.
[0078] In operation S231, historical operation instructions are cached into memory based on the pressure value, wherein each cached historical operation instruction is greater than or equal to the pressure value.
[0079] The S232 is used to extract historical operation instructions from memory and inject them into the stress test environment.
[0080] It's important to note that historical operation commands parsed from log information can be stored on the local disk. If the local disk needs to be read every time historical operation commands are injected into the stress test environment, the overhead of this disk read step may cause the stress test results to deviate from expectations. Therefore, caching historical operation commands in memory can reduce the impact of reading the local disk. Caching historical operation commands in memory based on the stress value and then retrieving them from memory to inject into the stress test environment facilitates the successful injection of historical operation commands.
[0081] Of course, historical operation commands can be injected into the stress test environment based on the pressure value, or they can be read from the local disk and injected directly into the stress test environment. Operations S231 and S232 should not be construed as limitations on this application.
[0082] The following reference Figures 6-8 A stress testing method based on the above-described database according to embodiments of this application is described in detail. It is to be understood that the following description is merely illustrative and not intended to limit the scope of this application.
[0083] The following are explanations of the terms used in this article:
[0084] MySQL cluster: A MySQL service group with one master and multiple slaves. A cluster contains one master database and multiple slave databases. The master database handles write traffic, and the slave databases handle read traffic.
[0085] DML: Statements that modify table data, such as deleting, updating, or modifying a row of data.
[0086] DDL: Statements that modify the table structure, such as adding or deleting columns or changing the character set of a table.
[0087] Dbproxy: Used to implement read / write separation for MySQL access. Accessing MySQL master and slave databases through Dbproxy will automatically route read and write traffic. Write traffic (DML statements, DDL statements) will be sent to the master database, and read traffic (select statements) will be sent to the slave database.
[0088] QPS: The number of database read requests per second.
[0089] TPS: The number of database write requests per second.
[0090] Latency: The time difference between writing data to the master database and synchronizing it to the slave database, measured in seconds (s) in MySQL.
[0091] Average response time: The average time it takes for dbproxy to return data to the client when reading or writing data. It is usually measured in milliseconds (ms).
[0092] MySQL instance: A machine with a set of MySQL database software installed. Multiple MySQL instances can be installed on one machine, and each instance can contain multiple databases.
[0093] threads_running: The number of SQL statements running simultaneously. When the cluster is under heavy load, more SQL statements will be executed at the same time, and the threads_running value will be very high. It can be obtained in real time from the MySQL instance.
[0094] This application primarily addresses the challenge of accurately assessing the read / write capacity details of an in-use MySQL cluster by extracting actual online SQL traffic and replaying it to a slave database or cluster mirror within the MySQL cluster, without compromising online stability.
[0095] The database stress testing method of this application is described in detail below.
[0096] 1. Function Description
[0097] 1.1 The online MySQL cluster needs to use dbporoxy traffic forwarding mode to collect all SQL text accessing MySQL, parse and store the SQL text uniformly, and finally use multiple processes to perform concurrent SQL injection to completely simulate the actual online access of this cluster.
[0098] 1.2 To address increased SQL pressure, each SQL statement is timestamped. During pressure increases, SQL statements with later timestamped statements are compressed and executed at the current time. This can be understood as parsing 10,000 SQL statements from one hour of data and executing them within 15 minutes, effectively doubling the SQL pressure.
[0099] 2. Architecture Design
[0100] 2.1 Online MySQL-DBProxy access architecture, such as Figure 6 As shown, MySQL uses a master-slave architecture and utilizes dbproxy to achieve read-write separation. When business SQL is accessed, dbproxy automatically identifies DML and DDL operations, sends DML operations to the master database to complete data creation, deletion, modification, and query, and sends query SQL to the slave database to achieve data read-write separation.
[0101] 2.2dbproxy data collection: During the load testing process, it is necessary to parse the online proxy logs to generate replay SQL. Since the generated SQL is quite large, it cannot be directly stored in memory and needs to be stored on disk first. Therefore, the storage options considered are: MySQL and local disk.
[0102] Writing the generated SQL to the local disk reduces the time by more than 50% compared to writing the SQL to the database, and also significantly reduces the consumption of machine resources, especially CPU and memory (parsing a 1GB file and writing it to the disk only requires less than 5% of CPU, memory, and disk resources, but writing to the database requires 50% of CPU resources and about 10% of memory resources). Therefore, writing to the local disk is faster than writing to MySQL and avoids the problem of memory overflow. Storing parsed data on the local disk is a better choice.
[0103] Since the SQL information required for playback is stored on the local disk, reading from the local disk every time playback is needed could lead to unexpected playback results due to the overhead of reading the SQL. Therefore, to solve this problem, a prefetching strategy is adopted. Simply put, data is prefetched from the database and cached in memory to reduce the impact of reading from the local disk.
[0104] When load testing begins, a specified amount of replay SQL information is pre-read and cached in memory. Then, the number of SQL statements in the SQL queue in memory is checked periodically to see if it meets the minimum replay requirement (the number of SQL statements in the SQLQueue is greater than or equal to the current replay QPS * 10). If it does not meet the requirement, caching continues. This ensures that there are SQL statements in memory that will be used for subsequent replays, reducing the impact of reading.
[0105] The collected data can be segmented by time, and the SQL queries for the required time period can be parsed to better reflect online peaks or troughs, allowing for targeted stress testing of the SQL components at different times.
[0106] 3. Load testing strategy
[0107] 3.1 Write TPS load testing strategy. Since write load testing cannot be replayed to the online slave database, load testing can only be performed using the image of this cluster, such as... Figure 7 The diagram shown is a traffic replay write load test structure diagram. A complete online MySQL instance image can be restored using online backup. One master and one slave are sufficient. The load test environment can be recycled immediately after use.
[0108] When writing the flow rate and water level, the following two indicators need to be monitored (abnormality of either indicator indicates that the current playback pressure is too high).
[0109] Latency: Whether the master-slave latency is greater than 10 seconds (configured when the user initiates the task).
[0110] Echo level: Check if the echo level is greater than N milliseconds (configured when the user initiates the task).
[0111] During the stress test, the initial pressure is set to 500 TPS (configured when the user initiates the task). Every five minutes, the indicators are checked. If the indicators are found to be normal, the pressure is increased; if the indicators are abnormal, the pressure is reduced.
[0112] Pressure increase strategy: Double the pressure each time, that is, increase the pressure by 500 TPS (initial TPS) each time.
[0113] Pressure reduction strategy: If a flat response anomaly is triggered, the pressure is reduced by 5 times the initial TPS (for example, if the initial TPS is 1000 TPS, then the pressure is reduced by 200 TPS). Then, the SQL for those five minutes is replayed. If the indicator is still abnormal, the pressure is reduced again until the indicator is normal. The pressure at this point is the highest pressure of this replay. If the indicator anomaly is triggered again later, the pressure is reduced again, but no more pressure is added. The subsequent SQL is replayed.
[0114] Once the replay definition is complete, the first step is to trigger an abnormal indicator during the pressure release process, i.e., reaching a peak value, indicating that a limit has been reached and the pressure will not increase further; only pressure reduction operations will occur until all SQL replays no longer trigger abnormal indicators. This pressure is the water level we need, and this value is recorded and stored in the metadata database.
[0115] 3.2 Read QPS load testing strategy: When load testing the QPS level, the online write traffic will be replayed normally at the same time. Therefore, when load testing the read traffic level, the following two indicators need to be monitored (abnormality of either indicator indicates that the current replay pressure is too high).
[0116] threads_running: Whether the threads_running value of the MySQL instance exceeds the number of CPU cores (configured when the user initiates the task).
[0117] Echo level: Check if the echo level is greater than N milliseconds (configured when the user initiates the task).
[0118] During the stress test, the initial pressure is 1000 QPS (configured when the user initiates the task). Every five minutes, the indicators are checked. If the indicators are found to be normal, the pressure is increased; if the indicators are abnormal, the pressure is reduced.
[0119] Pressure increase strategy: Double the pressure each time, that is, increase the pressure by 1000 QPS (initial QPS) each time.
[0120] Pressure reduction strategy: If a flat response anomaly is triggered, the pressure is reduced by 5 times the initial QPS (for example, if the initial QPS is 1000 QPS, then the pressure is reduced by 200 QPS). Then, the SQL for those five minutes is replayed. If the metrics are still abnormal, the pressure is reduced again until the metrics are normal (the pressure at this point is the highest pressure in this replay. If the metrics are still abnormal afterward, the pressure is reduced again, but no more pressure will be added). Then, the subsequent SQL is replayed.
[0121] Once the replay definition is complete, the first step is to trigger an abnormal indicator during the pressure release process, i.e., reaching a peak value, indicating that a limit has been reached and the pressure will not increase further; only pressure reduction operations will occur until all SQL replays no longer trigger abnormal indicators. This pressure is the water level we need, and this value is recorded and stored in the metadata database.
[0122] To reduce read load testing costs, an idle online slave database can be used for load testing. This eliminates the need to consider the impact of write operations, as the online master-slave data is synchronized in real time. With only one slave database configured, the total online read capacity is the number of slave databases multiplied by the load testing capacity of a single slave database. This ensures accuracy while saving the increased costs associated with configuring a mirrored environment. Figure 8 The diagram shown is a read load test architecture diagram.
[0123] 4. Environmental recycling
[0124] After the load test is completed, the mirror machine or the independently used slave machine is automatically recycled and can be used for machine scheduling in the next load test environment.
[0125] This application collects and parses actual online SQL queries, performs traffic control, and replays the traffic on idle slave databases or cluster mirrors, fully covering all scenarios of business database access. It also allows for flexible selection of peak traffic times to view capacity performance under specific time-period traffic pressure. This provides more accurate MySQL capacity information, enabling system maintenance personnel to gain a more comprehensive understanding of cluster usage. This application collects online SQL traffic as load testing data, with SQL text obtained from the business access dbproxy logs. Time periods can be selected for traffic control as needed. The capacity data output strategy uses the SQL average response value, latency, and instance threads_running value returned by dbproxy as references; latency and acceptable SQL average response values can be provided by the system user, and threads_runnings value is the actual number of CPU cores in the cluster. This application allows read / write load testing using online business system mirrors as the testing platform. System mirrors can be restored from backups, and read load testing can be performed directly on unused or temporarily expanded slave databases in the cluster, without considering the traffic impact of real-time online writes. The load testing environment of this application can be recycled and reused at any time to ensure the number of concurrent load tests, that is, the load testing system can run multiple MySQL clusters for load testing at the same time.
[0126] Based on the aforementioned database stress testing method, this application also provides a database stress testing device 10. The following will be combined with... Figure 9 The database stress testing device 10 is described in detail.
[0127] Figure 9 A schematic block diagram of a database pressure testing apparatus 10 according to an embodiment of this application is shown.
[0128] The database stress testing device 10 includes an acquisition module 1, a determination module 2, an injection module 3, an inspection module 4, a first adjustment module 5, and a second adjustment module 6.
[0129] Get module 1, which is used to perform operation S210: Step 1, get the historical operation instructions of the database.
[0130] Determine module 2, which is used to perform operation S220: Step 2, determine the stress test environment corresponding to the database based on the database's production environment.
[0131] Injection module 3 is used to perform operation S230: Step 3, inject historical operation instructions into the pressure test environment according to the pressure value, wherein the pressure value is m historical operation instructions injected into the pressure test environment per second, and m is an integer greater than 1.
[0132] Check module 4, which is used to perform operation S240: Step 4, check the pressure index of the stress test environment every t seconds, where t is an integer greater than or equal to 1.
[0133] First adjustment module 5, first adjustment module 5 is used to perform operation S250: step five, when the pressure index is normal, adjust the pressure value according to the pressurization strategy, repeat steps three and four until the pressure index is abnormal.
[0134] The second adjustment module 6 is used to perform operation S260: Step six, when the pressure index is abnormal, adjust the pressure value according to the pressure reduction strategy, repeat steps three and four until the pressure index checked for n consecutive t seconds is normal, and determine the current pressure value as the standard pressure value of the database, where n is an integer greater than or equal to 1.
[0135] According to the database stress testing apparatus 10 of this application embodiment, by injecting historical operation commands into the stress testing environment, the execution of operation commands in the actual production environment can be simulated. By adjusting or maintaining the pressure value and checking the pressure index of the stress testing environment every t seconds, the standard pressure value of the database can be determined, thereby completing the stress test of the database. Compared with the prior art, the pressure value of this application can be controlled and adjusted. Testers can dynamically adjust the pressure value according to the pressure index, thereby improving the efficiency and flexibility of stress testing. Moreover, the historical operation commands of this application are historical operation commands in the production environment, which are completely consistent with the actual situation and can fully cover the complexity of database command access, achieving accurate testing. In addition, this application only needs to reproduce the production environment to obtain the stress testing environment, which is easy to implement, consumes less manpower and resource costs, and has a shorter stress testing cycle.
[0136] According to embodiments of this application, this application also provides an electronic device, a computer-readable storage medium, and a computer program product.
[0137] Figure 10 A schematic block diagram of an example electronic device 800 that can be used to implement embodiments of this application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the application described and / or claimed herein.
[0138] like Figure 10As shown, device 800 includes a computing unit 801, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 802 or a computer program loaded from storage unit 808 into random access memory (RAM) 803. RAM 803 may also store various programs and data required for the operation of device 800. The computing unit 801, ROM 802, and RAM 803 are interconnected via bus 804. Input / output (I / O) interface 805 is also connected to bus 804.
[0139] Multiple components in device 800 are connected to I / O interface 805, including: input unit 806, such as keyboard, mouse, etc.; output unit 807, such as various types of monitors, speakers, etc.; storage unit 808, such as disk, optical disk, etc.; and communication unit 809, such as network card, modem, wireless transceiver, etc. Communication unit 809 allows device 800 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0140] The computing unit 801 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above, such as image recognition methods. For example, in some embodiments, the image recognition method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the image recognition method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform image recognition methods by any other suitable means (e.g., by means of firmware).
[0141] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0142] The program code used to implement the methods of this application may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0143] In the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0144] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0145] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), the Internet, and blockchain networks.
[0146] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is established by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service system, which addresses the shortcomings of traditional physical hosts and VPS (Virtual Private Server, or simply "VPS") services, such as high management difficulty and weak business scalability. Servers can also be servers in distributed systems or servers integrated with blockchain technology.
[0147] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this application can be achieved, and this is not limited herein.
[0148] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A database stress testing method, characterized in that, include: Step 1: Obtain historical operation instructions from the database, including: obtaining log information from the database's production environment and parsing the log information into the historical operation instructions; Step 2: Determine the stress testing environment corresponding to the database based on the production environment of the database; Step 3: Inject the historical operation commands into the pressure test environment according to the pressure value, wherein the pressure value is m historical operation commands injected into the pressure test environment per second, and m is an integer greater than 1; Step 4: Check the pressure index of the stress test environment every t seconds, where t is an integer greater than or equal to 1; Step 5: When the pressure indicator is normal, adjust the pressure value according to the pressurization strategy, and repeat steps 3 and 4 until the pressure indicator becomes abnormal; and Step six: When the pressure index is abnormal, adjust the pressure value according to the pressure reduction strategy, and repeat steps three and four until the pressure index is normal after n consecutive t seconds of checking. Then, determine the current pressure value as the standard pressure value of the database, where n is an integer greater than or equal to 1. The database includes a master database and a slave database. The master database is used for writing data, and the slave database is used for reading data. The stress test includes write performance testing and / or read performance testing. When the stress test includes write performance testing, the historical operation instructions include historical write operation instructions. When the stress test includes read performance testing, the historical operation instructions include historical read operation instructions. When the stress test includes write performance testing, the stress test environment corresponding to the database is determined based on the database's production environment, including: Configure the mirror environment of the primary database on the mirror server; and The mirror environment of the main database is used as the stress test environment; When the stress test includes read performance testing, the stress test environment corresponding to the database is determined based on the database's production environment, including: The slave database of the database is copied; and The copied database is used as the stress test environment; When the stress test includes write performance testing and read performance testing, the stress test environment corresponding to the database is determined based on the database's production environment, including: Configure a mirror environment for the database on the mirror server, wherein the mirror environment includes mirror environments for the master database and the slave database; and The mirror environment of the database is used as the stress test environment.
2. The method according to claim 1, characterized in that, When step three is executed for the first time, the pressure value is the initial pressure value. The initial pressure value is determined based on the number of historical operation instructions obtained during the test period, wherein the test period is s minutes, the number of historical operation instructions obtained during the s minutes is r, and the initial pressure value is greater than r / 60s, where s is greater than or equal to 1 and r is an integer greater than or equal to 100.
3. The method according to claim 1, characterized in that, When the stress test includes write performance testing, the stress metrics include latency and / or the first average response time. When the stress indicator includes the delay time, the stress indicator abnormality includes the delay time being greater than or equal to a first threshold. When the stress indicator includes the first average response time, the stress indicator abnormality includes the first average response time being greater than or equal to a second threshold. Here, the delay time is the time difference between writing data to the master database and synchronizing it to the slave database, and the first average response time is the first average response time for writing data to the master database. When the stress test includes a read performance test, the stress metrics include the number of instructions executed simultaneously and / or a second average response time. When the stress indicator includes the number of instructions running simultaneously, the stress indicator anomaly includes the number of instructions running simultaneously being greater than or equal to a third threshold. When the stress indicator includes the second average response time, the stress indicator anomaly includes the second average response time being greater than or equal to a fourth threshold. Here, the number of instructions running simultaneously is the number of read operation history operation instructions running simultaneously in the slave database, and the second average response time is the second average response time for reading data from the slave database.
4. The method according to claim 2, characterized in that, The pressurization strategy is to increase the pressure by a factor of 1 each time, and the depressurization strategy is to depress the pressure by q% of the initial pressure each time, where q is greater than or equal to 1 and less than or equal to 80.
5. The method according to any one of claims 1 to 4, characterized in that, The step of injecting the historical operation instructions into the pressure test environment based on the pressure value includes: The historical operation instructions are cached in memory according to the pressure value, wherein each cached historical operation instruction is greater than or equal to the pressure value; and The historical operation instructions are extracted from the memory and injected into the stress test environment.
6. A database stress testing device, characterized in that, include: The acquisition module is used to execute step one, acquiring historical operation instructions of the database, including: acquiring log information from the database's production environment and parsing the log information into the historical operation instructions; The determination module is used to execute step two, which determines the stress test environment corresponding to the database based on the production environment of the database. An injection module is used to perform step three, injecting the historical operation instructions into the pressure test environment according to the pressure value, wherein the pressure value is m historical operation instructions injected into the pressure test environment per second, and m is an integer greater than 1; The inspection module is used to perform step four, checking the pressure index of the stress test environment every t seconds, where t is an integer greater than or equal to 1; The first adjustment module is used to execute step five, whereby, when the pressure indicator is normal, the pressure value is adjusted according to the pressurization strategy, and steps three and four are repeated until the pressure indicator becomes abnormal; and The second adjustment module is used to execute step six. When the pressure index is abnormal, the pressure value is adjusted according to the pressure reduction strategy. Steps three and four are repeated until the pressure index is normal after n consecutive t seconds of checks. The current pressure value is then determined as the standard pressure value of the database, where n is an integer greater than or equal to 1. The database includes a master database and a slave database. The master database is used for writing data, and the slave database is used for reading data. The stress test includes write performance testing and / or read performance testing. When the stress test includes write performance testing, the historical operation instructions include historical write operation instructions. When the stress test includes read performance testing, the historical operation instructions include historical read operation instructions. When the stress test includes write performance testing, the stress test environment corresponding to the database is determined based on the database's production environment, including: Configure the mirror environment of the primary database on the mirror server; and The mirror environment of the main database is used as the stress test environment; When the stress test includes read performance testing, the stress test environment corresponding to the database is determined based on the database's production environment, including: The slave database of the database is copied; and The copied database is used as the stress test environment; When the stress test includes write performance testing and read performance testing, the stress test environment corresponding to the database is determined based on the database's production environment, including: Configure a mirror environment for the database on the mirror server, wherein the mirror environment includes mirror environments for the master database and the slave database; and The mirror environment of the database is used as the stress test environment.
7. An electronic device, characterized in that, include: One or more processors; One or more memories are provided for storing executable instructions that, when executed by the processor, implement the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The storage medium stores executable instructions that, when executed by a processor, implement the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Database pressure measuring method, device and electronic device
CN109254904A
Server pressure test method and device and computer readable storage medium
CN111078478A
