CN116775315B - Multi-core CPU concurrent transaction allocation method based on dependency graph - Google Patents
Multi-core CPU concurrent transaction allocation method based on dependency graph Download PDFInfo
- Publication number
- CN116775315B CN116775315B CN202311056907.5A CN202311056907A CN116775315B CN 116775315 B CN116775315 B CN 116775315B CN 202311056907 A CN202311056907 A CN 202311056907A CN 116775315 B CN116775315 B CN 116775315B
- Authority
- CN
- China
- Prior art keywords
- transaction
- dependency
- node
- transactions
- dependency graph
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
- G06F9/5038—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/901—Indexing; Data structures therefor; Storage structures
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Description
技术领域Technical Field
本发明涉及数据库事务分配技术领域,特别是一种基于依赖图的多核CPU并发事务分配方法。The present invention relates to the technical field of database transaction allocation, and in particular to a multi-core CPU concurrent transaction allocation method based on a dependency graph.
背景技术Background Art
近些年来,互联网的高速发展不仅推动了应用规模的快速扩展,还引发了海量数据的涌现,以及对数据库系统在支持大吞吐量的事务处理方面的迫切需求。后台数据库系统面临着应对日益增长的数据量和并发请求的挑战,在这个背景下,数据库系统作为关键的数据管理和事务处理平台,得到了进一步的优化和发展。事务处理是数据库系统最为关键的特性之一,它涉及处理并发的事务请求,其中多核CPU并发事务分配成为提高系统性能的重要环节。数据库中多核CPU并发事务分配方法的目标是通过合理调度并发事务,使得系统性能得到最大化。In recent years, the rapid development of the Internet has not only promoted the rapid expansion of application scale, but also triggered the emergence of massive data and the urgent need for database systems to support high-throughput transaction processing. Backend database systems are facing the challenge of coping with the growing amount of data and concurrent requests. In this context, database systems, as key data management and transaction processing platforms, have been further optimized and developed. Transaction processing is one of the most critical features of database systems. It involves processing concurrent transaction requests, among which multi-core CPU concurrent transaction allocation has become an important part of improving system performance. The goal of the multi-core CPU concurrent transaction allocation method in the database is to maximize system performance by reasonably scheduling concurrent transactions.
为了应对多核处理器带来的挑战,目前存在多种技术用于多核CPU事务调度,如优先级调度算法、时间片轮转调度算法、多级反馈队列调度算法等。如优先级调度方法,根据事务的优先级来决定事务的调度顺序,当一个高优先级的事务因为某些原因被阻塞或等待,可能会导致资源分配不均,造成低优先级事务的饥饿现象;时间片轮转调度算法,每个事务被分配一个时间片,当时间片用完后,事务会被暂停,放到就绪队列的末尾等待下一轮调度,可能导致资源利用率不高和事务切换开销增加;多级反馈队列调度算法:综合多个队列的调度算法,每个队列有不同的优先级和时间片大小,多级队列调度算法可能导致事务切换的开销增加,特别是当事务的数量很多时,事务切换的开销可能会变得显著。In order to cope with the challenges brought by multi-core processors, there are currently a variety of technologies for multi-core CPU transaction scheduling, such as priority scheduling algorithm, time slice round-robin scheduling algorithm, multi-level feedback queue scheduling algorithm, etc. For example, the priority scheduling method determines the scheduling order of transactions according to the priority of the transaction. When a high-priority transaction is blocked or waiting for some reason, it may lead to uneven resource allocation and cause starvation of low-priority transactions; the time slice round-robin scheduling algorithm, each transaction is assigned a time slice. When the time slice is used up, the transaction will be suspended and placed at the end of the ready queue waiting for the next round of scheduling, which may lead to low resource utilization and increased transaction switching overhead; multi-level feedback queue scheduling algorithm: a scheduling algorithm that integrates multiple queues, each queue has different priorities and time slice sizes, and the multi-level queue scheduling algorithm may lead to increased transaction switching overhead, especially when the number of transactions is large, the transaction switching overhead may become significant.
因此,亟需一种基于依赖图的多核CPU并发事务分配方法,用于解决上述技术问题。Therefore, there is an urgent need for a multi-core CPU concurrent transaction allocation method based on a dependency graph to solve the above technical problems.
发明内容Summary of the invention
本发明提供一种基于依赖图的多核CPU并发事务分配方法,用于解决现有技术中,数据库资源利用率不高和事务切换开销较大的技术问题。具体技术方案如下:The present invention provides a multi-core CPU concurrent transaction allocation method based on a dependency graph, which is used to solve the technical problems of low database resource utilization and high transaction switching overhead in the prior art. The specific technical solution is as follows:
第一方面,本发明提供一种基于依赖图的多核CPU并发事务分配方法,所述方法包括:In a first aspect, the present invention provides a multi-core CPU concurrent transaction allocation method based on a dependency graph, the method comprising:
基于数据库中事务之间的执行关联性构建依赖图,所述数据库中的每个事务作为图中的一个节点,事务之间的依赖关系形成图中的有向边;Building a dependency graph based on the execution association between transactions in the database, wherein each transaction in the database serves as a node in the graph, and the dependency relationships between transactions form directed edges in the graph;
基于所述依赖图相邻两节点之间的依赖关系确定所述相邻两节点对应的边的信息素量;Determine the pheromone amount of the edge corresponding to the two adjacent nodes based on the dependency relationship between the two adjacent nodes in the dependency graph;
基于所述依赖图各个节点对应事务的事务度量属性确定各个节点的启发式信息;Determining heuristic information of each node based on a transaction metric attribute of a transaction corresponding to each node of the dependency graph;
基于所述信息素量和所述启发式信息,通过蚁群的行为模型和依赖图中执行所述数据库中的事务,并根据执行结果更新所述依赖图上各个边的信息素量。Based on the pheromone quantity and the heuristic information, the transaction in the database is executed through the behavior model of the ant colony and the dependency graph, and the pheromone quantity of each edge on the dependency graph is updated according to the execution result.
进一步的,所述基于数据库中事务之间的执行关联性构建依赖图,包括:Furthermore, the step of constructing a dependency graph based on the execution association between transactions in the database includes:
基于所述数据库中的每个事务建立一个对应的节点;Establishing a corresponding node based on each transaction in the database;
基于每个所述节点对应的事务之间的数据流动关系、时间戳信息、价值信息、提交顺序,确定各个节点之间的边,所述边用于表示各个节点之间的关联性。Based on the data flow relationship, timestamp information, value information, and submission order between the transactions corresponding to each of the nodes, the edges between the nodes are determined, and the edges are used to represent the association between the nodes.
进一步的,所述基于每个所述节点对应的事务之间的数据流动关系、时间戳信息、价值信息、提交顺序,确定各个节点之间的边,具体为:Furthermore, based on the data flow relationship, timestamp information, value information, and submission order between the transactions corresponding to each node, the edges between the nodes are determined, specifically:
通过记录数据来源、数据去向和版本信息标记对应节点之间的数据依赖关系R1:The data dependency relationship R1 between corresponding nodes is marked by recording data source, data destination and version information:
通过记录事务或数据的时间戳信息标记对应节点之间的控制依赖关系R2:The control dependency relationship R2 between corresponding nodes is marked by recording the timestamp information of transactions or data:
通过记录事务价值信息标记对应节点之间的事务优先级依赖关系R3:By recording the transaction value information, the transaction priority dependency R3 between the corresponding nodes is marked:
通过记录事务提交顺序标记对应节点之间的并行执行关系R4。The parallel execution relationship R4 between corresponding nodes is marked by recording the transaction submission order.
进一步的,所述基于所述依赖图相邻两节点之间的依赖关系确定所述相邻两节点对应的边的信息素量,包括:Furthermore, the step of determining the pheromone amount of the edge corresponding to two adjacent nodes based on the dependency relationship between the two adjacent nodes in the dependency graph includes:
确定数据依赖关系R1对应的数据权重D1、控制依赖关系R2对应的控制权重D2、事务优先级依赖关系R3对应的优先权重D3、并行执行关系R4对应的并行权重D4;Determine the data weight D1 corresponding to the data dependency R1, the control weight D2 corresponding to the control dependency R2, the priority weight D3 corresponding to the transaction priority dependency R3, and the parallel weight D4 corresponding to the parallel execution relationship R4;
基于初始信息素量、信息素蒸发系数、所述相邻两节点之间的依赖关系和各个所述依赖关系对应的权重,确定所述相邻两节点对应的边的信息素量。Based on the initial pheromone quantity, the pheromone evaporation coefficient, the dependency relationship between the two adjacent nodes and the weight corresponding to each of the dependency relationships, the pheromone quantity of the edge corresponding to the two adjacent nodes is determined.
进一步的,所述基于所述依赖图各个节点对应事务的事务属性确定各个节点的启发式信息,包括:Furthermore, the determining of the heuristic information of each node based on the transaction attribute of the transaction corresponding to each node of the dependency graph includes:
确定所述事务属性中各个属性对应的属性启发式信息;Determine attribute heuristic information corresponding to each attribute in the transaction attribute;
确定所述各个属性启发式信息对应的权重;Determine the weight corresponding to each attribute heuristic information;
基于所述各个属性启发式信息和所述权重确定所述事务的启发式信息;Determining heuristic information of the transaction based on the respective attribute heuristic information and the weight;
基于所述事务的启发式信息、所述各个属性启发式信息的最大值和最小值确定启发式信息映射值,所述启发式信息映射值作为相邻节点之间的启发式信息。A heuristic information mapping value is determined based on the heuristic information of the transaction and the maximum and minimum values of the heuristic information of each attribute, and the heuristic information mapping value is used as the heuristic information between adjacent nodes.
进一步的,所述各个节点对应的事务属性包括:节点事务资源利用率、节点事务执行时间、节点事务优先级、节点事务等待时间。Furthermore, the transaction attributes corresponding to each node include: node transaction resource utilization, node transaction execution time, node transaction priority, and node transaction waiting time.
进一步的,所述基于蚁群的行为模型按照所述依赖图执行所述数据库中的事务,并更新所述依赖图上各个边上的信息素,具体为:Furthermore, the ant colony-based behavior model executes the transactions in the database according to the dependency graph and updates the pheromone on each edge of the dependency graph, specifically:
基于所述依赖图中的各个节点的启发式信息和各个边的信息素量,模拟蚁群并发执行数据库中的事务;Based on the heuristic information of each node in the dependency graph and the pheromone amount of each edge, simulating an ant colony to concurrently execute transactions in the database;
基于执行事务的完成质量更新所述执行事务对应的边的信息素量。The pheromone amount of the edge corresponding to the executed transaction is updated based on the completion quality of the executed transaction.
进一步的,所述基于执行事务的完成质量更新所述执行事务对应的边的信息素量,所采用的公式为:Furthermore, the pheromone quantity of the edge corresponding to the executed transaction is updated based on the completion quality of the executed transaction, and the formula adopted is:
是信息素的蒸发速率,用于控制信息素的挥发和降低信息素量; It is the evaporation rate of pheromones, which is used to control the volatilization of pheromones and reduce the amount of pheromones;
是蚂蚁k通过边(i, j)的信息素增量,所述信息素增量与蚂蚁k的调度方案质量有关。 is the pheromone increment of ant k through edge (i, j), and the pheromone increment is related to the quality of ant k's scheduling plan.
第二方面,本发明还提供一种基于依赖图的多核CPU并发事务分配系统,所述系统包括:依赖图模块、信息素量模块、启发式信息模块、更新模块;In a second aspect, the present invention further provides a multi-core CPU concurrent transaction allocation system based on a dependency graph, the system comprising: a dependency graph module, a pheromone quantity module, a heuristic information module, and an update module;
所述依赖图模块用于,基于数据库中事务之间的执行关联性构建依赖图,所述数据库中的每个事务作为图中的一个节点,事务之间的依赖关系形成图中的有向边;The dependency graph module is used to construct a dependency graph based on the execution association between transactions in the database, wherein each transaction in the database serves as a node in the graph, and the dependency relationships between transactions form directed edges in the graph;
所述信息素量模块用于,基于所述依赖图相邻两节点之间的依赖关系确定所述相邻两节点对应的边的信息素量;The pheromone quantity module is used to determine the pheromone quantity of the edge corresponding to the two adjacent nodes based on the dependency relationship between the two adjacent nodes in the dependency graph;
所述启发式信息模块用于,基于所述依赖图各个节点对应事务的事务属性确定各个节点的启发式信息;The heuristic information module is used to determine the heuristic information of each node based on the transaction attributes of the transaction corresponding to each node of the dependency graph;
所述更新模块用于,基于所述信息素量和所述启发式信息,通过蚁群的行为模型和依赖图中执行所述数据库中的事务,并根据执行结果更新所述依赖图上各个边的信息素量。The updating module is used to execute the transaction in the database through the behavior model of the ant colony and the dependency graph based on the pheromone quantity and the heuristic information, and to update the pheromone quantity of each edge on the dependency graph according to the execution result.
第三方面,本发明还提供一种数据库,所述数据库中设置有存储器和处理器,所述存储器用于存储计算机程序,所述处理器用于调用所述存储器内的计算机程序以执行如下步骤:In a third aspect, the present invention further provides a database, wherein the database is provided with a memory and a processor, the memory is used to store a computer program, and the processor is used to call the computer program in the memory to perform the following steps:
基于数据库中事务之间的执行关联性构建依赖图,所述数据库中的每个事务作为图中的一个节点,事务之间的依赖关系形成图中的有向边;Building a dependency graph based on the execution association between transactions in the database, wherein each transaction in the database serves as a node in the graph, and the dependency relationships between transactions form directed edges in the graph;
基于所述依赖图相邻两节点之间的依赖关系确定所述相邻两节点对应的边的信息素量;Determine the pheromone amount of the edge corresponding to the two adjacent nodes based on the dependency relationship between the two adjacent nodes in the dependency graph;
基于所述依赖图各个节点对应事务的事务属性确定各个节点的启发式信息;Determine heuristic information of each node based on the transaction attributes of the transaction corresponding to each node of the dependency graph;
基于所述信息素量和所述启发式信息,通过蚁群的行为模型和依赖图中执行所述数据库中的事务,并根据执行结果更新所述依赖图上各个边的信息素量。Based on the pheromone quantity and the heuristic information, the transaction in the database is executed through the behavior model of the ant colony and the dependency graph, and the pheromone quantity of each edge on the dependency graph is updated according to the execution result.
发明效果:Effect of the invention:
对于本方法所解决的问题,首次针对多核CPU并发事务分配调度进行依赖图构建。在数据库系统应用中,多核CPU可以同时执行多个事务,这种并发处理能力可以更好地支持数据库系统在多用户访问时的需求,在高并发的情况下提高数据库的吞吐量和响应时间,本方法基于所构建的依赖图解决数据库中多核CPU并发事务调度分配问题,更有效地利用多核CPU的优势,提高并发处理能力,在事务灵活性、可靠性、资源利用率等方面均有突破。For the problem solved by this method, a dependency graph is constructed for the first time for the allocation and scheduling of concurrent transactions on multi-core CPUs. In database system applications, multi-core CPUs can execute multiple transactions at the same time. This concurrent processing capability can better support the needs of database systems when accessed by multiple users, and improve the throughput and response time of the database under high concurrency. This method solves the problem of scheduling and allocating concurrent transactions on multi-core CPUs in the database based on the constructed dependency graph, more effectively utilizes the advantages of multi-core CPUs, improves concurrent processing capabilities, and has breakthroughs in transaction flexibility, reliability, resource utilization, etc.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1是本发明一种基于依赖图的多核CPU并发事务分配方法的流程图;FIG1 is a flow chart of a multi-core CPU concurrent transaction allocation method based on a dependency graph according to the present invention;
图2是本发明一种基于依赖图的多核CPU并发事务分配方法的基于依赖关系的DAG依赖图;FIG2 is a DAG dependency graph based on dependency relationships of a multi-core CPU concurrent transaction allocation method based on a dependency graph according to the present invention;
图3是本发明一种基于依赖图的多核CPU并发事务分配方法的架构关系图。FIG3 is an architectural relationship diagram of a multi-core CPU concurrent transaction allocation method based on a dependency graph according to the present invention.
具体实施方式DETAILED DESCRIPTION
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整的描述。显然,所描述的实施例,仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
具体实施例1:Specific embodiment 1:
本发明提供一种基于依赖图的多核CPU并发事务分配方法,用于解决现有技术中,数据库资源利用率不高和事务切换开销较大的技术问题。具体技术方案如下:The present invention provides a multi-core CPU concurrent transaction allocation method based on a dependency graph, which is used to solve the technical problems of low database resource utilization and high transaction switching overhead in the prior art. The specific technical solution is as follows:
第一方面,本发明提供一种基于依赖图的多核CPU并发事务分配方法,所述方法包括:基于数据库中事务之间的执行关联性构建依赖图,所述数据库中的每个事务作为图中的一个节点,事务之间的依赖关系形成图中的有向边;基于所述依赖图相邻两节点之间的依赖关系确定所述相邻两节点对应的边的信息素量;基于所述依赖图各个节点对应事务的事务度量属性确定各个节点的启发式信息;基于所述信息素量和所述启发式信息,通过蚁群的行为模型和依赖图中执行所述数据库中的事务,并根据执行结果更新所述依赖图上各个边的信息素量。In the first aspect, the present invention provides a multi-core CPU concurrent transaction allocation method based on a dependency graph, the method comprising: constructing a dependency graph based on the execution correlation between transactions in a database, wherein each transaction in the database serves as a node in the graph, and the dependency relationship between transactions forms a directed edge in the graph; determining the pheromone amount of the edge corresponding to two adjacent nodes based on the dependency relationship between the two adjacent nodes in the dependency graph; determining the heuristic information of each node based on the transaction metric attributes of the transaction corresponding to each node in the dependency graph; executing the transactions in the database through the behavior model of an ant colony and the dependency graph based on the pheromone amount and the heuristic information, and updating the pheromone amount of each edge on the dependency graph according to the execution result.
本实施例中,在系统中,事务被识别并构建成依赖图。每个事务作为图中的一个节点,事务之间的依赖关系形成图中的有向边。依赖边可以是数据依赖,即一个事务的执行依赖于另一个事务的输出数据,也可以是控制依赖,即一个事务的执行受到另一个事务执行的影响,或其它依赖。事务之间的执行关联性也包括数据关联、控制关联等。事务度量属性包括节点事务资源利用率、节点事务执行时间、节点事务优先级、节点事务等待时间等属性。依赖图用于表示事务之间的依赖关系,而蚁群算法用来模拟事务的调度行为,蚂蚁所走的路径图并不是指依赖图,而是指蚁群算法中蚂蚁群体在搜索空间中选择路径的过程。In this embodiment, in the system, transactions are identified and constructed into a dependency graph. Each transaction is a node in the graph, and the dependencies between transactions form directed edges in the graph. The dependency edge can be a data dependency, that is, the execution of one transaction depends on the output data of another transaction, or a control dependency, that is, the execution of one transaction is affected by the execution of another transaction, or other dependencies. The execution association between transactions also includes data association, control association, etc. Transaction measurement attributes include node transaction resource utilization, node transaction execution time, node transaction priority, node transaction waiting time and other attributes. The dependency graph is used to represent the dependency relationship between transactions, and the ant colony algorithm is used to simulate the scheduling behavior of transactions. The path graph taken by ants does not refer to the dependency graph, but to the process of ant colonies selecting paths in the search space in the ant colony algorithm.
进一步的,所述基于数据库中事务之间的执行关联性构建依赖图,包括:基于所述数据库中的每个事务建立一个对应的节点;基于每个所述节点对应的事务之间的数据流动关系、时间戳信息、价值信息、提交顺序,确定各个节点之间的边,所述边用于表示各个节点之间的关联性。Furthermore, the construction of a dependency graph based on the execution correlation between transactions in the database includes: establishing a corresponding node based on each transaction in the database; determining the edges between the nodes based on the data flow relationship, timestamp information, value information, and submission order between the transactions corresponding to each of the nodes, wherein the edges are used to represent the correlation between the nodes.
进一步的,所述基于每个所述节点对应的事务之间的数据流动关系、时间戳信息、价值信息、提交顺序,确定各个节点之间的边,具体为:通过记录数据来源、数据去向和版本信息标记对应节点之间的数据依赖关系R1:通过记录事务或数据的时间戳信息标记对应节点之间的控制依赖关系R2:通过记录事务价值信息标记对应节点之间的事务优先级依赖关系R3:通过记录事务提交顺序标记对应节点之间的并行执行关系R4。Furthermore, based on the data flow relationship, timestamp information, value information, and submission order between the transactions corresponding to each of the nodes, the edges between the nodes are determined, specifically: the data dependency relationship R1 between the corresponding nodes is marked by recording the data source, data destination, and version information; the control dependency relationship R2 between the corresponding nodes is marked by recording the timestamp information of the transaction or data; the transaction priority dependency R3 between the corresponding nodes is marked by recording the transaction value information; and the parallel execution relationship R4 between the corresponding nodes is marked by recording the transaction submission order.
进一步的,所述基于所述依赖图相邻两节点之间的依赖关系确定所述相邻两节点对应的边的信息素量,包括:确定数据依赖关系R1对应的数据权重D1、控制依赖关系R2对应的控制权重D2、事务优先级依赖关系R3对应的优先权重D3、并行执行关系R4对应的并行权重D4;基于初始信息素量、信息素蒸发系数、所述相邻两节点之间的依赖关系和各个所述依赖关系对应的权重,确定所述相邻两节点对应的边的信息素量。Furthermore, the method of determining the pheromone amount of the edge corresponding to two adjacent nodes based on the dependency relationship between the two adjacent nodes in the dependency graph includes: determining the data weight D1 corresponding to the data dependency R1, the control weight D2 corresponding to the control dependency R2, the priority weight D3 corresponding to the transaction priority dependency R3, and the parallel weight D4 corresponding to the parallel execution relationship R4; and determining the pheromone amount of the edge corresponding to the two adjacent nodes based on the initial pheromone amount, the pheromone evaporation coefficient, the dependency relationship between the two adjacent nodes and the weights corresponding to each of the dependency relationships.
进一步的,所述基于所述依赖图各个节点对应事务的事务属性确定各个节点的启发式信息,包括:确定所述事务属性中各个属性对应的属性启发式信息;确定所述各个属性启发式信息对应的权重;基于所述各个属性启发式信息和所述权重确定所述事务的启发式信息;基于所述事务的启发式信息、所述各个属性启发式信息的最大值和最小值确定启发式信息映射值,所述启发式信息映射值作为所述相邻节点之间的启发式信息。Furthermore, the heuristic information of each node is determined based on the transaction attributes of the transactions corresponding to each node of the dependency graph, including: determining the attribute heuristic information corresponding to each attribute in the transaction attributes; determining the weight corresponding to each attribute heuristic information; determining the heuristic information of the transaction based on each attribute heuristic information and the weight; determining the heuristic information mapping value based on the heuristic information of the transaction and the maximum and minimum values of each attribute heuristic information, and the heuristic information mapping value is used as the heuristic information between the adjacent nodes.
进一步的,所述各个节点对应的事务属性包括:节点事务资源利用率、节点事务执行时间、节点事务优先级、节点事务等待时间。Furthermore, the transaction attributes corresponding to each node include: node transaction resource utilization, node transaction execution time, node transaction priority, and node transaction waiting time.
进一步的,所述基于蚁群的行为模型按照所述依赖图执行所述数据库中的事务,并更新所述依赖图上各个边上的信息素,具体为:基于所述依赖图中的各个节点的启发式信息和各个边的信息素量,模拟蚁群并发执行数据库中的事务;基于执行事务的完成质量更新所述执行事务对应的边的信息素量。Furthermore, the ant colony-based behavior model executes transactions in the database according to the dependency graph and updates the pheromones on each edge of the dependency graph. Specifically, based on the heuristic information of each node in the dependency graph and the pheromone quantity of each edge, the ant colony is simulated to concurrently execute transactions in the database; based on the completion quality of the executed transactions, the pheromone quantity of the edge corresponding to the executed transaction is updated.
进一步的,所述基于执行事务的完成质量更新所述执行事务对应的边的信息素量,所采用的公式为:Furthermore, the pheromone quantity of the edge corresponding to the executed transaction is updated based on the completion quality of the executed transaction, and the formula adopted is:
是信息素的蒸发速率,用于控制信息素的挥发和降低信息素量;是蚂蚁k通过边(i, j)的信息素增量,所述信息素增量与蚂蚁k的调度方案质量有关。 It is the evaporation rate of pheromones, which is used to control the volatilization of pheromones and reduce the amount of pheromones; is the pheromone increment of ant k through edge (i, j), and the pheromone increment is related to the quality of ant k's scheduling plan.
具体实施例2:Specific embodiment 2:
基于依赖图的多核CPU并发事务分配方法旨在最大程度地提高数据并发性和数据库系统性能,通过识别和解决事务之间的依赖关系来合理安排调度。这样的方法有助于避免数据库事务之间的资源竞争、减少了上下文切换,并尽可能地将核心的计算资源用于有效的并行计算。以下是一种基于依赖图的多核CPU并发事务分配方法的具体实施例:The multi-core CPU concurrent transaction allocation method based on dependency graph aims to maximize data concurrency and database system performance by identifying and resolving dependencies between transactions to arrange scheduling reasonably. Such a method helps to avoid resource competition between database transactions, reduce context switching, and use core computing resources for effective parallel computing as much as possible. The following is a specific embodiment of a multi-core CPU concurrent transaction allocation method based on dependency graph:
第一步、依赖图的构建:The first step is to build a dependency graph:
在系统中,事务被识别并构建成依赖图。每个事务作为图中的一个节点,事务之间的依赖关系形成图中的有向边(以下称为依赖边、有向边或边)。依赖边连接事务节点,表示事务之间的依赖关系。依赖边可以是数据依赖,即一个事务的执行依赖于另一个事务的输出数据,也可以是控制依赖,即一个事务的执行受到另一个事务执行的影响,或其它依赖。In the system, transactions are identified and constructed into a dependency graph. Each transaction is a node in the graph, and the dependencies between transactions form directed edges in the graph (hereinafter referred to as dependency edges, directed edges or edges). Dependency edges connect transaction nodes and represent the dependencies between transactions. Dependency edges can be data dependencies, that is, the execution of one transaction depends on the output data of another transaction, or control dependencies, that is, the execution of one transaction is affected by the execution of another transaction, or other dependencies.
建立依赖图:首先,将多核CPU的事务表示成一个有向无环图(DAG)。Building a dependency graph: First, the transactions of multi-core CPUs are represented as a directed acyclic graph (DAG).
它是由一组顶点和有向边组成的图,其中每条边都有一个方向,且不存在形成环的路径。也就是说,在DAG中,从任意一个顶点出发沿着有向边的方向最终不能回到起点,不会形成回路或环路,同时避免事务死锁或循环依赖。It is a graph consisting of a set of vertices and directed edges, where each edge has a direction and there is no path that forms a loop. In other words, in a DAG, starting from any vertex and following the direction of the directed edge, you cannot eventually return to the starting point, and will not form a loop or cycle, while avoiding transaction deadlock or circular dependency.
1、通过记录数据来源和数据去向及版本等信息标记数据依赖关系R1:1. Mark the data dependency R1 by recording the data source, data destination, version and other information:
(1)读写依赖关系(Read-Write Dependencies):如果一个事务读取了另一个事务写入的数据,就存在读写依赖关系。这种依赖关系需要特别考虑,以保证数据的一致性。(1) Read-Write Dependencies: If one transaction reads data written by another transaction, a read-write dependency exists. This dependency requires special consideration to ensure data consistency.
(2)写写依赖关系(Write-Write Dependencies):如果两个事务都写入了相同的数据项,就存在写写依赖关系。这可能导致数据冲突和竞争条件,需要合理地调度事务的执行顺序。(2) Write-Write Dependencies: If two transactions write the same data item, there is a write-write dependency. This may lead to data conflicts and race conditions, and the execution order of transactions needs to be properly scheduled.
(3)读读依赖关系(Read-Read Dependencies):如果两个事务都读取入了相同的数据项,就存在读读依赖关系。(3) Read-Read Dependencies: If two transactions read the same data item, a read-read dependency exists.
2、通过记录事务或数据的时间戳信息标记控制依赖关系R2:2. Control dependency R2 by recording the timestamp information of transactions or data:
(4)控制流依赖:一个事务的执行顺序受到另一个事务执行顺序的影响。例如,一个事务的执行分支取决于另一个事务的执行结果,或者一个事务在另一个事务执行之前必须等待。(4) Control flow dependency: The execution order of one transaction is affected by the execution order of another transaction. For example, the execution branch of one transaction depends on the execution result of another transaction, or one transaction must wait before another transaction executes.
(5)等待依赖:一个事务在执行过程中等待另一个事务的完成,以便继续执行。例如,一个事务需要等待另一个事务的锁释放才能继续执行。(5) Waiting dependency: A transaction waits for another transaction to complete before it can continue to execute. For example, a transaction needs to wait for the lock of another transaction to be released before it can continue to execute.
(6)先趋依赖:一个事务的执行必须在另一个事务之前发生。例如,一个事务是另一个事务的前驱事务,必须先完成才能执行后续的事务。(6) Predecessor dependency: The execution of one transaction must occur before another transaction. For example, one transaction is the predecessor of another transaction and must be completed before the subsequent transaction can be executed.
3、通过记录事务价值信息标记事务优先级依赖关系R3:3. Mark the transaction priority dependency R3 by recording the transaction value information:
(7)优先级标记:在数据库系统中,可以为事务设置不同的优先级标记,优先级高的事务会被优先调度执行。(7) Priority tag: In a database system, different priority tags can be set for transactions, and transactions with higher priorities will be scheduled for execution first.
4、通过记录事务提交顺序可以标记并行执行关系R4:4. By recording the transaction submission order, the parallel execution relationship R4 can be marked:
(8)并行执行关系:两个事务可以同时执行,并且彼此之间没有依赖关系。在有向图中,可以通过添加没有有向边连接的独立事务节点来表示。(8) Parallel execution relationship: Two transactions can be executed simultaneously and have no dependency on each other. In a directed graph, this can be represented by adding independent transaction nodes without directed edges.
第二步、依赖图分析:Step 2: Dependency graph analysis:
分析依赖图,利用事务之间的有向边确定事务之间的依赖关系。Analyze the dependency graph and use the directed edges between transactions to determine the dependencies between transactions.
(1)依赖图表示:首先,将数据库中的事务表示为依赖图的节点。每个事务可以是一个节点,或者如果一个事务被拆分为多个子任务,则每个子任务也可以是一个节点。事务之间的依赖关系用边来表示。(1) Dependency graph representation: First, the transactions in the database are represented as nodes of the dependency graph. Each transaction can be a node, or if a transaction is split into multiple subtasks, each subtask can also be a node. The dependency relationship between transactions is represented by edges.
(2)数据依赖分析:分析事务之间的数据依赖关系。数据依赖表示一个任务需要另一个任务的输出数据作为输入数据。在依赖图中,如果节点 A 有一条有向边指向节点 B,那么节点 B 依赖于节点 A,表示任务 B 需要任务 A 的输出数据。通过分析边的指向,可以确定数据依赖关系。(2) Data dependency analysis: Analyze the data dependency between transactions. Data dependency means that one task requires the output data of another task as input data. In the dependency graph, if node A has a directed edge pointing to node B, then node B depends on node A, indicating that task B requires the output data of task A. By analyzing the direction of the edge, the data dependency can be determined.
(3)控制依赖分析:分析任务之间的控制依赖关系。控制依赖表示一个任务的执行受到另一个任务执行的影响。例如,如果任务 A 是任务 B 的前驱任务,那么任务 B 的执行必须在任务 A 执行后才能开始。通过分析任务之间的先后关系,可以确定控制依赖关系。(3) Control dependency analysis: Analyze the control dependency relationship between tasks. Control dependency means that the execution of one task is affected by the execution of another task. For example, if task A is the predecessor task of task B, then the execution of task B can only start after the execution of task A. By analyzing the order of tasks, the control dependency relationship can be determined.
(4)优先级分配:根据依赖图的分析结果,为每个任务或节点分配优先级,用于指示任务的执行重要性和实时性要求。(4) Priority assignment: Based on the analysis results of the dependency graph, a priority is assigned to each task or node to indicate the execution importance and real-time requirements of the task.
(5)并行执行可能性分析:根据事务之间的依赖关系,确定是否有可能并行执行一些事务。如果两个事务之间不存在数据依赖和控制依赖,那么它们可以在多核CPU上并行执行。识别哪些事务可以并发执行,即无关联事务或并行执行事务。(5) Parallel execution possibility analysis: Based on the dependencies between transactions, determine whether it is possible to execute some transactions in parallel. If there is no data dependency and control dependency between two transactions, they can be executed in parallel on a multi-core CPU. Identify which transactions can be executed concurrently, that is, unrelated transactions or parallel transactions.
第三步、事务调度:Step 3: Transaction Scheduling:
蚁群算法(Ant Colony Optimization, ACO)是一种模拟蚂蚁群体寻找食物路径的优化算法,在多核CPU事务调度中,蚁群算法可以帮助找到一组最优的事务并发调度分配方案,蚂蚁在蚁群算法中的行为可以对应于事务的执行顺序。蚁群算法模拟了蚂蚁在搜索空间中释放信息素并根据信息素量和启发式信息来做出决策的过程。在多核CPU事务调度中,可以使用类似的方法来模拟蚂蚁在依赖图上搜索最优调度方案,以最大程度地提高CPU利用率和系统性能。但是现有的蚁群算法多用于路径规划的研究。现有技术中并没有直接将蚁群算法直接应用于数据库事务分配的应用。为此,本发明提出一种改进的蚁群算法,具体内容如下:Ant Colony Optimization (ACO) is an optimization algorithm that simulates an ant colony searching for food paths. In multi-core CPU transaction scheduling, the ant colony algorithm can help find a set of optimal concurrent transaction scheduling allocation schemes. The behavior of ants in the ant colony algorithm can correspond to the execution order of transactions. The ant colony algorithm simulates the process of ants releasing pheromones in the search space and making decisions based on the amount of pheromones and heuristic information. In multi-core CPU transaction scheduling, a similar method can be used to simulate ants searching for the optimal scheduling scheme on the dependency graph to maximize CPU utilization and system performance. However, existing ant colony algorithms are mostly used for path planning research. There is no application in the prior art that directly applies the ant colony algorithm to database transaction allocation. To this end, the present invention proposes an improved ant colony algorithm, the specific contents of which are as follows:
在多核CPU事务调度中,依赖图可以看作是一个有向无环图(DAG),事务集合E={S1,S2,S3,S4,S5,S6,…,Sn},W包含事务间的依赖关系,事务依赖关系集合为W={R1,R2,R3,R4}。In multi-core CPU transaction scheduling, the dependency graph can be regarded as a directed acyclic graph (DAG), the transaction set E = {S1, S2, S3, S4, S5, S6, …, Sn}, W contains the dependencies between transactions, and the transaction dependency set is W = {R1, R2, R3, R4}.
改进蚁群算法在多核CPU事务调度中的应用过程如下:The application process of the improved ant colony algorithm in multi-core CPU transaction scheduling is as follows:
信息素表示: 将依赖图中的边视为路径,将信息素量与边相关联。信息素代表着路径的质量或适应度,通常可以初始化为一个较小的正值,在本方法中,信息素采用步骤一所建立的依赖图的依赖关系进行衡量,如数据依赖R1、控制依赖R2、事务优先级依赖R3、并行执行依赖R4。Pheromone representation: The edges in the dependency graph are considered as paths, and the amount of pheromone is associated with the edges. Pheromones represent the quality or fitness of the path and can usually be initialized to a small positive value. In this method, pheromones are measured using the dependency relationships of the dependency graph established in step 1, such as data dependency R1, control dependency R2, transaction priority dependency R3, and parallel execution dependency R4.
1)定义边的信息素量:1) Define the pheromone amount of the edge:
假设有一条边e连接节点i和节点j,信息素量表示为τ(i, j)。Assume that there is an edge e connecting nodes i and j, and the amount of pheromone is represented by τ(i, j).
2)考虑依赖关系对信息素量的影响:通过依赖关系关系确定信息素量2) Consider the impact of dependency on pheromone quantity: Determine the pheromone quantity through dependency relationship
依赖关系包括数据依赖R1、控制依赖R2、事务优先级依赖R3、并行执行依赖R4,以及它们对应的权重为D1、D2、D3、D4。那么可以通过加权和的方式将依赖关系的影响结合到信息素量中,公式如下:Dependencies include data dependency R1, control dependency R2, transaction priority dependency R3, parallel execution dependency R4, and their corresponding weights are D1, D2, D3, and D4. The influence of dependencies can be combined into the pheromone quantity by weighted sum, as shown in the following formula:
其中,τ0(i, j)是初始信息素量,是信息素蒸发系数,R1(i, j)、R2(i, j)、R3 (i, j)、R4(i, j)分别代表不同依赖关系的影响值。Among them, τ0(i, j) is the initial pheromone amount, is the pheromone evaporation coefficient, R1(i, j), R2(i, j), R3 (i, j), and R4(i, j) represent the impact values of different dependencies, respectively.
(2)蚂蚁行为模拟: 模拟多只蚂蚁在依赖图上的移动和选择路径的过程。每个蚂蚁根据信息素量和启发式信息选择下一个要执行的事务,直到所有事务都被调度。创建一群蚂蚁,并让它们模拟在依赖图上的移动和路径选择过程。每只蚂蚁都从一个起始节点开始,然后根据信息素量和启发式信息选择下一个要执行的节点。蚂蚁按照选择执行事务,直到所有的事务都被调度。这一步中,蚂蚁的选择策略可以使用蚁群算法的公式来决定。蚂蚁在选择下一个节点时,可以使用概率方式,根据信息素量和启发式信息来进行决策。通常情况下,蚂蚁在节点i上选择下一个节点j的概率可以由以下公式计算:(2) Ant behavior simulation: Simulate the process of multiple ants moving and selecting paths on the dependency graph. Each ant selects the next transaction to be executed based on the amount of pheromone and heuristic information until all transactions are scheduled. Create a group of ants and let them simulate the process of moving and selecting paths on the dependency graph. Each ant starts from a starting node and then selects the next node to be executed based on the amount of pheromone and heuristic information. Ants execute transactions according to their selection until all transactions are scheduled. In this step, the ant's selection strategy can be determined using the formula of the ant colony algorithm. When selecting the next node, the ant can use a probabilistic method to make decisions based on the amount of pheromone and heuristic information. Generally, the probability that an ant selects the next node j on node i can be calculated by the following formula:
此公式即为路径选择概率公式。蚂蚁在选择下一个要执行的事务时,根据信息素量和启发式信息来计算路径选择的概率,其中:This formula is the path selection probability formula. When the ant chooses the next transaction to be executed, it calculates the probability of path selection based on the amount of pheromone and heuristic information, where:
表示蚂蚁从节点i选择节点j的概率。 represents the probability that an ant chooses node j from node i.
表示边(i, j)上的信息素量。 Represents the amount of pheromone on edge (i, j).
是调节信息素和启发式信息在选择中的权重的参数。 is a parameter that adjusts the weight of pheromone and heuristic information in the selection.
表示启发式信息,使用问题特定的指标进行计算。 Represents heuristic information, computed using problem-specific metrics.
为启发式信息映射值。 Maps values for heuristic information.
表示蚂蚁k未访问过的节点集合。 Represents the set of nodes that ant k has not visited.
(3)启发式信息:启发式信息帮助蚂蚁在没有信息素引导的情况下,选择可能更有希望的路径。考虑多核cpu并发事务分配方法最主要的影响因素是节点事务资源利用率、节点事务执行时间、节点事务优先级、节点事务等待时间,随着蚂蚁的搜索过程进行更新,以更好地指导路径的选择。(3) Heuristic information: Heuristic information helps ants choose paths that may be more promising without the guidance of pheromones. The most important factors affecting the multi-core CPU concurrent transaction allocation method are node transaction resource utilization, node transaction execution time, node transaction priority, and node transaction waiting time, which are updated as the ants search to better guide path selection.
1)节点事务资源利用率:如果节点i和节点j共享相同的资源(例如共享缓存、共享内存等),则节点i的执行可能会影响到节点j的性能,从而影响的取值。1) Node transaction resource utilization: If nodes i and j share the same resources (such as shared cache, shared memory, etc.), the execution of node i may affect the performance of node j, thereby affecting The value of .
2)节点事务执行时间:节点i上的事务执行时间会影响其他节点上事务的调度情况。较长的执行时间可能会导致更多的依赖节点等待,从而影响的取值。2) Node transaction execution time: The transaction execution time on node i will affect the scheduling of transactions on other nodes. Longer execution time may cause more dependent nodes to wait, thus affecting The value of .
3)节点事务优先级:某些事务可能具有更高的优先级,需要尽早得到执行。优先级较高的事务对应的节点可能会成为其他节点的依赖对象,从而影响的取值。3) Node transaction priority: Some transactions may have higher priority and need to be executed as soon as possible. The nodes corresponding to the transactions with higher priority may become dependent objects of other nodes, thus affecting The value of .
4)节点事务等待时间:节点i上的事务等待时间的占比会影响其他节点上事务的等待时间。较长的等待时间可能会导致更多的节点等待资源,总等待时间增加,从而影响的取值。4) Node transaction waiting time: The proportion of transaction waiting time on node i will affect the waiting time of transactions on other nodes. Longer waiting time may cause more nodes to wait for resources, increasing the total waiting time, thus affecting The value of .
进一步的,基于节点资源利用率:Furthermore, based on node resource utilization:
=资源利用率Ui/资源总量U = Resource utilization Ui/total resources U
其中,资源利用率Ui表示节点i当前已分配的事务所占用的资源比例,资源总量表示总资源容量。这个公式表示节点i的资源利用率越高,越大,表示节点i的资源对节点的影响程度较大,这条路径更有吸引力。Among them, resource utilization Ui represents the proportion of resources currently occupied by the transactions allocated to node i, and the total amount of resources represents the total resource capacity. This formula means that the higher the resource utilization of node i, The larger it is, the greater the influence of node i’s resources on the node, and the more attractive this path is.
基于事务执行时间:Based on transaction execution time:
=1-(事务执行时间Ti/最大事务执行时间T) =1-(transaction execution time Ti/maximum transaction execution time T)
其中,事务执行时间Ti表示节点i上执行事务所需的时间,最大事务执行时间表示所有事务中最长的执行时间,如果事务i在节点i上执行所需时间较短,值较大,表示节点i的执行时间对节点的影响程度较大,这条路径更有吸引力。Among them, the transaction execution time Ti represents the time required to execute a transaction on node i, and the maximum transaction execution time represents the longest execution time of all transactions. If the time required to execute transaction i on node i is shorter, A larger value indicates that the execution time of node i has a greater impact on the node, and this path is more attractive.
基于事务的优先级:Based on the priority of the transaction:
=事务优先级Pi / 最高优先级P =Transaction priority Pi / highest priority P
其中,优先级Pi表示事务i的优先级,最高优先级表示所有事务中最高的优先级。表示优先级较高的事务对应的节点i对节点的影响程度较大,值较大,其对蚂蚁更具吸引力。Among them, priority Pi represents the priority of transaction i, and the highest priority represents the highest priority among all transactions. It means that the node i corresponding to the transaction with higher priority has a greater impact on the node, The larger the value, the more attractive it is to ants.
基于事务等待时间:Based on transaction wait time:
=1-(事务等待时间Wi / 最大事务等待时间W) =1-(transaction waiting time Wi / maximum transaction waiting time W)
其中,最大事务等待时间W表示所有事务中最长的等待时间。若节点i上的事务等待时间较短, 值较大,表示节点i的等待时间对节点的影响程度较大,该路径更有吸引力。Among them, the maximum transaction waiting time W represents the longest waiting time among all transactions. If the transaction waiting time on node i is short, A larger value indicates that the waiting time of node i has a greater impact on the node, and the path is more attractive.
其中,H1,H2,H3,H4分别是影响因素的权重Among them, H1, H2, H3, and H4 are the weights of the influencing factors.
由于不同因素的量纲可能不同,直接将它们结合在一起可能会导致值域差异较大。为了确保它们在蚁群算法中对决策的影响是合理的,可以对进行归一化,将其映射到一个相同的范围内。Since different factors may have different dimensions, directly combining them together may result in large differences in the range of values. In order to ensure that their influence on the decision-making in the ant colony algorithm is reasonable, Normalize them to map them into the same range.
使用线性归一化方法将映射到[0, 1]范围内:Using linear normalization method, Mapped to the range [0, 1]:
其中, 是所有中的最小值,是所有中的最大值。这样,所有的值都在[0, 1]之间,确保了它们具有相同的量纲和权重处理的效果。in, Yes all The minimum value in Yes all In this way, all The values are all between [0, 1], ensuring that they have the same dimension and weight processing effect.
这样,蚂蚁在选择下一个节点时,会同时考虑信息素量和启发式信息,并基于概率进行选择。In this way, when the ant chooses the next node, it will consider both the pheromone amount and the heuristic information and make a choice based on probability.
(4)信息素更新:当所有蚂蚁完成一次迭代后,根据调度方案的质量,更新信息素量。通常,更优秀的调度方案会释放更多的信息素。(4) Pheromone update: When all ants complete an iteration, the amount of pheromone is updated according to the quality of the scheduling plan. Generally, a better scheduling plan will release more pheromones.
其中:in:
是信息素的蒸发速率,用于控制信息素的挥发和降低信息素量。 It is the evaporation rate of pheromone, which is used to control the volatilization of pheromone and reduce the amount of pheromone.
是蚂蚁k通过边(i, j)的信息素增量,通常与蚂蚁k的调度方案质量有关。 is the pheromone increment of ant k through edge (i, j), which is usually related to the quality of ant k ’s scheduling plan.
在信息素更新过程中,较好的调度方案会释放更多的信息素到相关的边上,从而增强这些边被蚂蚁选择的可能性。During the pheromone update process, a better scheduling scheme will release more pheromones to the relevant edges, thereby increasing the possibility of these edges being selected by ants.
(4)重复迭代: 重复执行蚂蚁的行为模拟和信息素更新过程,直到满足最大迭代次数K。(4) Repeated iteration: Repeat the ant behavior simulation and pheromone update process until the maximum number of iterations K is met.
(5)选择最优解: 在多次迭代后,从蚂蚁的行为中得到多个调度方案,其中。F为常量,Lk表示蚂蚁所走过的路径质量,通过对比从中选择最优解,最终获得集代表在迭代中蚂蚁群体所找到的最优的并发事务分配方案,即具有最好性能的调度方案作为最终结果。(5) Select the optimal solution: After multiple iterations, multiple scheduling solutions are obtained from the behavior of the ants. F is a constant, Lk represents the quality of the path taken by the ants, and the optimal solution is selected by comparison, and finally The set represents the optimal concurrent transaction allocation scheme found by the ant colony in the iteration, that is, the scheduling scheme with the best performance as the final result.
第四步、执行并进行依赖关系跟踪更新:Step 4: Execute and update dependency tracking:
采用蚁群算法在多核CPU上执行并行事务分配,可以获得最优的调度组,从而最大限度地提高系统性能。在调度组执行过程中,跟踪依赖关系的满足情况。如果某个调度组的依赖关系无法满足,可能需要暂停该事务组的执行,直到依赖关系得到满足。By using the ant colony algorithm to perform parallel transaction allocation on a multi-core CPU, the optimal scheduling group can be obtained, thereby maximizing system performance. During the execution of the scheduling group, the satisfaction of the dependencies is tracked. If the dependency of a scheduling group cannot be satisfied, the execution of the transaction group may need to be suspended until the dependency is satisfied.
通过多只蚂蚁的并行行动,蚁群算法可以更好地利用多核CPU的并行性能。每只蚂蚁相当于一个并行执行单元,可以独立地探索不同的调度方案,从而加速搜索过程。同时,蚁群算法的并行性也有助于避免陷入局部最优解,增加算法搜索全局最优解的可能性和自适应性。蚁群算法通过对资源利用率高、事务执行时间少、事务优先级高、事务等待时间短进行优化,选择出最优的路径解,提高多核CPU并发事务的执行效率。Through the parallel actions of multiple ants, the ant colony algorithm can better utilize the parallel performance of multi-core CPUs. Each ant is equivalent to a parallel execution unit, which can independently explore different scheduling schemes, thereby accelerating the search process. At the same time, the parallelism of the ant colony algorithm also helps to avoid falling into the local optimal solution, increasing the possibility and adaptability of the algorithm to search for the global optimal solution. The ant colony algorithm selects the optimal path solution by optimizing high resource utilization, low transaction execution time, high transaction priority, and short transaction waiting time, thereby improving the execution efficiency of multi-core CPU concurrent transactions.
具体实施例3:Specific embodiment 3:
第二方面,本发明还提供一种基于依赖图的多核CPU并发事务分配系统,所述系统包括:依赖图模块、信息素量模块、启发式信息模块、更新模块;In a second aspect, the present invention further provides a multi-core CPU concurrent transaction allocation system based on a dependency graph, the system comprising: a dependency graph module, a pheromone quantity module, a heuristic information module, and an update module;
所述依赖图模块用于,基于数据库中事务之间的执行关联性构建依赖图,所述数据库中的每个事务作为图中的一个节点,事务之间的依赖关系形成图中的有向边;The dependency graph module is used to construct a dependency graph based on the execution association between transactions in the database, wherein each transaction in the database serves as a node in the graph, and the dependency relationships between transactions form directed edges in the graph;
所述信息素量模块用于,基于所述依赖图相邻两节点之间的依赖关系确定所述相邻两节点对应的边的信息素量;The pheromone quantity module is used to determine the pheromone quantity of the edge corresponding to the two adjacent nodes based on the dependency relationship between the two adjacent nodes in the dependency graph;
所述启发式信息模块用于,基于所述依赖图各个节点对应事务的事务属性确定各个节点的启发式信息;The heuristic information module is used to determine the heuristic information of each node based on the transaction attributes of the transaction corresponding to each node of the dependency graph;
所述更新模块用于,基于蚁群的行为模型按照所述依赖图执行所述数据库中的事务,并更新所述依赖图上各个边上的信息素。The updating module is used to execute the transactions in the database according to the dependency graph based on the behavior model of the ant colony, and to update the pheromone on each edge of the dependency graph.
优选的,所述依赖图模块具体用于:基于所述数据库中的每个事务建立一个对应的节点;Preferably, the dependency graph module is specifically used to: establish a corresponding node based on each transaction in the database;
基于每个所述节点对应的事务之间的数据流动关系、时间戳信息、价值信息、提交顺序,确定各个节点之间的边,所述边用于表示各个节点之间的关联性。Based on the data flow relationship, timestamp information, value information, and submission order between the transactions corresponding to each of the nodes, the edges between the nodes are determined, and the edges are used to represent the association between the nodes.
优选的,所述依赖图模块还用于:通过记录数据来源、数据去向和版本信息标记对应节点之间的数据依赖关系R1:Preferably, the dependency graph module is further used to: mark the data dependency relationship R1 between corresponding nodes by recording data source, data destination and version information:
通过记录事务或数据的时间戳信息标记对应节点之间的控制依赖关系R2:The control dependency relationship R2 between corresponding nodes is marked by recording the timestamp information of transactions or data:
通过记录事务价值信息标记对饮节点之间的事务优先级依赖关系R3:By recording the transaction value information, the transaction priority dependency R3 between the nodes is marked:
通过记录事务提交顺序标记对应节点之间的并行执行关系R4。The parallel execution relationship R4 between corresponding nodes is marked by recording the transaction submission order.
优选的,所述信息素量模块用于:确定数据依赖关系R1对应的数据权重D1、控制依赖关系R2对应的控制权重D2、事务优先级依赖关系R3对应的优先权重D3、并行执行关系R4对应的并行权重D4;Preferably, the pheromone quantity module is used to: determine the data weight D1 corresponding to the data dependency R1, the control weight D2 corresponding to the control dependency R2, the priority weight D3 corresponding to the transaction priority dependency R3, and the parallel weight D4 corresponding to the parallel execution relationship R4;
基于初始信息素量、信息素蒸发系数、所述相邻两节点之间的依赖关系和各个所述依赖关系对应的权重,确定所述相邻两节点对应的边的信息素量。Based on the initial pheromone quantity, the pheromone evaporation coefficient, the dependency relationship between the two adjacent nodes and the weight corresponding to each of the dependency relationships, the pheromone quantity of the edge corresponding to the two adjacent nodes is determined.
优选的,所述启发式信息模块用于:确定所述事务属性中各个属性对应的属性启发式信息;Preferably, the heuristic information module is used to: determine the attribute heuristic information corresponding to each attribute in the transaction attribute;
确定所述各个属性启发式信息对应的权重;Determine the weight corresponding to each attribute heuristic information;
基于所述各个属性启发式信息和所述权重确定所述事务的启发式信息;Determining heuristic information of the transaction based on the respective attribute heuristic information and the weight;
基于所述事务的启发式信息、所述各个属性启发式信息的最大值和最小值确定启发式信息映射值,所述启发式信息映射值作为所述相邻节点之间的启发式信息。A heuristic information mapping value is determined based on the heuristic information of the transaction and the maximum and minimum values of the heuristic information of each attribute, and the heuristic information mapping value is used as the heuristic information between the adjacent nodes.
优选的,所述各个节点对应的事务属性包括:节点事务资源利用率、节点事务执行时间、节点事务优先级、节点事务等待时间。Preferably, the transaction attributes corresponding to each node include: node transaction resource utilization, node transaction execution time, node transaction priority, and node transaction waiting time.
优选的,所述更新模块用于:基于所述依赖图中的各个节点的启发式信息和各个边的信息素量,模拟蚁群并发执行数据库中的事务;Preferably, the update module is used to: simulate ant colonies to concurrently execute transactions in the database based on the heuristic information of each node and the pheromone amount of each edge in the dependency graph;
基于执行事务的完成质量更新所述执行事务对应的边的信息素量。The pheromone amount of the edge corresponding to the executed transaction is updated based on the completion quality of the executed transaction.
优选的,所述基于执行事务的完成质量更新所述执行事务对应的边的信息素量,所采用的公式为:Preferably, the pheromone quantity of the edge corresponding to the executed transaction is updated based on the completion quality of the executed transaction, and the formula adopted is:
是信息素的蒸发速率,用于控制信息素的挥发和降低信息素量。 It is the evaporation rate of pheromone, which is used to control the volatilization of pheromone and reduce the amount of pheromone.
是蚂蚁k通过边(i, j)的信息素增量,所述信息素增量与蚂蚁k的调度方案质量有关。 is the pheromone increment of ant k through edge (i, j), and the pheromone increment is related to the quality of ant k's scheduling plan.
具体实施例4:Specific embodiment 4:
第三方面,本发明还提供一种数据库,所述数据库中设置有存储器和处理器,所述存储器用于存储计算机程序,所述处理器用于调用所述存储器内的计算机程序以执行如下步骤:In a third aspect, the present invention further provides a database, wherein the database is provided with a memory and a processor, the memory is used to store a computer program, and the processor is used to call the computer program in the memory to perform the following steps:
基于数据库中事务之间的执行关联性构建依赖图,所述数据库中的每个事务作为图中的一个节点,事务之间的依赖关系形成图中的有向边;Building a dependency graph based on the execution association between transactions in the database, wherein each transaction in the database serves as a node in the graph, and the dependency relationships between transactions form directed edges in the graph;
基于所述依赖图相邻两节点之间的依赖关系确定所述相邻两节点对应的边的信息素量;Determine the pheromone amount of the edge corresponding to the two adjacent nodes based on the dependency relationship between the two adjacent nodes in the dependency graph;
基于所述依赖图各个节点对应事务的事务属性确定各个节点的启发式信息;Determine heuristic information of each node based on the transaction attributes of the transaction corresponding to each node of the dependency graph;
基于蚁群的行为模型按照所述依赖图执行所述数据库中的事务,并更新所述依赖图上各个边上的信息素。The transaction in the database is executed according to the dependency graph based on the behavior model of the ant colony, and the pheromone on each edge of the dependency graph is updated.
进一步的,所述基于数据库中事务之间的执行关联性构建依赖图,包括:Furthermore, the step of constructing a dependency graph based on the execution association between transactions in the database includes:
基于所述数据库中的每个事务建立一个对应的节点;Establishing a corresponding node based on each transaction in the database;
基于每个所述节点对应的事务之间的数据流动关系、时间戳信息、价值信息、提交顺序,确定各个节点之间的边,所述边用于表示各个节点之间的关联性。Based on the data flow relationship, timestamp information, value information, and submission order between the transactions corresponding to each of the nodes, the edges between the nodes are determined, and the edges are used to represent the association between the nodes.
进一步的,所述基于每个所述节点对应的事务之间的数据流动关系、时间戳信息、价值信息、提交顺序,确定各个节点之间的边,具体为:Furthermore, based on the data flow relationship, timestamp information, value information, and submission order between the transactions corresponding to each node, the edges between the nodes are determined, specifically:
通过记录数据来源、数据去向和版本信息标记对应节点之间的数据依赖关系R1:The data dependency relationship R1 between corresponding nodes is marked by recording data source, data destination and version information:
通过记录事务或数据的时间戳信息标记对应节点之间的控制依赖关系R2:The control dependency relationship R2 between corresponding nodes is marked by recording the timestamp information of transactions or data:
通过记录事务价值信息标记对应节点之间的事务优先级依赖关系R3:By recording the transaction value information, the transaction priority dependency R3 between the corresponding nodes is marked:
通过记录事务提交顺序标记对应节点之间的并行执行关系R4。The parallel execution relationship R4 between corresponding nodes is marked by recording the transaction submission order.
进一步的,所述基于所述依赖图相邻两节点之间的依赖关系确定所述相邻两节点对应的边的信息素量,包括:Furthermore, the step of determining the pheromone amount of the edge corresponding to two adjacent nodes based on the dependency relationship between the two adjacent nodes in the dependency graph includes:
确定数据依赖关系R1对应的数据权重D1、控制依赖关系R2对应的控制权重D2、事务优先级依赖关系R3对应的优先权重D3、并行执行关系R4对应的并行权重D4;Determine the data weight D1 corresponding to the data dependency R1, the control weight D2 corresponding to the control dependency R2, the priority weight D3 corresponding to the transaction priority dependency R3, and the parallel weight D4 corresponding to the parallel execution relationship R4;
基于初始信息素量、信息素蒸发系数、所述相邻两节点之间的依赖关系和各个所述依赖关系对应的权重,确定所述相邻两节点对应的边的信息素量。Based on the initial pheromone quantity, the pheromone evaporation coefficient, the dependency relationship between the two adjacent nodes and the weight corresponding to each of the dependency relationships, the pheromone quantity of the edge corresponding to the two adjacent nodes is determined.
进一步的,所述基于所述依赖图各个节点对应事务的事务属性确定各个节点的启发式信息,包括:Furthermore, the determining of the heuristic information of each node based on the transaction attribute of the transaction corresponding to each node of the dependency graph includes:
确定所述事务属性中各个属性对应的属性启发式信息;Determine attribute heuristic information corresponding to each attribute in the transaction attribute;
确定所述各个属性启发式信息对应的权重;Determine the weight corresponding to each attribute heuristic information;
基于所述各个属性启发式信息和所述权重确定所述事务的启发式信息;Determining heuristic information of the transaction based on the respective attribute heuristic information and the weight;
基于所述事务的启发式信息、所述各个属性启发式信息的最大值和最小值确定启发式信息映射值,所述启发式信息映射值作为所述相邻节点之间的启发式信息。A heuristic information mapping value is determined based on the heuristic information of the transaction and the maximum and minimum values of the heuristic information of each attribute, and the heuristic information mapping value is used as the heuristic information between the adjacent nodes.
进一步的,所述各个节点对应的事务属性包括:节点事务资源利用率、节点事务执行时间、节点事务优先级、节点事务等待时间。Furthermore, the transaction attributes corresponding to each node include: node transaction resource utilization, node transaction execution time, node transaction priority, and node transaction waiting time.
进一步的,所述基于蚁群的行为模型按照所述依赖图执行所述数据库中的事务,并更新所述依赖图上各个边上的信息素,具体为:Furthermore, the ant colony-based behavior model executes the transactions in the database according to the dependency graph and updates the pheromone on each edge of the dependency graph, specifically:
基于所述依赖图中的各个节点的启发式信息和各个边的信息素量,模拟蚁群并发执行数据库中的事务;Based on the heuristic information of each node in the dependency graph and the pheromone amount of each edge, simulating an ant colony to concurrently execute transactions in the database;
基于执行事务的完成质量更新所述执行事务对应的边的信息素量。The pheromone amount of the edge corresponding to the executed transaction is updated based on the completion quality of the executed transaction.
进一步的,所述基于执行事务的完成质量更新所述执行事务对应的边的信息素量,所采用的公式为:Furthermore, the pheromone quantity of the edge corresponding to the executed transaction is updated based on the completion quality of the executed transaction, and the formula adopted is:
是信息素的蒸发速率,用于控制信息素的挥发和降低信息素量。 It is the evaporation rate of pheromone, which is used to control the volatilization of pheromone and reduce the amount of pheromone.
是蚂蚁k通过边(i, j)的信息素增量,所述信息素增量与蚂蚁k的调度方案质量有关。 is the pheromone increment of ant k through edge (i, j), and the pheromone increment is related to the quality of ant k's scheduling plan.
Claims (7)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311056907.5A CN116775315B (en) | 2023-08-22 | 2023-08-22 | Multi-core CPU concurrent transaction allocation method based on dependency graph |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311056907.5A CN116775315B (en) | 2023-08-22 | 2023-08-22 | Multi-core CPU concurrent transaction allocation method based on dependency graph |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN116775315A CN116775315A (en) | 2023-09-19 |
| CN116775315B true CN116775315B (en) | 2024-01-02 |
Family
ID=87991642
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202311056907.5A Active CN116775315B (en) | 2023-08-22 | 2023-08-22 | Multi-core CPU concurrent transaction allocation method based on dependency graph |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN116775315B (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN120469737B (en) * | 2025-07-15 | 2025-09-12 | 苏州元脑智能科技有限公司 | Method for determining service start sequence, electronic device and storage medium |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105487920A (en) * | 2015-10-12 | 2016-04-13 | 沈阳工业大学 | Ant colony algorithm based optimization method for real-time task scheduling of multi-core system |
| CN106844049A (en) * | 2017-01-13 | 2017-06-13 | 广西电网有限责任公司电力科学研究院 | A kind of method for allocating tasks of distributed computing system |
| CN109033301A (en) * | 2018-07-16 | 2018-12-18 | 中国科学技术大学 | A kind of db transaction execution method based on graphics processor |
| CN109684083A (en) * | 2018-12-11 | 2019-04-26 | 北京工业大学 | A kind of multilevel transaction schedule allocation strategy towards under edge-cloud isomery |
| CN115629822A (en) * | 2022-11-09 | 2023-01-20 | 深圳计算科学研究院 | Concurrent transaction processing method and system based on multi-core processor |
| CN116303495A (en) * | 2023-02-24 | 2023-06-23 | 陈晓帆 | A database system and method supporting parallel update |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US8806495B2 (en) * | 2006-11-20 | 2014-08-12 | Microsoft Corp. | Lightweight transactional memory for data parallel programming |
-
2023
- 2023-08-22 CN CN202311056907.5A patent/CN116775315B/en active Active
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105487920A (en) * | 2015-10-12 | 2016-04-13 | 沈阳工业大学 | Ant colony algorithm based optimization method for real-time task scheduling of multi-core system |
| CN106844049A (en) * | 2017-01-13 | 2017-06-13 | 广西电网有限责任公司电力科学研究院 | A kind of method for allocating tasks of distributed computing system |
| CN109033301A (en) * | 2018-07-16 | 2018-12-18 | 中国科学技术大学 | A kind of db transaction execution method based on graphics processor |
| CN109684083A (en) * | 2018-12-11 | 2019-04-26 | 北京工业大学 | A kind of multilevel transaction schedule allocation strategy towards under edge-cloud isomery |
| CN115629822A (en) * | 2022-11-09 | 2023-01-20 | 深圳计算科学研究院 | Concurrent transaction processing method and system based on multi-core processor |
| CN116303495A (en) * | 2023-02-24 | 2023-06-23 | 陈晓帆 | A database system and method supporting parallel update |
Non-Patent Citations (1)
| Title |
|---|
| "分布式流式计算框架关键技术的研究与实现";顾昕;《中国优秀硕士学位论文全文数据库 信息科技辑》;第I140-396页 * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN116775315A (en) | 2023-09-19 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US6434590B1 (en) | Methods and apparatus for scheduling parallel processors | |
| US8671409B2 (en) | Scheduling method and system, corresponding computational grid and computer program product | |
| CN120429123B (en) | Heterogeneous computing acceleration method and system based on deep learning framework network | |
| CN109634742A (en) | A kind of time-constrain scientific workflow optimization method based on ant group algorithm | |
| CN101464965B (en) | Multi-nuclear parallel ant group design method based on TBB | |
| Zhang et al. | A resource optimization scheduling model and algorithm for heterogeneous computing clusters based on GNN and RL: Z. Zhang et al. | |
| CN118860610B (en) | A Deadlock-Free Dynamic Scheduling Method for Automated Laboratories Based on Monte Carlo Tree Search | |
| CN116775315B (en) | Multi-core CPU concurrent transaction allocation method based on dependency graph | |
| CN119645667A (en) | Task allocation optimization method and device for multi-core heterogeneous ASIC computing main board | |
| Ahmad et al. | An Analytical Review and Performance Measures of State-of-Art Scheduling Algorithms in Heterogenous Computing Enviornment: W. Ahmad et al. | |
| CN114662932A (en) | A Node Hierarchical Workflow Scheduled Task Scheduling Method | |
| Salari-Hamzehkhani et al. | Introducing an improved deep reinforcement learning algorithm for task scheduling in cloud computing | |
| Czarnul et al. | Optimization of resource-aware parallel and distributed computing: a review: P. Czarnul et al. | |
| CN114860417B (en) | Multi-core neural network processor and multi-task allocation scheduling method for same | |
| CN120295732A (en) | Task scheduling method and device based on resource optimization | |
| CN118567818B (en) | Task scheduling method, device, equipment, storage medium and product | |
| CN120335953A (en) | Multi-core processor task scheduling method under NUMA architecture based on reinforcement learning | |
| Yan | " Post-game analysis"--a heuristic resource management framework for concurrent systems | |
| CN118114842B (en) | Hydrologic model scheduling method and device, storage medium and electronic equipment | |
| Khan et al. | Architectural support for task scheduling: hardware scheduling for dataflow on NUMA systems | |
| CN120123062B (en) | Data processing mode based on SQL script | |
| CN121070629B (en) | Load balancing methods and systems for low-power AI processors | |
| CN119761770B (en) | Equipment support planning method, device, computer-readable storage medium, electronic device and computer program product | |
| CN120849133B (en) | A method and system for generating intermediate representations of multi-architecture compilation driven by heterogeneous computing power fusion | |
| Han | Resource scheduling algorithm for heterogeneous high-performance clusters |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |