Database pressure testing method and device, electronic equipment and storage medium
By analyzing and reorganizing the test query statements, dynamically adjusting the load mode, and obtaining thread concurrency and execution time, the problem of fixed load mode of the stress test tool is solved, and more accurate database stress testing is achieved.
Patent Information
- Application Number
- CN202510612170.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-13
- Publication Date
- 2025-08-15
AI Technical Summary
In the prior art, the load mode configured by the stress test tool is fixed and cannot be dynamically adjusted according to the test environment, resulting in the stress test results that cannot accurately reflect the performance of the database in the production environment, and the accuracy of the stress test is low.
By performing statement analysis on the preset test query statement, the statement execution order is obtained, and the load mode is dynamically adjusted according to the business query statement, the thread concurrency and thread execution time are obtained, and the business query statement is executed through the target thread, the reference execution time is obtained, and stress test is carried out.
It improves the accuracy of database stress testing, makes business operations more matched with load patterns, and can more truly reflect the system performance of the database in different business scenarios.
Smart Images

Figure CN120492300A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology and is applied to the fields of financial technology and digital medicine, and in particular to a database stress testing method, device, electronic device and storage medium. Background Art
[0002] To ensure stable and efficient database operation in a production environment, database stress testing is necessary to evaluate its performance under various load conditions. For example, in FinTech scenarios, banking databases need to support a large number of users performing online transactions simultaneously, such as balance inquiries, transfers, and payments. To ensure that the banking database can handle these high volumes of concurrent transaction requests, stress testing is necessary. Another example is in digital healthcare scenarios, where digital healthcare databases involve a large number of transactions, such as registration, payment, and test result entry. To ensure that the digital healthcare database can handle these high volumes of transactions under high load, stress testing is necessary.
[0003] In the prior art, databases are stress-tested using stress-testing tools. However, these tools typically configure a fixed load pattern, preventing dynamic adjustment based on the test environment. If the configured load pattern is inaccurate, the stress-test results may not reflect the database's performance in production, resulting in low stress-test accuracy. Summary of the Invention
[0004] The main purpose of the embodiments of the present application is to provide a database stress testing method, device, electronic device and storage medium, aiming to improve the accuracy of database stress testing.
[0005] To achieve the above objectives, a first aspect of an embodiment of the present application provides a database stress testing method, the database stress testing method comprising:
[0006] Parsing the test query statements to obtain the execution order of the test query statements;
[0007] Reorganize the test query statements according to the statement execution order to obtain business query statements;
[0008] Acquire simulated business data and store the simulated business data in a test database;
[0009] Obtaining a load pattern according to the business query statement, and obtaining thread concurrency and thread execution duration according to the load pattern;
[0010] Starting a target thread according to the thread concurrency, and executing the business query statement on the simulated business data through the target thread to obtain a reference execution time; wherein the reference execution time is the time it takes for the target thread to execute the business query statement;
[0011] A stress test is performed on the test database according to the reference execution time and the thread execution time.
[0012] In some embodiments, obtaining thread concurrency and thread execution duration according to the load pattern includes:
[0013] Obtain thread configuration parameters according to the load pattern;
[0014] Obtaining a parameter configuration order of the thread configuration parameters;
[0015] Extracting the thread concurrency and the thread execution duration from the thread configuration parameters according to the parameter configuration order.
[0016] In some embodiments, executing the business query statement on the simulated business data through the target thread to obtain a reference execution duration includes:
[0017] Obtaining the query frequency and query waiting time of the business query statement;
[0018] Obtaining database connection reuse status based on the query frequency and query waiting time;
[0019] Obtaining a target database connection link from a connection pool according to the database connection reuse state;
[0020] The business query statement is executed on the simulated business data through the target thread and the target database connection link to obtain the reference execution duration.
[0021] In some embodiments, the connection pool includes an original database connection link, and obtaining a target database connection link from the connection pool according to the database connection reuse state includes:
[0022] Obtaining the link connection status of the original database connection link;
[0023] Acquiring a storage capacity of the connection pool according to the link connection state;
[0024] If the storage capacity is less than a preset capacity threshold, a new link is created to obtain the target database connection link;
[0025] If the storage capacity is equal to the preset capacity threshold, the original database connection link is screened according to the link connection status to obtain the target database connection link.
[0026] In some embodiments, obtaining the link connection status of the original database connection link includes:
[0027] In response to the thread start request, an interference thread is started, and the original database connection link is obtained through the interference thread; wherein the original database connection link has an initial connection state;
[0028] The initial connection state is updated to obtain the link connection state.
[0029] In some embodiments, obtaining the storage capacity of the connection pool according to the link connection status includes:
[0030] Calculating the link utilization of the connection pool according to the link connection status;
[0031] The storage capacity of the connection pool is obtained according to the link utilization.
[0032] In some embodiments, the reorganizing the test query statements according to the statement execution order to obtain the business query statements includes:
[0033] Obtaining the transaction type of the test query statement and the transaction ratio of the transaction type;
[0034] Filtering the test query statement according to the transaction type and the transaction ratio to obtain a reference query statement;
[0035] The reference query statements are reorganized according to the statement execution order to obtain the business query statement.
[0036] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides a database stress testing device, the database stress testing device comprising:
[0037] A statement parsing module is used to parse the preset test query statement to obtain the statement execution order of the test query statement;
[0038] A reorganization module, configured to reorganize the test query statements according to the statement execution order to obtain business query statements;
[0039] A storage module is used to obtain simulated business data and store the simulated business data in a test database;
[0040] An acquisition module, configured to acquire a load pattern according to the business query statement, and acquire thread concurrency and thread execution duration according to the load pattern;
[0041] An execution module, configured to start a target thread according to the thread concurrency, and execute the business query statement on the simulated business data through the target thread to obtain a reference execution time; wherein the reference execution time is the time it takes for the target thread to execute the business query statement;
[0042] A testing module is used to perform a stress test on the test database according to the reference execution time and the thread execution time.
[0043] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and the processor implements the method described in the first aspect when executing the computer program.
[0044] To achieve the above-mentioned purpose, the fourth aspect of the embodiments of the present application proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the method described in the first aspect.
[0045] The database stress testing method, database stress testing device, electronic device and computer-readable storage medium proposed in the embodiments of the present application are that the database will perform many complex business operations in the production environment. In order to make the test environment closer to the production environment, it is necessary to simulate the complex business operations in the production environment. Complex business operations are composed of multiple query statements. In order to accurately simulate real complex business operations, the test query statements are parsed to obtain the statement execution order of the test query statements. The test query statements are reorganized according to the statement execution order to obtain business query statements, so as to test whether the functions of the database work as expected based on the business query statements. Simulated business data is obtained to simulate the data scenario in the production environment based on the simulated business data, and the simulated business data is stored in the test database to test the performance of the database under various data conditions. The load pattern is obtained according to the business query statement to dynamically adjust the load pattern according to the business query statement, rather than using a fixed load pattern, so that the matching between the business operation and the load pattern is higher, the accuracy of the load pattern acquisition is improved, and thus the accuracy of the stress test is improved. The thread concurrency and thread execution time are obtained according to the load pattern to simulate high concurrency load and execution time. Start the target thread based on the thread concurrency, execute business query statements on the simulated business data through the target thread, obtain the reference execution time, and perform stress testing on the test database based on the reference execution time and the thread execution time. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 This is a flowchart of the database stress testing method provided by an embodiment of the present application;
[0047] Figure 2 yes Figure 1 Flowchart of step S120 in FIG.
[0048] Figure 3 yes Figure 1 Flowchart of step S140 in FIG.
[0049] Figure 4 yes Figure 1 Flowchart of step S150 in FIG.
[0050] Figure 5 yes Figure 4 Flowchart of step S430 in FIG.
[0051] Figure 6 yes Figure 5 Flowchart of step S510 in FIG.
[0052] Figure 7 yes Figure 5 Flowchart of step S520 in FIG.
[0053] Figure 8 Schematic diagram of the structure of the database stress testing device provided in the embodiment of the present application;
[0054] Figure 9 This is a schematic diagram of the hardware structure of the electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0056] It should be noted that although the device schematics illustrate functional module divisions and the flowcharts illustrate logical sequences, in certain circumstances, the steps shown or described may be performed in a sequence that differs from the module divisions in the device or the sequence in the flowcharts. The terms "first," "second," and so on, in the specification, claims, and drawings, are used to distinguish similar items and are not necessarily used to describe a specific sequence or precedence.
[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0058] To ensure stable and efficient database operation in a production environment, database stress testing is necessary to evaluate its performance under various load conditions. For example, in FinTech scenarios, banking databases need to support a large number of users performing online transactions simultaneously, such as balance inquiries, transfers, and payments. To ensure that the banking database can handle these high volumes of concurrent transaction requests, stress testing is necessary. Another example is in digital healthcare scenarios, where digital healthcare databases involve a large number of transactions, such as registration, payment, and test result entry. To ensure that the digital healthcare database can handle these high volumes of transactions under high load, stress testing is necessary.
[0059] In the prior art, databases are stress-tested using stress-testing tools. However, these tools typically configure a fixed load pattern, preventing dynamic adjustment based on the test environment. If the configured load pattern is inaccurate, the stress-test results may not reflect the database's performance in production, resulting in low stress-test accuracy.
[0060] Based on this, embodiments of the present application provide a database stress testing method, a database stress testing device, an electronic device, and a computer-readable storage medium, aiming to improve the accuracy of database stress testing.
[0061] The database stress testing method, database stress testing device, electronic device, and computer-readable storage medium provided in the embodiments of the present application are specifically illustrated through the following embodiments. First, the database stress testing method in the embodiments of the present application is described.
[0062] The database stress testing method provided in the embodiment of the present application relates to the field of computer technology. The database stress testing method provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or as a server cluster or distributed system composed of multiple physical servers, or as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the database stress testing method, etc., but is not limited to the above forms.
[0063] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, and the like. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments in which tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media, including storage devices.
[0064] Figure 1 This is an optional flowchart of the database stress testing method provided in the embodiment of the present application. Figure 1 The method may include but is not limited to steps S110 to S160.
[0065] Step S110, parsing the preset test query statement to obtain the statement execution order of the test query statement;
[0066] Step S120, reorganizing the test query statement according to the statement execution order to obtain a business query statement;
[0067] Step S130, obtaining simulated business data and storing the simulated business data in a test database;
[0068] Step S140: Obtain a load pattern according to the business query statement, and obtain thread concurrency and thread execution duration according to the load pattern;
[0069] Step S150: starting a target thread according to the thread concurrency, executing a business query statement on the simulated business data through the target thread, and obtaining a reference execution time; wherein the reference execution time is the time it takes for the target thread to execute the business query statement;
[0070] Step S160 : performing a stress test on the test database according to the reference execution time and the thread execution time.
[0071] In steps S110 to S160 shown in the embodiment of the present application, business query statements are used to simulate the user's actual business operations, and the load pattern is dynamically adjusted according to the business query statements, rather than using a fixed load pattern configured by a stress testing tool. This makes the business operations more compatible with the load pattern, improves the accuracy of load pattern acquisition, and thus improves the accuracy of stress testing.
[0072] In step S110 of some embodiments, a stress testing tool is called to generate a test query statement, which is a query statement used to verify the performance parameters of the database under high load conditions during the database stress testing process. The test query statement adopts Structured Query Language (SQL), which can be a simple query statement containing basic database operations such as insert, delete, update, and query, or a complex query statement containing complex operations such as multi-table connection, subquery, and aggregate function. The test query statement is lexically analyzed and decomposed into a series of lexical units, such as keywords, identifiers, operators, and constants. According to the grammatical rules of the structured query language, the lexical units are converted into a syntax tree, which shows the hierarchical relationship of each test query statement, and the statement execution order of the test query statement is obtained according to the syntax tree. The statement execution order is used to reflect the execution order of the test query statement in the actual business process.
[0073] By reorganizing the test query statements in the order in which they are executed, business query statements are generated. This allows for more business scenarios to be covered based on the business query statements and supports the processing of complex business logic. By reorganizing the query statements in the order of actual business processes, it is possible to accurately simulate real business operations in a production environment, thereby more accurately reflecting the database's system performance in different business scenarios. For example, in a fintech scenario, a transfer operation will sequentially undergo multiple sub-business operations, such as verifying the account, checking the balance, deducting funds, adding funds, recording the transaction, and sending notifications. To more realistically simulate the transfer business scenario, the test query statements for each sub-business operation can be combined according to the order in which the statements are executed. For another example, in a digital healthcare scenario, a patient visit operation will sequentially undergo multiple sub-business operations, such as creating an appointment, verifying the doctor's availability at the appointment time, recording the appointment, sending a confirmation, and recording the visit information. By reorganizing the test query statements for these sub-business operations, a patient visit scenario can be simulated.
[0074] See also Figure 2 In some embodiments, step S120 may include but is not limited to steps S210 to S230:
[0075] Step S210, obtaining the transaction type and transaction ratio of the transaction type of the test query statement;
[0076] Step S220, screening the test query statements according to the transaction type and transaction ratio to obtain reference query statements;
[0077] Step S230 : reorganize the reference query statements according to the statement execution order to obtain the business query statements.
[0078] In step S210 of some embodiments, a single test query statement can be used as a transaction. In a production environment, different types of transactions usually exist in a certain proportion. For example, 70% of database requests are used to request the banking database to perform balance query operations, and 30% of database requests are used to request the banking database to perform transfer operations. In order to more realistically simulate the actual business scenario, the transaction type of the test query statement and the transaction ratio of the transaction type are obtained. Transaction types include read transactions, write transactions, or read-write mixed transactions. Read transactions only include data query operations, write transactions include data modification operations, such as insert operations, update operations, and delete operations. Read-write mixed transactions are transactions that include both data query operations and data modification operations. The sum of the transaction ratios of read transactions, write transactions, and read-write mixed transactions is 1.
[0079] In step S220 of some embodiments, if the transaction ratio of the transaction type does not meet the preset ratio condition, the test query statement is screened according to the transaction type to obtain a reference query statement, and the transaction ratio of the transaction type of the reference query statement meets the preset ratio condition. If the transaction ratio of the transaction type meets the preset ratio condition, the test query statement is used as the reference query statement. The preset ratio condition is used to indicate the set ratios of read transactions, write transactions, and read-write mixed transactions, such as the set ratio of read transactions is 70%, the set ratio of write transactions is 20%, and the set ratio of read-write mixed transactions is 10%. At least one preset ratio condition can be defined in the configuration file in advance, and different preset ratio conditions can be used to obtain combinations of transaction types with different transaction ratios, thereby testing the performance of the database in executing query statements of different transaction types and different transaction ratios.
[0080] The stress testing tool generates multiple test query statements. These transaction types include read transactions, write transactions, and mixed read and write transactions. The transaction ratio of read transactions is 60%, the transaction ratio of write transactions is 10%, and the transaction ratio of mixed read and write transactions is 30%. The preset ratio conditions indicate that the set ratio of read transactions is 70%, the set ratio of write transactions is 20%, and the set ratio of mixed read and write transactions is 10%. If the transaction ratio of a transaction type does not meet the preset ratio conditions, the test query statements are filtered according to the transaction type to ensure that the transaction ratio of the transaction type meets the preset ratio conditions.
[0081] In step S230 of some embodiments, the reference query statements are reorganized in sequence according to the statement execution order to obtain the business query statement.
[0082] Through the above steps S210 to S230, complex business operations in real business scenarios can be accurately simulated, thereby improving the accuracy of database stress testing.
[0083] In step S130 of some embodiments, simulated business data is generated using a stress testing tool. The simulated business data is business data generated during the database stress testing process by simulating the data structure and data characteristics of a real business scenario. Database connection parameters are obtained, including the database address, port number, database name, etc. The database connection parameters are used to connect to a test database, and the simulated business data is stored in the test database, which is the database to be stress tested.
[0084] The load pattern indicates the load generation method, including constant, incremental, pulse, or random load patterns. In constant load pattern, the load level remains constant and is used to evaluate the sustained performance of the database under a stable load. In incremental load pattern, the load level continuously increases, simulating a situation where the number of requests increases over time. In pulse load pattern, the load level suddenly increases within a short period of time, simulating sudden high-concurrency requests. In random load pattern, the load level fluctuates randomly, simulating unpredictable user behavior and load fluctuations. A mapping table between business operation types and load patterns can be pre-established. The business operation type of a business query statement can be obtained, and the mapping table can be queried based on the business operation type to obtain the load pattern. This helps to better correlate the load pattern with specific business scenarios and enable dynamic adjustment of the load pattern. The thread concurrency and thread execution duration are obtained based on the load pattern. The thread concurrency is the number of concurrent threads, and the thread execution duration is the duration of the database stress test under that thread concurrency. For example, if the business operation type is a transfer operation, which is usually a high-frequency operation, the constant load mode can be used to simulate daily transfer operations. During specific periods of time, there will be sudden peaks in transfer operations, and the pulse load mode can be used to simulate the sudden load during peak periods.
[0085] See also Figure 3 In some embodiments, step S140 may include but is not limited to steps S310 to S330:
[0086] Step S310, obtaining thread configuration parameters according to the load mode;
[0087] Step S320, obtaining the parameter configuration order of the thread configuration parameters;
[0088] Step S330 : extracting thread concurrency and thread execution duration from thread configuration parameters according to the parameter configuration order.
[0089] In step S310 of some embodiments, if the load mode is a constant load mode, a first concurrency sequence and a first duration sequence are generated, wherein the first concurrency sequence stores multiple concurrencies, each of which has the same value, and the first duration sequence stores the execution duration corresponding to each concurrency, and the value of each execution duration may be the same or different. If the load mode is a step-by-step increasing mode, a second concurrency sequence and a second duration sequence are generated, wherein the second concurrency sequence stores multiple concurrencies that increase in sequence, and the second duration sequence stores the execution duration corresponding to each concurrency, and the value of each execution duration may be the same or different. If the load mode is a pulse load mode, a third concurrency sequence and a third duration sequence are generated, wherein the third concurrency sequence has one or more mutated concurrencies, and the third duration sequence stores the execution duration corresponding to each concurrency, and the value of each execution duration may be the same or different. If the load mode is a random load mode, a fourth concurrency sequence and a fourth duration sequence are generated. The fourth concurrency sequence is a random sequence and stores multiple randomly generated concurrencies. The fourth duration sequence stores the execution duration corresponding to each concurrency. The values of each execution duration can be the same or different. The concurrency and execution duration are used as thread configuration parameters.
[0090] In step S320 of some embodiments, the concurrency is arranged in a concurrency sequence in a certain order, and the concurrency has an arrangement order. The execution duration is arranged in a duration sequence in a certain order, and the execution duration has an arrangement order. Since there is a one-to-one correspondence between concurrency and execution duration, the arrangement order of concurrency in the concurrency sequence or the arrangement order of execution duration in the duration sequence can be used as the parameter configuration order. If the load mode is a step-by-step increasing mode, the second concurrency sequence is [1,5,10], and the second duration sequence is [10,10,10], then the thread configuration parameters are [1,10], [5,10], and [10,10], respectively, and the parameter configuration orders are 1, 2, and 3, respectively.
[0091] In step S330 of some embodiments, the concurrency is extracted from the thread configuration parameters in the order of parameter configuration to obtain the thread concurrency, and the execution duration is extracted from the thread configuration parameters to obtain the thread execution duration. It should be noted that the concurrency and execution duration of the next thread are obtained only after the stress test is performed based on the current thread concurrency and the current thread execution duration.
[0092] Through the above steps S310 to S330, different load conditions can be dynamically generated according to the load pattern, thereby testing the system performance parameters of the database under different load conditions, ensuring the accuracy and reliability of the database stress test.
[0093] Start target threads based on the thread concurrency. If the thread concurrency is 5, start 5 target threads. Use the target threads to execute business query statements on simulated business data to simulate database business requests in a high-concurrency environment. Record the execution time of the target threads to obtain the reference execution time.
[0094] See also Figure 4 In some embodiments, step S150 may include but is not limited to steps S410 to S440:
[0095] Step S410, obtaining the query frequency and query waiting time of the business query statement;
[0096] Step S420, obtaining the database connection reuse status based on the query frequency and query waiting time;
[0097] Step S430: obtaining a target database connection link from the connection pool according to the database connection reuse state;
[0098] Step S440 , executing the business query statement on the simulated business data through the target thread and the target database connection link to obtain a reference execution time.
[0099] In step S410 of some embodiments, in real-world business scenarios, users frequently perform various database operations, and multiple users may access the database simultaneously. For example, during peak transaction times, a large number of users may simultaneously perform operations such as transfers, bill payments, and balance inquiries. To test the system performance of the database under high load, the query frequency of business query statements is obtained to simulate the situation where multiple users concurrently access the database. The query frequency is the number of times a business query statement is executed per unit time. The query frequency can be the same business query statement or different business query statements. For example, if a business query statement is executed 100 times in 1 minute, the query frequency is 100 times / minute. After performing a business operation, users typically wait for a period of time before performing the next business operation. For example, after browsing the insurance product details page, a user may spend time considering whether to purchase the product before performing the next operation. To simulate real-world business operation behavior, the query wait time of the business query statement is obtained. The query wait time is the length of time required to execute the business query statement.
[0100] In step S420 of some embodiments, each time a database is accessed, a new database connection needs to be established. Establishing and disconnecting a connection involves steps such as network communication, identity authentication, and resource allocation, which will result in a large system resource overhead. In order to reduce the resource overhead of establishing and disconnecting a connection, the query waiting time and the query frequency are multiplied to obtain the query duration. If the query duration is greater than or equal to the duration threshold, indicating that the database access volume is large, the interface switch of the connection multiplexing interface is set to the on state to obtain the database connection multiplexing state, and the resource overhead is reduced by multiplexing the database connection. If the query duration is less than the duration threshold, the resource overhead of establishing and disconnecting a connection can be ignored, and the interface switch of the connection multiplexing interface is set to the off state.
[0101] In step S430 of some embodiments, a connection pool is a mechanism for managing and reusing database connections. This mechanism creates a certain number of database connections in advance and stores them in memory. To reduce the overhead of creating and disconnecting connections and improve stress testing efficiency, a target database connection link is retrieved from the connection pool based on the database connection reuse status, allowing for quick access and use of database connections without creating a new connection for each access. The target database connection link, or database connection, is a communication link established between a client and a database. The client can be a stress testing tool or a stress testing framework.
[0102] In step S440 of some embodiments, the target thread uses the target database connection link to execute a business query statement on the simulated business data, and records the execution time of the business query statement to obtain a reference execution time.
[0103] In the above steps S410 to S440, database connections are managed through a connection pool so that database connections can be quickly acquired and used when needed, thereby avoiding resource consumption caused by frequent creation and destruction of database connections and improving the efficiency of stress testing.
[0104] See also Figure 5 In some embodiments, step S430 may include but is not limited to steps S510 to S540:
[0105] Step S510, obtaining the link connection status of the original database connection link;
[0106] Step S520, obtaining the storage capacity of the connection pool according to the link connection status;
[0107] Step S530: If the storage capacity is less than the preset capacity threshold, a new link is created to obtain a target database connection link;
[0108] Step S540: If the storage capacity is equal to the preset capacity threshold, the original database connection link is screened according to the link connection status to obtain the target database connection link.
[0109] In step S510 of some embodiments, the connection pool includes at least one original database connection link, where the original database connection link is an existing database connection in the connection pool. The link connection status of the original database connection link is obtained, where the link connection status includes an occupied state or an idle state. If the link connection status is occupied, it indicates that the original database connection link is occupied by the target thread. If the link connection status is idle, it indicates that the original database connection link is not occupied by any target thread. If there is an original database connection link in the connection pool with an idle state, the original database connection link is used as the target database connection link.
[0110] In step S520 of some embodiments, if there is no original database connection link with an idle link connection state in the connection pool, the storage capacity of the connection pool is obtained, where the storage capacity is the number of database connection links in the connection pool.
[0111] In step S530 of some embodiments, the preset capacity threshold is the maximum number of database connections that can be stored in the connection pool. If the storage capacity is less than the preset capacity threshold, indicating that the storage capacity of the connection pool has not reached the upper limit, a new database connection link is created to obtain the target database connection link.
[0112] In step S540 of some embodiments, if the storage capacity is equal to the preset capacity threshold, indicating that the storage capacity of the connection pool has reached the upper limit of the capacity, then when waiting for the link connection state to switch from the occupied state to the idle state, the original database connection link in the idle state is selected as the target database connection link.
[0113] Through the above steps S510 to S540, an available target database connection link can be obtained for use by the target thread to perform the stress test task on the database.
[0114] See also Figure 6 In some embodiments, step S510 may include but is not limited to steps S610 to S620:
[0115] Step S610: In response to the thread start request, start the interference thread and obtain the original database connection link through the interference thread; wherein the original database connection link is in an initial connection state;
[0116] Step S620: Update the initial connection state to obtain the link connection state.
[0117] In step S610 of some embodiments, in a production environment, various abnormal situations may occur in the database, such as network interruption, server failure, etc. The embodiments of the present application simulate these abnormal situations by interfering with threads. In response to a thread start request, the interfering thread is turned on, and the original database connection link is obtained from the connection pool through the interfering thread. The original database connection link has an initial connection state, and the initial connection state is an idle state. If there is no original database connection link in the connection pool that is currently in an idle state, the database connection link occupied by the target thread is forcibly recovered to obtain the original database connection link, and the initial connection state of the original database connection link is set to an idle state, and the original database connection link is obtained through the interfering thread.
[0118] In step S620 of some embodiments, the initial connection state is switched from the idle state to the occupied state to obtain a link connection state.
[0119] Through the above steps S610 to S620, a situation where the database connection is interrupted can be simulated to test the recovery capability of the database in the face of network instability, server failure or other abnormal situations.
[0120] See also Figure 7 In some embodiments, step S520 may include but is not limited to steps S710 to S720:
[0121] Step S710, calculating the link utilization of the connection pool according to the link connection status;
[0122] Step S720: Obtain the storage capacity of the connection pool according to the link utilization.
[0123] In step S710 of some embodiments, the number of original database connection links in the connection pool with an idle state is counted to obtain a first number. The number of original database connection links in the connection pool with an occupied state is counted to obtain a second number. The ratio of the second number to the first number is calculated to obtain a link utilization rate.
[0124] In step S720 of some embodiments, if the link utilization is greater than or equal to the utilization threshold, indicating that most of the database connection links in the connection pool are occupied, the storage capacity of the connection pool is obtained. If the link utilization is less than the utilization threshold, indicating that most of the database connection links in the connection pool are idle, there is no need to obtain the storage capacity of the connection pool. The utilization threshold can be set according to actual conditions, such as 0.8.
[0125] Through the above steps S710 to S720, the storage capacity can be dynamically acquired according to the link utilization, so as to allocate a database connection link to the target thread according to the storage capacity.
[0126] In step S160 of some embodiments, if the reference execution time is less than the thread execution time, the step of executing the business query statement on the simulated business data through the target thread is repeated until the reference execution time is greater than or equal to the thread execution time, completing the stress test of the test database under a certain thread concurrency. If the reference execution time is greater than or equal to the thread execution time, the next thread concurrency and the next thread execution time are obtained to perform a database stress test. While executing the business query statement, the use of the database's processor, memory, disk, I / O and other resources can be detected through the system performance detection tool.
[0127] See also Figure 8 The present application also provides a database stress testing device that can implement the above database stress testing method. The database stress testing device includes:
[0128] The statement parsing module 810 is used to parse the preset test query statement to obtain the statement execution order of the test query statement;
[0129] Reorganization module 820, used to reorganize the test query statement according to the statement execution order to obtain the business query statement;
[0130] The storage module 830 is used to obtain simulated business data and store the simulated business data in a test database;
[0131] An acquisition module 840 is configured to acquire a load pattern according to a business query statement, and acquire thread concurrency and thread execution duration according to the load pattern;
[0132] An execution module 850 is configured to start a target thread based on the thread concurrency, execute a business query statement on the simulated business data through the target thread, and obtain a reference execution time; wherein the reference execution time is the time it takes for the target thread to execute the business query statement;
[0133] The testing module 860 is used to perform a stress test on the test database according to the reference execution time and the thread execution time.
[0134] The specific implementation of the database stress testing device is basically the same as the specific embodiment of the above-mentioned database stress testing method, and will not be repeated here.
[0135] The present application also provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the above-described database stress testing method when executing the computer program. The electronic device can be any smart terminal, such as a tablet computer or an in-vehicle computer.
[0136] See also Figure 9 , Figure 9The hardware structure of an electronic device according to another embodiment is shown. The electronic device includes:
[0137] The processor 910 may be implemented as a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is configured to execute relevant programs to implement the technical solutions provided in the embodiments of the present application.
[0138] The memory 920 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 920 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 920 and is called by the processor 910 to execute the database stress testing method of the embodiments of this application.
[0139] Input / output interface 930, used to implement information input and output;
[0140] Communication interface 940, used to implement communication interaction between this device and other devices, which can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WiFi, Bluetooth, etc.);
[0141] bus 950 , which transmits information between various components of the device (e.g., processor 910 , memory 920 , input / output interface 930 , and communication interface 940 );
[0142] The processor 910 , the memory 920 , the input / output interface 930 , and the communication interface 940 are connected to each other in communication within the device via a bus 950 .
[0143] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned database stress testing method is implemented.
[0144] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0145] The database stress testing method, database stress testing device, electronic device and computer storage medium provided by the embodiments of the present application use business query statements to simulate real business operations of users, and dynamically adjust the load mode according to the business query statements, rather than using a fixed load mode configured by the stress testing tool. This makes the matching between business operations and load modes higher, improves the accuracy of load mode acquisition, and thus improves the accuracy of stress testing.
[0146] The embodiments described in the embodiments of this application are intended to more clearly illustrate the technical solutions of the embodiments of this application and do not constitute a limitation on the technical solutions provided by the embodiments of this application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0147] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0148] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, i.e., they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.
[0149] Those skilled in the art will appreciate that all or some of the steps in the methods, systems, and functional modules / units in the devices disclosed above may be implemented as software, firmware, hardware, or appropriate combinations thereof.
[0150] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0151] It should be understood that in this application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0152] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the above-mentioned units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0153] The units described above as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0154] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0155] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes multiple instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: various media that can store programs, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0156] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but are not intended to limit the scope of the present invention. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and essence of the present invention should be within the scope of the present invention.
Claims
1. A database stress testing method, characterized in that: The method comprises: Parsing the test query statements to obtain the execution order of the test query statements; Reorganize the test query statements according to the statement execution order to obtain business query statements; Acquire simulated business data and store the simulated business data in a test database; Obtaining a load pattern according to the business query statement, and obtaining thread concurrency and thread execution duration according to the load pattern; Starting a target thread according to the thread concurrency, and executing the business query statement on the simulated business data through the target thread to obtain a reference execution time; wherein the reference execution time is the time it takes for the target thread to execute the business query statement; A stress test is performed on the test database according to the reference execution time and the thread execution time.
2. The method according to claim 1, characterized in that The obtaining of thread concurrency and thread execution duration according to the load pattern includes: Obtain thread configuration parameters according to the load pattern; Obtaining a parameter configuration order of the thread configuration parameters; Extracting the thread concurrency and the thread execution duration from the thread configuration parameters according to the parameter configuration order.
3. The method according to claim 1, characterized in that The executing the business query statement on the simulated business data through the target thread to obtain a reference execution time includes: Obtaining the query frequency and query waiting time of the business query statement; Obtaining database connection reuse status based on the query frequency and query waiting time; Obtaining a target database connection link from a connection pool according to the database connection reuse state; The business query statement is executed on the simulated business data through the target thread and the target database connection link to obtain the reference execution duration.
4. The method according to claim 3, characterized in that The connection pool includes an original database connection link, and obtaining a target database connection link from the connection pool according to the database connection reuse state includes: Obtaining the link connection status of the original database connection link; Acquiring a storage capacity of the connection pool according to the link connection state; If the storage capacity is less than a preset capacity threshold, a new link is created to obtain the target database connection link; If the storage capacity is equal to the preset capacity threshold, the original database connection link is screened according to the link connection status to obtain the target database connection link.
5. The method according to claim 4, characterized in that The obtaining of the link connection status of the original database connection link includes: In response to the thread start request, an interference thread is started, and the original database connection link is obtained through the interference thread; wherein the original database connection link has an initial connection state; The initial connection state is updated to obtain the link connection state.
6. The method according to claim 4, characterized in that The acquiring the storage capacity of the connection pool according to the link connection state includes: Calculating the link utilization of the connection pool according to the link connection status; The storage capacity of the connection pool is obtained according to the link utilization.
7. The method according to any one of claims 1 to 6, characterized in that The step of reorganizing the test query statements according to the statement execution order to obtain a business query statement includes: Obtaining the transaction type of the test query statement and the transaction ratio of the transaction type; Filtering the test query statement according to the transaction type and the transaction ratio to obtain a reference query statement; The reference query statements are reorganized according to the statement execution order to obtain the business query statement.
8. A database stress testing device, characterized in that: The device comprises: A statement parsing module is used to parse the preset test query statement to obtain the statement execution order of the test query statement; A reorganization module, configured to reorganize the test query statements according to the statement execution order to obtain business query statements; A storage module is used to obtain simulated business data and store the simulated business data in a test database; An acquisition module, configured to acquire a load pattern according to the business query statement, and acquire thread concurrency and thread execution duration according to the load pattern; An execution module, configured to start a target thread according to the thread concurrency, and execute the business query statement on the simulated business data through the target thread to obtain a reference execution time; wherein the reference execution time is the time it takes for the target thread to execute the business query statement; A testing module is used to perform a stress test on the test database according to the reference execution time and the thread execution time.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Method and system for testing database server
CN121387743A