Database load balancing method, device, electronic device and storage medium

By combining the load statistics information of the database statement and the load information of the database node, the target database node is determined to execute the SQL statement, and the resource overload problem caused by the difference in load characteristics of the SQL statement in the prior art is solved, and the database statement-level load balancing and Performance improvement.

CN119003661BActive Publication Date: 2025-02-18DIGITAL YI TECH (BEIJING) CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411456712.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-18
Publication Date
2025-02-18
Estimated Expiration
2044-10-18

AI Technical Summary

Technical Problem

The existing distributed database load balancing method is mainly carried out at the database instance level, and the load characteristics differences of different SQL statements are not effectively considered, resulting in some SQL statements being balanced on the same node, resulting in resource overload and performance degradation.

Method used

By obtaining the load statistics information of database statements and the load information of each database node, a target database node is determined in multiple database nodes by load balancing to execute specific database statements to achieve database statement-level load balancing.

Benefits of technology

It realizes load balancing at the database statement level, makes full use of the resources of each database node, avoids resource overload of a certain node, and improves the performance of SQL execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003661B_ABST
    Figure CN119003661B_ABST
Patent Text Reader

Abstract

The present application belongs to the field of database technology, and specifically discloses a database load balancing method, device, electronic device and storage medium, the method comprising: obtaining a first database statement; judging whether the database statement load information structure contains load statistics corresponding to the first database statement, the database statement load information structure is used to store the load statistics corresponding to the database statement; if it is determined that the database statement load information structure contains the load statistics corresponding to the first database statement, then based on the load information of each database node and the load statistics corresponding to the first database statement, a target database node is determined in a load balancing manner among multiple database nodes; and the first database statement is sent to the target database node. Through the present application, load balancing at the database statement level can be achieved, and various resources of each database node can be fully utilized, thereby giving full play to the maximum performance of each database node.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of database technology, and more specifically, relates to a database load balancing method, device, electronic device and storage medium. Background Art

[0002] Traditional distributed database load balancing is generally implemented at the driver layer, which is the interface layer between the database node and the application. It is responsible for converting the application's request into a format that the database can understand, and converting the results returned by the database into a format that the application can process. At the same time, the database node provides an SQL interface for querying available database nodes and their load conditions.

[0003] The driver layer is usually executed by the database driver (Database Driver), which is a software layer. The specific workflow of the existing driver layer is as follows: (1) The driver connects to the database node and executes SQL statements to pull database node information, mainly available database node information and its load status; (2) When the application requests a connection, the driver allocates the connection based on the load status of the database node.

[0004] The existing distributed database load balancing solution is based on database instance-level load balancing. However, in practice, the load characteristics generated by different SQL statements vary greatly. For example, the IO cost, operator data volume, and network overhead of OLAP-type SQL statements are relatively large. Traditional load balancing methods do not consider the differences in load characteristics of SQL statements in instances, and may balance SQL statements with the same load characteristics to the same node, resulting in the load limit being reached in advance. For example, SQL statements with high IO costs are balanced to the same node, resulting in the IO of the node reaching its upper limit, and the performance of SQL statement execution will decrease. Summary of the invention

[0005] In view of the defects of the prior art, the purpose of this application is to achieve load balancing at the database statement level.

[0006] To achieve the above objectives, in a first aspect, the present application provides a database load balancing method, the method comprising:

[0007] Get the first database statement (such as SQL statement);

[0008] Determine whether the database statement load information structure stores load statistics corresponding to the first database statement, the database statement load information structure being used to store load statistics corresponding to the database statement;

[0009] If it is determined that the database statement load information structure stores load statistics information corresponding to the first database statement, then determining a target database node from the plurality of database nodes in a load balancing manner based on the load information of each database node and the load statistics information corresponding to the first database statement;

[0010] Send the first database statement to the target database node.

[0011] The database statement payload information structure may be referred to as an SQL payload information structure or an SQL payload information Map.

[0012] By combining the load information of each database node and the load statistics information corresponding to the first database statement, a target database node for executing the first database statement is determined in a load balancing manner, so that load balancing at the database statement level (or SQL level) can be achieved, and various resources of each database node, such as IO resources, storage space resources and network resources, can be fully utilized, so as to give full play to the maximum performance of each database node.

[0013] In a possible implementation, the load statistics corresponding to the database statement include: a first storage space load, a first IO load and a first network load, and correspondingly, the load information of the database node includes: a second storage space load, a second IO load and a second network load.

[0014] The first storage space load is used to represent the consumption of storage space resources of the database node by the database statement during the process of the database node executing the database statement.

[0015] The first IO load is used to represent the consumption of IO resources of the database node by the database statement during the process of the database node executing the database statement.

[0016] The first network load is used to represent the amount of network resource consumption of the database node by the database statement when the database node is executing the database statement.

[0017] The second storage space load is used to represent the overall consumption of storage space resources of the database node.

[0018] The second IO load is used to represent the overall consumption of IO resources of the database node.

[0019] The second network load is used to represent the overall consumption of network resources of the database node.

[0020] In a possible implementation, the method of determining a target database node from among the multiple database nodes in a load balancing manner based on the load information of each database node and the load statistics information corresponding to the first database statement includes:

[0021] Based on the load information of each database node and the load statistics corresponding to the first database statement, select a candidate node from the multiple database nodes, and the remaining resources of the candidate node are greater than the resources consumed by executing the first database statement;

[0022] Based on the load information of each candidate node and the load statistics information corresponding to the first database statement, estimate the load estimation information of each candidate node when executing the first database statement;

[0023] Based on the load estimation information corresponding to each candidate node, a candidate node with the lowest load when executing the first database statement is determined as the target database node.

[0024] Here, the remaining resources of the above-mentioned candidate node are greater than the resources consumed by executing the first database statement, and the remaining resources of the candidate node in terms of storage space, IO and network are greater than the corresponding resources consumed by executing the first database statement. For example, the remaining amount of storage space resources of the candidate node is greater than the storage space resources consumed by executing the first database statement, the remaining amount of IO resources of the candidate node is greater than the IO resources consumed by executing the first database statement, and the remaining amount of network resources of the candidate node is greater than the network resources consumed by executing the first database statement.

[0025] Here, the load estimation information of the above-mentioned estimated candidate nodes when executing the first database statement is exemplified. Based on the load information of the candidate nodes, the load of the candidate nodes in terms of storage space, IO and network can be obtained. Based on the load statistics corresponding to the first database statement, the consumption of storage space resources, IO resources and network resources of the database node by the database statement during the execution of the database statement can be obtained.

[0026] By summing the storage space load of the candidate node and the consumption of storage space resources by the first database statement, the storage space load of the candidate node when executing the first database statement can be estimated to determine the storage space load estimation value.

[0027] By summing the IO load of the candidate node and the consumption of IO resources by the first database statement, the IO load of the candidate node when executing the first database statement can be estimated to determine an IO load estimation value.

[0028] By summing the network load of the candidate node and the consumption of network resources by the first database statement, the network load of the candidate node when executing the first database statement can be estimated to determine the estimated network load value.

[0029] The load estimation information may include storage space load estimation, IO load estimation and network load estimation.

[0030] Here, the above-mentioned determination of an alternative node with the lowest load when executing the first database statement as the target database node is exemplified. Optionally, based on the storage space load estimate, IO load estimate and network load estimate in the load estimate information corresponding to the alternative node, the total load estimate corresponding to the alternative node is obtained, and the total load estimate corresponding to different alternative nodes is compared. Then, the alternative node with the lowest total load estimate among all the alternative nodes can be determined as the target database node.

[0031] Optionally, based on the load priority sorting and the load statistics corresponding to the first database statement, a target class load (storage space load, network load or IO load) is selected from multiple types of loads as an evaluation indicator, and the consumption of the target class resources (storage space resources, network resources or IO resources) by the first database statement is greater than 0, and then the target class load estimate value (storage space load estimate value, IO load estimate value or network load estimate value) in the load estimate information corresponding to the candidate node is compared, and the target class load estimate values ​​corresponding to different candidate nodes are compared, and the candidate node with the lowest target class load estimate value can be determined as the target database node among all candidate nodes. Among them, the load priority sorting is used to indicate the priority sorting between different types of loads, for example, the priority of storage space load>the priority of network load>the priority of IO load.

[0032] Here, the above-mentioned screening out a target class load from multiple types of loads as an evaluation indicator is exemplified. Based on the load statistical information corresponding to the first database statement, the consumption of each type of resource by the first database statement can be determined, and then one or more alternative class loads are screened out. The consumption of the alternative class resources by the first database statement is greater than 0, and then the loads are sorted according to their priority, and the target class load is screened out from all the alternative class loads. The target class load is the one with the highest priority among all the alternative class loads.

[0033] It can be understood that the target database node is an alternative node with the lowest load when executing the first database statement. Sending the first database statement to the target database node can make full use of various idle resources of the target database node, achieve load balancing at the database statement level, and improve the load balancing effect.

[0034] In a possible implementation, the method further includes:

[0035] Traverse each database statement in the database statement list, obtain the load statistics information corresponding to the traversed database statement by accessing the database node, and update the database statement load information structure based on the load statistics information corresponding to the traversed database statement;

[0036] The database node is used to count the resources consumed by executing database statements to obtain load statistics corresponding to the database statements.

[0037] A database statement list may be referred to as an SQL statement list.

[0038] In a possible implementation manner, after determining whether the database statement load information structure stores load statistics information corresponding to the first database statement, the method further includes:

[0039] If it is determined that the database statement load information structure does not store load statistics information corresponding to the first database statement, the first database statement is added to the database statement list.

[0040] In a possible implementation, the method further includes:

[0041] Obtain the load information of the database node by accessing the database node.

[0042] In a possible implementation manner, after determining whether the database statement load information structure stores load statistics information corresponding to the first database statement, the method further includes:

[0043] If it is determined that the database statement load information structure does not store the load statistics information corresponding to the first database statement, then determining whether there is a second database statement in the database statement load information structure, and the second database statement and the first database statement use the same statement template;

[0044] In the case where the second database statement exists in the database statement load information structure, determining a target database node from among the plurality of database nodes in a load balancing manner based on the load information of each database node and the load statistics information corresponding to the second database statement;

[0045] Send the first database statement to the target database node.

[0046] Here, the statement template used by the database statement is explained. The SQL statement is lexically analyzed, and the constant expressions in the SQL statement are taken out and normalized and replaced to generate the statement template. The main steps are column name normalization and parameter value normalization. The generated statement template is the statement template used by the database statement.

[0047] For example, select id from test where id = 10 and select name from test where id = 1000 are both normalized into select from test where test=?, so these two SQL statements use the same statement template.

[0048] In a possible implementation manner, after determining whether the second database statement exists in the database statement load information structure, the method further includes:

[0049] In the case where the second database statement does not exist in the database statement load information structure, based on the load information of each database node, determining a target database node from the plurality of database nodes in a load balancing manner;

[0050] Send the first database statement to the target database node.

[0051] In a second aspect, the present application provides a database load balancing device, comprising:

[0052] A statement acquisition module, used to acquire a first database statement;

[0053] A judgment module, used to judge whether the database statement load information structure stores load statistics information corresponding to the first database statement, the database statement load information structure is used to store load statistics information corresponding to the database statement;

[0054] a determination module, configured to determine a target database node from among the plurality of database nodes in a load balancing manner based on the load information of each database node and the load statistics information corresponding to the first database statement if it is determined that the database statement load information structure stores the load statistics information corresponding to the first database statement;

[0055] The sending module is used to send the first database statement to the target database node.

[0056] In a third aspect, the present application provides an electronic device comprising: at least one memory for storing programs; and at least one processor for executing the programs stored in the memory. When the program stored in the memory is executed, the processor is used to execute the method described in the first aspect or any possible implementation of the first aspect.

[0057] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a processor, the processor executes the method described in the first aspect or any possible implementation of the first aspect.

[0058] It can be understood that the beneficial effects of the second to fourth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here.

[0059] In general, the above technical solutions conceived by this application have the following beneficial effects compared with the prior art:

[0060] By combining the load information of each database node and the load statistics information corresponding to the first database statement, a target database node for executing the first database statement is determined in a load balancing manner, so that load balancing at the database statement level (or SQL level) can be achieved, and various resources of each database node, such as IO resources, storage space resources and network resources, can be fully utilized, so as to give full play to the maximum performance of each database node. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Figure 1 It is a schematic diagram of a flow chart of obtaining load information of a database node provided by the prior art;

[0062] Figure 2 It is a flowchart of database load balancing provided by the prior art;

[0063] Figure 3 It is a flowchart of a database load balancing method provided in an embodiment of the present application;

[0064] Figure 4 It is a schematic diagram of the process of updating database node load information provided by an embodiment of the present application;

[0065] Figure 5 This is a flow chart of obtaining SQL load statistics information provided by an embodiment of the present application;

[0066] Figure 6 This is a flow chart of issuing SQL provided in an embodiment of the present application;

[0067] Figure 7 It is a structural diagram of a database load balancing device provided in an embodiment of the present application;

[0068] Figure 8 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0069] In order to facilitate a clearer understanding of the embodiments of the present application, some relevant background knowledge is first introduced as follows.

[0070] Figure 1 It is a flow chart of obtaining the load information of database nodes provided by the prior art, such as Figure 1As shown, the driver starts the background thread; polls each database node through the background thread; executes SQL statements to pull database node information, mainly available database node information and its load status; stores the node load information in the node load information structure (Map), which is a HashMap, where the key is the identifier of the database node and the value is the load information of the database node.

[0071] Figure 2 It is a flowchart of database load balancing provided by the prior art, such as Figure 2 As shown, when an application requests a connection, the driver obtains the node with the least load from the node load information structure and forwards the SQL statement to the node (the node with the least load).

[0072] For example, a distributed database includes: database node 1, database node 2 and database node 3. When an application requests to obtain a connection, the driver obtains the load of each database node. For example, the load utilization rate of database node 1 is 10%, the load utilization rate of database node 2 is 40%, and the load utilization rate of database node 3 is 60%. The driver sends the SQL statement to database node 1 with the smallest load according to the load of the database node.

[0073] In practice, the load characteristics generated by different SQL statements vary greatly. For example, the three SQL statements shown in Table 1 have significantly different consumption of various resources. If the various loads are not differentiated at the SQL level, it is easy for a certain type of resource to reach a bottleneck in advance, and the performance of SQL statement execution will decrease.

[0074] Table 1 Comparison of resource consumption by different SQL statements

[0075]

[0076] Taking Online Analytical Processing (OLAP) SQL statements as an example, their IO cost, operator data volume, and network overhead are relatively large. Traditional load balancing methods do not consider the differences in SQL load characteristics in instances, and may balance SQL statements with the same load characteristics to the same node, resulting in the load limit being reached in advance. For example, SQL statements with high IO costs are balanced to the same node, causing the IO of the node to reach its upper limit, and the performance of SQL statement execution will decrease.

[0077] In order to overcome the above-mentioned defects, the present application provides a database load balancing method, device, electronic device and storage medium, which can achieve database statement-level load balancing, and can make full use of various resources of each database node, thereby giving full play to the maximum performance of each database node.

[0078] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0079] The terms "first", "second", etc. in the specification and claims herein are used to distinguish different objects rather than to describe a specific order of the objects. For example, a first database statement and a second database statement are used to distinguish different database statements rather than to describe a specific order of the database statements.

[0080] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0081] In the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more than two. For example, multiple processing units refer to two or more processing units, etc.; multiple elements refer to two or more elements, etc.

[0082] First, the technical terms involved in the embodiments of the present application are introduced.

[0083] (1) Database statistics: The database collects information about tables and indexes through sampling and statistics, such as the number of records in a table and the number of clustered index pages. When generating an execution plan, the database needs to make an estimate based on the index statistics and calculate the execution plan with the lowest cost (or minimum overhead).

[0084] (2) Load statistics: This paper proposes a concept in which database nodes count the network, IO, and operator overhead of the SQL statements actually executed, and store these values ​​in the database node's load statistics table.

[0085] (3) SQL: Structured Query Language (SQL) is a special-purpose programming language, a database query and programming language used to access data and query, update and manage relational database systems.

[0086] (4) Load: The resource consumption of the database when executing SQL, mainly including IO, operator off-disk volume, and network.

[0087] (5) Database load balancing: Database load balancing distributes the load generated by the actual SQL execution to multiple nodes for execution, thereby giving full play to the maximum performance of each node.

[0088] (6) IO (input / output) overhead: refers to the resources consumed when performing data reading and writing operations in a computer system. This includes the data transmission time between hardware devices (such as hard disks, memory, network interface cards) and the CPU, as well as the additional computing and scheduling overhead of the operating system when processing this data.

[0089] (7) Operator offload: The intermediate data generated on the disk during the operator operation is called operator offload. For example, the sorting operator wants to use 500M memory for sorting, but in fact only 300M memory is allocated due to memory limitations. In this case, the temporary intermediate data used for sorting needs to be written to the disk. This is the origin of data offload. When intermediate data is offloaded to the disk, it is called operator offload.

[0090] (8) Network overhead: refers to the time and resource consumption required for data transmission in a computer network.

[0091] (9) HashMap is a mapping data structure based on the hashing principle, and has corresponding implementations in programming languages ​​such as Java and C++. It stores key-value pairs and allows fast retrieval. The key is used to uniquely identify data, and the value is the data associated with the key. In HashMap, each key-value pair is calculated using a hash function to obtain a unique hash code, and then the key-value pair is stored in the corresponding location according to the hash code.

[0092] The embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application.

[0093] Figure 3 is a flow chart of a database load balancing method provided in an embodiment of the present application, such as Figure 3 As shown, the method includes the following steps S101 to S104.

[0094] Step S101: Obtain a first database statement (eg, SQL statement).

[0095] Step S102, determining whether the database statement load information structure stores load statistics information corresponding to the first database statement, the database statement load information structure being used to store load statistics information corresponding to the database statement.

[0096] Step S103, if it is determined that the database statement load information structure contains load statistics corresponding to the first database statement, a target database node is determined from multiple database nodes in a load balancing manner based on the load information of each database node and the load statistics corresponding to the first database statement.

[0097] Step S104: sending the first database statement to the target database node.

[0098] It is understandable that the first database statement may be a database statement to be executed, such as an SQL statement to be executed. After the first database statement is obtained, the load statistics corresponding to the first database statement may be searched in the database statement load information structure. If the database statement load information structure contains the load statistics corresponding to the first database statement, the consumption of various resources (such as storage space resources, IO resources, and network resources) of the database node when the first database statement is executed by the database node may be determined. At the same time, the remaining situation of various resources of each database node may be determined according to the load information of each database node (the total amount of a certain type of resource minus the load of the corresponding type can obtain the remaining amount of the resource of the type). Then, the target database node may be determined in a load balancing manner in combination with the load information of each database node and the load statistics corresponding to the first database statement, so as to ensure that after the first database statement is sent to the target database node, the remaining amount of various resources of the target database node can meet the consumption of various resources by the first database statement, and each database node maintains a balanced state in various loads (such as storage space load, IO load, and network load, etc.).

[0099] Therefore, by combining the load information of each database node and the load statistical information corresponding to the first database statement, the target database node for executing the first database statement is determined in a load balancing manner, which can achieve load balancing at the database statement level (or SQL level), and can make full use of various resources of each database node, such as IO resources, storage space resources and network resources, so as to give full play to the maximum performance of each database node and prevent a database node from reaching the upper limit prematurely.

[0100] The database load balancing method provided by the present application is described below with an example. The process of database load balancing is divided into three sub-processes: a sub-process for updating database node load information, a sub-process for obtaining SQL load statistics information, and a sub-process for issuing SQL.

[0101] (1) The sub-process for updating the database node load information: the driver periodically polls the load information of each database node in the background, including IO, network, and operator off-disk capacity.

[0102] Figure 4 is a schematic diagram of a process for updating database node load information provided by an embodiment of the present application, such as Figure 4 As shown, in this process, the driver starts the background thread; the background thread connects to each database node and polls each database node; executes SQL statements to query the load information of the node, such as (storage space load utilization, IO load utilization, network load utilization); stores the load information of the node in the node load information structure, which is a HashMap, in which the key is the identifier of the database node and the value is the load information of the database node.

[0103] For example, assuming that the network resources, storage space resources and IO load resources of each database node remain the same, in this case, the network load utilization rate (the proportion of the network load occupied by the network resources of the database node) can be used to characterize the network load, and the storage space load utilization rate (the proportion of the storage space load occupied by the storage space resources of the database node) can be used to characterize the storage space load; and the IO load utilization rate (the proportion of the IO load occupied by the IO resources of the database node) can be used to characterize the IO load.

[0104] Assume that the distributed database includes: database node 1, database node 2 and database node 3, and the network resources, storage space resources and IO load resources of each database node remain the same. In this case, the node load information structure (Map) is shown in Table 2.

[0105] Table 2 Data table of node load information structure

[0106]

[0107] (2) The sub-process for obtaining SQL load statistics is as follows: the driver program counts the executed SQL and periodically queries each node of the database for the SQL load statistics in the background to obtain information such as IO, network, and operator off-disk volume.

[0108] Figure 5 is a flow chart of obtaining SQL load statistics information provided by an embodiment of the present application, such as Figure 5 As shown, in this process, the driver starts the background SQL load update thread; the background thread traverses the SQL statements in the SQL statement list, connects to the database node, and queries the load statistics information (storage space load usage, IO load usage, network load usage) corresponding to the SQL from the load statistics table of the database node; the SQL and the load statistics information are stored in the SQL load information structure, which is a HashMap, in which the key is the SQL statement and the value is the load statistics information.

[0109] like Figure 5 As shown, the driver can also record the SQL statements sent by the application and add the SQL statements to the SQL statement list.

[0110] Assume that the network resources, storage space resources, and IO load resources of each database node remain the same. In this case, the SQL load information structure (Map) is shown in Table 3.

[0111] Table 3 SQL load information structure data table

[0112]

[0113] (3) The sub-process of sending SQL. When executing SQL, the driver decides which node to send it to based on the load statistics of the SQL and the load information of the node.

[0114] Figure 6 This is a flow chart of issuing SQL provided in the embodiment of the present application, such as Figure 6 As shown, in this process, the application calls the driver to execute the SQL statement; the driver queries the load statistics information corresponding to the SQL statement from the SQL load information MAP according to the SQL statement; if the SQL statement is not found, it indicates that the SQL statement is executed for the first time. At this time, the node with the smallest load utilization rate can be found according to the node load as the node (execution node) for executing the SQL statement, that is, the above-mentioned target database node; if the SQL statement is found, the execution node is calculated according to the node load and the load statistics information corresponding to the SQL statement; and the SQL statement is sent to the execution node.

[0115] For example, according to Table 2 and Table 3, the SQL statement "select count( ) from customer joinorders where order.customer_id = customer_id", because the operator consumes a lot of storage space, and the storage space in database node 3 has been consumed by 90%, database node 1 and database node 2 are selected first. Because this SQL has obvious IO consumption and the IO consumption of database node 2 has been 50%, this SQL is sent to database node 1.

[0116] The database load balancing device provided by the present application is described below. The database load balancing device described below and the database load balancing method described above can be referenced to each other.

[0117] Figure 7 is a schematic diagram of the structure of a database load balancing device provided in an embodiment of the present application. Figure 7As shown, the device includes: a statement acquisition module 10, a judgment module 20, a determination module 30 and a sending module 40. Among them:

[0118] A statement acquisition module 10, used to acquire a first database statement;

[0119] A determination module 20, used to determine whether the database statement load information structure stores load statistics information corresponding to the first database statement, the database statement load information structure being used to store load statistics information corresponding to the database statement;

[0120] A determination module 30, configured to determine a target database node from among the plurality of database nodes in a load balancing manner based on the load information of each database node and the load statistics information corresponding to the first database statement if it is determined that the database statement load information structure stores the load statistics information corresponding to the first database statement;

[0121] The sending module 40 is used to send the first database statement to the target database node.

[0122] It can be understood that the detailed functional implementation of each of the above-mentioned units / modules can be found in the introduction of the aforementioned method embodiment, and will not be repeated here.

[0123] It should be understood that the above-mentioned device is used to execute the method in the above-mentioned embodiment. The implementation principle and technical effect of the corresponding program module in the device are similar to those described in the above-mentioned method. The working process of the device can refer to the corresponding process in the above-mentioned method, which will not be repeated here.

[0124] Based on the method in the above embodiment, an embodiment of the present application provides an electronic device, Figure 8 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 8 As shown, the electronic device may include: a processor (Processor) 810, a communication interface (Communications Interface) 820, a memory (Memory) 830 and a communication bus 840, wherein the processor 810, the communication interface 820, and the memory 830 communicate with each other through the communication bus 840. The processor 810 can call the logic instructions in the memory 830 to execute the method in the above embodiment.

[0125] In addition, the logic instructions in the above-mentioned memory 830 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application.

[0126] Based on the method in the above embodiment, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a processor, the processor executes the method in the above embodiment.

[0127] Based on the method in the above embodiment, an embodiment of the present application provides a computer program product. When the computer program product runs on a processor, the processor executes the method in the above embodiment.

[0128] It is understandable that the processor in the embodiment of the present application may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. The general-purpose processor may be a microprocessor or any conventional processor.

[0129] The method steps in the embodiments of the present application can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.

[0130] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

[0131] It should be understood that the various numerical numbers involved in the embodiments of the present application are only used for the convenience of description and are not used to limit the scope of the embodiments of the present application.

[0132] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present application shall be included in the scope of protection of the present application.

Claims

1. A database load balancing method, characterized in that: include: Get the first database statement; Determine whether a database statement load information structure stores load statistics corresponding to the first database statement, wherein the database statement load information structure is used to store load statistics corresponding to the database statement; If it is determined that the database statement load information structure stores load statistics information corresponding to the first database statement, then determining a target database node from a plurality of database nodes in a load balancing manner based on the load information of each database node and the load statistics information corresponding to the first database statement; Sending the first database statement to the target database node; After determining whether the database statement load information structure stores load statistics information corresponding to the first database statement, the method further includes: If it is determined that the database statement load information structure does not store load statistics information corresponding to the first database statement, then determining whether a second database statement exists in the database statement load information structure, and the second database statement and the first database statement use the same statement template; In the case where the second database statement exists in the database statement load information structure, determining a target database node from among the plurality of database nodes in a load balancing manner based on the load information of each database node and the load statistics information corresponding to the second database statement; The first database statement is sent to the target database node.

2. The database load balancing method according to claim 1, characterized in that: The step of determining a target database node from among the multiple database nodes in a load balancing manner based on the load information of each database node and the load statistics information corresponding to the first database statement includes: Based on the load information of each database node and the load statistics information corresponding to the first database statement, select a candidate node from multiple database nodes, wherein the remaining resources of the candidate node are greater than the resources consumed by executing the first database statement; Based on the load information of each candidate node and the load statistics information corresponding to the first database statement, estimate the load estimation information of each candidate node when executing the first database statement; Based on the load estimation information corresponding to each candidate node, a candidate node with the lowest load when executing the first database statement is determined as the target database node.

3. The database load balancing method according to claim 1, characterized in that: Also includes: Traversing each database statement in the database statement list, for the traversed database statement, obtaining load statistical information corresponding to the traversed database statement by accessing the database node, and updating the database statement load information structure based on the load statistical information corresponding to the traversed database statement; The database node is used to count the resources consumed by executing database statements to obtain load statistics corresponding to the database statements.

4. The database load balancing method according to claim 3, characterized in that: After determining whether the database statement load information structure stores load statistics information corresponding to the first database statement, the method further includes: If it is determined that the database statement load information structure does not store the load statistical information corresponding to the first database statement, the first database statement is added to the database statement list.

5. The database load balancing method according to claim 1, characterized in that: After determining whether the database statement load information structure contains a second database statement, the method further includes: In the case where the second database statement does not exist in the database statement load information structure, determining a target database node from among the plurality of database nodes in a load balancing manner based on the load information of each database node; The first database statement is sent to the target database node.

6. The database load balancing method according to any one of claims 1 to 5, characterized in that: The load statistics corresponding to the database statement include: a first storage space load, a first IO load and a first network load. Correspondingly, the load information of the database node includes: a second storage space load, a second IO load and a second network load.

7. A database load balancing device, characterized in that: include: A statement acquisition module, used to acquire a first database statement; A judgment module, used to judge whether a database statement load information structure stores load statistics information corresponding to the first database statement, wherein the database statement load information structure is used to store load statistics information corresponding to the database statement; a determination module, configured to determine a target database node from among a plurality of database nodes in a load balancing manner based on the load information of each database node and the load statistics information corresponding to the first database statement if it is determined that the database statement load information structure stores the load statistics information corresponding to the first database statement; A sending module, used for sending the first database statement to the target database node; After determining whether the database statement load information structure stores load statistics information corresponding to the first database statement, the method further includes: If it is determined that the database statement load information structure does not store load statistics information corresponding to the first database statement, then determining whether a second database statement exists in the database statement load information structure, and the second database statement and the first database statement use the same statement template; In the case where the second database statement exists in the database statement load information structure, determining a target database node from among the plurality of database nodes in a load balancing manner based on the load information of each database node and the load statistics information corresponding to the second database statement; The first database statement is sent to the target database node.

8. An electronic device, characterized in that: include: at least one memory for storing a computer program; At least one processor is used to execute the program stored in the memory. When the program stored in the memory is executed, the processor is used to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program runs on a processor, the processor is caused to execute the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • SQL query command processing method, device and equipment and readable storage medium

    CN111190927A

  • Processing method of statistical information of database operation statements, storage medium and equipment

    CN115858627A