CN116820786A - Data access method and device of database, electronic equipment and storage medium - Google Patents

Data access method and device of database, electronic equipment and storage medium Download PDF

Info

Publication number
CN116820786A
CN116820786A CN202311108662.6A CN202311108662A CN116820786A CN 116820786 A CN116820786 A CN 116820786A CN 202311108662 A CN202311108662 A CN 202311108662A CN 116820786 A CN116820786 A CN 116820786A
Authority
CN
China
Prior art keywords
target
access
thread
partition
task
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.)
Granted
Application number
CN202311108662.6A
Other languages
Chinese (zh)
Other versions
CN116820786B (en
Inventor
刘博格
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Primitive Data Beijing Information Technology Co ltd
Original Assignee
Primitive Data Beijing Information Technology Co ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Primitive Data Beijing Information Technology Co ltd filed Critical Primitive Data Beijing Information Technology Co ltd
Priority to CN202311108662.6A priority Critical patent/CN116820786B/en
Publication of CN116820786A publication Critical patent/CN116820786A/en
Application granted granted Critical
Publication of CN116820786B publication Critical patent/CN116820786B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a data access method and device of a database, electronic equipment and a storage medium, and relates to the technical field of databases. The method comprises the following steps: determining a coroutine task to be allocated based on a query request to the database, wherein the database comprises a plurality of partitions; acquiring target access times of the to-be-allocated coroutine task to each partition; obtaining access preference degrees of a plurality of candidate threads to each partition; predicting the allocation score of the coroutine task to be allocated to the candidate thread based on the target access times and the access preference; determining a target thread from a plurality of the candidate threads based on the allocation score; and distributing the to-be-distributed coroutine task to the target thread, and accessing the partition by the target thread based on the to-be-distributed coroutine task. The embodiment of the application improves the access efficiency of the database.

Description

Data access method and device of database, electronic equipment and storage medium
Technical Field
The present application relates to the field of database technologies, and in particular, to a method and an apparatus for accessing data of a database, an electronic device, and a storage medium.
Background
With the rapid development of big data and the Internet, the data concurrency query and analysis efficiency is an important index for measuring a database system. In order to improve concurrency, a modern database system adopts multithreading to execute user query requests, and cross-thread or inter-process data access competition is inevitably introduced. In an extreme scenario, when a large number of users need to read modified data and concentrate it in a certain area, the waiting and switching costs caused by inter-thread competition consume computing resources greatly, resulting in the occurrence of performance bottlenecks of the database system.
Therefore, how to provide a data access method for a database, so as to improve the access efficiency of the database, is a technical problem to be solved urgently.
Disclosure of Invention
The embodiment of the application mainly aims to provide a data access method and device of a database, electronic equipment and a storage medium, which can improve the access efficiency of the database.
To achieve the above object, a first aspect of an embodiment of the present application provides a data access method of a database, the database including a plurality of partitions, the data access method including:
determining a to-be-allocated coroutine task based on a query request to the database;
Acquiring target access times of the to-be-allocated coroutine task to each partition;
obtaining access preference degrees of a plurality of candidate threads to each partition;
predicting the allocation score of the coroutine task to be allocated to the candidate thread based on the target access times and the access preference;
determining a target thread from a plurality of the candidate threads based on the allocation score;
and distributing the to-be-distributed coroutine task to the target thread, and accessing the partition by the target thread based on the to-be-distributed coroutine task.
Optionally, the obtaining access preference of the plurality of candidate threads to each partition includes:
constructing an access preference matrix based on the plurality of partitions and the plurality of candidate threads; wherein each element in the access preference matrix is used for indicating the access preference degree of the candidate thread to the partition;
and acquiring the access preference degree from the access preference matrix.
Optionally, after the allocating the to-be-allocated coroutine task to the target thread, the data access method further includes:
acquiring an initial value aiming at an element corresponding to the target thread in the access preference matrix;
Acquiring the existing access times of the allocated coroutine task to be allocated of the target thread to each partition;
summing the existing access times and the target access times to obtain first total partition access times of the target thread to each partition;
multiplying the initial value by the existing access times, and summing the multiplication result and the target access times to obtain the first single partition access times of the target thread to the single partition;
obtaining a first target updating value based on the ratio between the first single partition access times and the first total partition access times;
replacing the initial value based on the first target update value to update the access preference matrix.
Optionally, after replacing the initial value based on the target update value to update the access preference matrix, the data access method further includes:
responding to the end of the access of the to-be-allocated coroutine task to the database, and subtracting the target access times from the existing access times to obtain second total partition access times of the target thread to each partition;
Multiplying the first target update value by the existing access times, and subtracting the multiplication result from the target access times to obtain the second single partition access times of the target thread to the single partition;
obtaining a second target updated value based on a ratio between the second single partition access number and the second total partition access number;
replacing the first target update value based on the second target update value to update the access preference matrix.
Optionally, the predicting, based on the target access times and the access preference, an allocation score of the coroutine task to be allocated to the candidate thread includes:
acquiring a target load of the cooperative task to be allocated and acquiring the existing load of the candidate thread;
determining a first score based on the target load and the existing load;
determining a second score based on multiplying the target number of accesses by the access preference;
the distribution score is determined based on the subtraction of the second score and the first score.
Optionally, the determining the first score based on the target load includes:
Summing the target load and the existing load to obtain a total load;
acquiring average existing loads of all candidate threads;
and subtracting the total load from the average existing load to determine a first score.
Optionally, the candidate threads are sequentially provided with thread numbers;
the determining a target thread from a plurality of the candidate threads based on the allocation score, comprising:
ranking a plurality of the candidate threads based on the allocation score;
based on the arrangement result, acquiring the thread number corresponding to the largest distribution score;
and if the thread number is a plurality of thread numbers, taking the candidate thread corresponding to the smallest thread number in the plurality of thread numbers as the target thread.
To achieve the above object, a second aspect of an embodiment of the present application provides a data access apparatus for a database, the database including a plurality of partitions, the data access apparatus comprising:
the first determining module is used for determining a cooperative distance task to be distributed based on a query request to the database;
the first acquisition module is used for acquiring the target access times of the to-be-allocated coroutine task to each partition;
The second acquisition module is used for acquiring the access preference degree of a plurality of candidate threads to each partition;
the prediction module is used for predicting the distribution score of the to-be-distributed coroutine task to the candidate thread based on the target access times and the access preference;
a second determining module configured to determine a target thread from a plurality of the candidate threads based on the allocation score;
and the allocation module is used for allocating the to-be-allocated coroutine task to the target thread, and accessing the partition by the target thread based on the to-be-allocated coroutine task.
To achieve the above object, a third aspect of the embodiments of the present application provides an electronic device, where the electronic device includes a memory, a processor, and the memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect.
To achieve the above object, a fourth aspect of the embodiments of the present application proposes a storage medium storing a computer program which, when executed by a processor, implements the method of the first aspect.
According to the data access method and device, the electronic equipment and the storage medium of the database, threads are not directly enabled to access the partitions of the database based on the query request of the database, the to-be-allocated coroutine task is determined based on the query request of the database, then the target access times of the to-be-allocated coroutine task to each partition are obtained, and the access preference degree of a plurality of candidate threads to each partition is obtained. The target access times can measure the access frequency of the coroutine task to be allocated to each partition, and the access preference can measure the access frequency of the candidate thread to each partition. And then, based on the target access times and the access preference, predicting the allocation score of the to-be-allocated coroutine task to the candidate threads, determining a target thread from a plurality of candidate threads based on the allocation score, allocating the to-be-allocated coroutine task to the target thread, and accessing the partition by the target thread based on the to-be-allocated coroutine task. The higher the allocation score of a certain candidate thread, the more the access frequency of the candidate thread to the partition is matched with the access frequency of the coroutine task to be allocated to the partition. Therefore, the application can allocate the to-be-allocated coroutine tasks accessing the same partition to the same target thread, and reduce the data overlapping degree accessed by each thread, thereby reducing the waiting and switching cost caused by the competition among threads, greatly consuming the computing resource and further improving the access efficiency of the database.
Drawings
FIG. 1 is a flow chart of a method for accessing data of a database according to one embodiment of the present application;
FIG. 2 is a flow chart of step 103 of FIG. 1 for obtaining access preference;
FIG. 3 is a flow chart of step 104 of FIG. 1 for determining an assigned score;
FIG. 4 is a flow chart of determining a first score of step 302 in FIG. 3;
FIG. 5 is a first flow chart of updating an access preference matrix provided by one embodiment of the present application;
FIG. 6 is a second flow diagram of updating an access preference matrix provided by one embodiment of the present application;
FIG. 7 is a schematic diagram of a specific implementation of a data access method according to an embodiment of the present application;
FIG. 8 is a block diagram of a data access device of a database according to an embodiment of the present application;
fig. 9 is a schematic hardware structure of an electronic device according to an embodiment of the present application.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
It should be noted that although functional block division is performed in a device diagram and a logic sequence is shown in a flowchart, in some cases, the steps shown or described may be performed in a different order than the block division in the device, or in the flowchart. The terms first, second and the like in the description and in the claims and in the above-described figures, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of the application only and is not intended to be limiting of the application.
With the rapid development of big data and the Internet, the data concurrency query and analysis efficiency is an important index for measuring a database system. In order to improve concurrency, a modern database system adopts multiple threads or multiple execution users to inquire, and cross-thread or inter-process data access competition is inevitably introduced. In an extreme scenario, when a large number of users need to read modified data and concentrate it in a certain area, the waiting and switching costs caused by inter-thread competition consume computing resources greatly, resulting in the occurrence of performance bottlenecks of the database system.
In view of this, the present application provides a data access method of a database, which is equivalent to a coroutine task adaptive allocation algorithm for reducing resource access competition. Firstly, packaging a query request into a coroutine task, and according to the access times of different coroutine tasks to access each partition, distributing the coroutine task accessing the same partition to the same thread as much as possible under the condition of considering the workload of each thread, so as to reduce the data overlapping degree accessed by each thread. Meanwhile, the algorithm can dynamically adjust the emphasis point of each thread for accessing the resource according to the running state of the current system. Because the thread executing coroutine task is sequential execution, the coroutine task belonging to the same thread does not have the competition relationship of parallel access resources, so the resource access competition of the whole database system can be effectively reduced.
In addition, the embodiment of the application also provides a data access device, electronic equipment and a storage medium of the database, aiming at reducing the waiting and switching cost caused by competition among threads to greatly consume computing resources and improving the concurrent access efficiency of the database when the database is read concurrently.
The data access method of the database provided by the embodiment of the application is applied to the server side, and can also be software running in the terminal or the server side. The server side can be configured as an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, and a cloud server for providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, basic cloud computing services such as big data and artificial intelligent platforms and the like; the software may be an application or the like that implements a data access method of the database, but is not limited to the above form.
The application is operational with numerous general purpose or special purpose computer system environments or configurations. For example: server computers, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, distributed computing environments that include any of the above systems or devices, and the like. The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiment of the application provides a data access method and device of a database, electronic equipment and a storage medium, and specifically, the following embodiment is used for explaining, and first describes the data access method of the database in the embodiment of the application.
Fig. 1 is an optional flowchart of a method for accessing data of a database according to an embodiment of the present application, where the database includes a plurality of partitions, the method for accessing data of the database may include, but is not limited to, steps 101 to 106.
Step 101, determining a cooperative journey task to be allocated based on a query request to a database;
102, obtaining target access times of a to-be-allocated coroutine task to each partition;
step 103, obtaining access preference degree of a plurality of candidate threads to each partition;
step 104, predicting the allocation score of the cooperative task to be allocated to the candidate thread based on the target access times and the access preference;
step 105, determining a target thread from a plurality of candidate threads based on the allocation score;
and step 106, distributing the to-be-distributed coroutine task to the target thread, and accessing the partition by the target thread based on the to-be-distributed coroutine task.
In steps 101 to 106 shown in the embodiment of the present application, the database includes a plurality of partitions, and different partitions are used to store different data resources. An allocation score for each candidate thread is predicted based on the target number of accesses and the access preference, and a target thread is determined based on the allocation score. And then distributing the to-be-distributed coroutine task to the target thread. In this way, the to-be-allocated coroutine tasks accessing the same partition can be allocated to the same target thread, and the data overlapping degree accessed by each target thread is reduced. Because the thread executing coroutine task is sequential execution, no competition relationship exists between coroutine tasks belonging to the same thread, the resource access competition of the whole database system can be effectively reduced, and the access efficiency of the database is improved.
The database generally stores a plurality of tables. One table may be used as one partition, or a plurality of tables may be used as one partition. In one example, one table stores teacher information, one table stores lesson information, and one table stores relationships (one-to-many) between teachers and lessons. The three tables correspond to the three partitions, respectively. For example, teacher information table as partitionCurriculum information table as partition->Relationship table between teacher and course as partition +.>
In step 101 of some embodiments, a coroutine task to be assigned is determined based on a query request to a database. A query request refers to a request issued by an object for querying data of a database. The to-be-allocated coroutine task refers to a coroutine task which is not allocated to the target thread yet, and is generated based on the query request. Multiple co-program tasks can be accommodated on the same thread, and the co-program tasks can run concurrently.
In one embodiment, step 101 includes:
determining a plurality of query partitions from the plurality of partitions based on the query request to the database;
based on a plurality of query partitions, packaging the query request into a plurality of to-be-allocated coroutine tasks; one to-be-allocated coroutine task corresponds to one query partition.
In one example, if an object needs to query a teacher's information and teach several courses, then the partition needs to be accessedObtaining teacher information while requiring access to the partition +.>The teacher was calculated to co-teach several classes. In this example, it may be determined that the query partition is 2 based on the query request, so that the coroutine task to be allocated is 2.
The method has the advantages that the query request is packaged into a plurality of to-be-allocated coroutine tasks based on the query partition, and one to-be-allocated coroutine task corresponds to one query partition, so that when the to-be-allocated coroutine task is executed by the target thread, the number of times of accessing across the partitions is reduced, and the database access efficiency is improved.
In step 102 of some embodiments, a target number of accesses to each partition for a coroutine task to be allocated is obtained. The target access frequency refers to the number of times that the partition needs to be accessed, and is used for measuring the access frequency to the partition. The execution optimizer can be called to obtain the target access times of the to-be-allocated coroutine task to each partition, or the to-be-allocated coroutine task can be analyzed to obtain the target access times of each partition.
In one example, the to-be-assigned corollary tasks include { query for information of Liu teacher, query Li Lao taught several courses, query for information of Liu teacher, query Liu Lao taught several courses }. Based on the information of 'inquiring Liu teacher' and 'inquiring Liu teacher' needs to access the partition The number of target accesses is 20. Based on 'inquiry Li Lao teaching several courses' and 'inquiry Liu Lao teaching several courses' need to access the partition +.>The target access number of (2) is 200. Finally, the to-be-assigned coroutine task pair partition in this example +.>Is 20 times and is divided into +.>The target access number of (2) is 200.
In another example, the to-be-allocated coroutine task of the above example may be divided into two to-be-allocated coroutine tasks. One to-be-allocated coroutine task comprises { inquiring information of Liu teacher, inquiring information of Liu teacher }, and the to-be-allocated coroutine task is partitionedThe number of target accesses is 20. Another to-be-allocated corollary task includes { query Li Lao teaches several courses, query Liu Lao teaches several courses }, then the to-be-allocated corollary task is>The target access number of (2) is 200. It should be noted that the number of the substrates,because the embodiment of the application adopts the allocation to the target thread based on the allocation score, different cooperative tasks to be allocated are executed by different threads with high probability, so if a certain cooperative task does not involve more than 2 partitions, the access competition among the threads can be further reduced, and the access efficiency of the database is further improved.
In step 103 of some embodiments, access preference for each partition by a plurality of candidate threads is obtained. The access preference is used to measure the frequency of accesses to the partition by the candidate thread. In one embodiment, step 103 includes: access preference for each partition is obtained based on the assigned coroutine task on the candidate thread.
In one embodiment, referring to fig. 2, step 103 includes:
step 201, constructing an access preference matrix based on a plurality of partitions and a plurality of candidate threads; each element in the access preference matrix is used for indicating the access preference degree of the candidate thread to the partition;
step 202, access preference is obtained from the access preference matrix.
In one example, assume that the database includesIn total m partitions, and assuming that the number of threads available for coroutine task execution is n, the preference matrix is accessed +.>Is +.>In which the elements->Indicating the access preference degree of the jth candidate thread to the ith partition and satisfying +.>. Initially, the initial value of each element in (1) is set to +.>I.e., it indicates that the access preference of each candidate thread to any partition is the same. After the access preference matrix is built, the elements are updated according to the assigned coroutine tasks to be assigned on the candidate threads, so that the access preference degree obtained from the access preference matrix is updated.
The method has the advantages that the access preference degree can be conveniently acquired based on the constructed access preference matrix, and the acquisition efficiency is improved.
In step 104 of some embodiments, an allocation score for allocation of the coroutine task to the candidate thread is predicted based on the target number of accesses and the access preference.
In one example, for candidate thread number j, a score is assigned。/>Indicating the number of target accesses to the ith partition,/-, for example>Indicating the access preference of the jth candidate thread to the ith partition. />Is a positive weight and can be adjusted according to specific requirements. />And (3) representing the matching degree of the target access times and the access preference degree of the candidate thread with the j number, if the partition with the larger target access times is just the partition with the highest access preference degree of the candidate thread with the j number, the item value is larger, and otherwise, the item value is smaller.
In one embodiment, referring to FIG. 3, step 104 comprises:
step 301, obtaining a target load of a cooperative task to be allocated and obtaining an existing load of a candidate thread;
step 302, determining a first score based on a target load and an existing load;
step 303, multiplying the target access times and the access preference degree to determine a second score;
At step 304, an allocation score is determined based on the second score subtracted from the first score.
Specifically, the target load refers to the calculated amount of the coroutine task to be allocated, and generally refers to how many CPU clock cycles the coroutine task needs to consume from the beginning to the end. Colloquially, several additions, subtractions, multiplications and divisions are required to obtain the final result. The load pressure of the candidate thread may be determined based on the target load and the existing load. The higher the target load, the higher the calculation amount required for indicating the coroutine task to be allocated, and the higher the load pressure of the candidate thread.
It should be noted that, referring to the above three table examples, the object needs to query information of a teacher and teach several courses. Then for the teacher partition of this table, a BTree index lookup is required, perhaps 10 accesses of data. For a relationship table between teacher and course, a full table scan may be required, requiring 100 accesses, at the cost of 10-5 clock cycles for CPU. The average existing load is independent of the co-program task to be allocated, and is related to the allocated co-program task to be allocated (also called the executing co-program task), for example, 10-6 clock cycles.
In this embodiment, in addition to the influence of the target number of accesses and the access preference degree on the allocation score, the influence of the target load and the existing load on the allocation score is also considered. The allocation score is determined based on the first score and the second score together, so that although the second score of a certain candidate thread is lower, the existing load corresponding to the candidate thread is added with the target load, the load pressure may be lower, and the lower first score can be obtained. The first score is thus subtracted from the second score such that the allocation score may be higher for the candidate thread than for other threads having a higher second score.
The embodiment has the advantages that the distribution score is determined based on the first score and the second score, so that the load pressure of the candidate threads is considered, the preference degree of the candidate threads for accessing the partition is considered, and the accuracy of determining the distribution score is improved.
In one embodiment, referring to FIG. 4, step 502 comprises:
step 401, summing the target load and the existing load to obtain a total load;
step 402, obtaining average existing loads of all candidate threads;
step 403, determining a first score based on the subtraction of the total load and the average existing load.
In this embodiment, for candidate thread number j, the first scoreWherein->Representing the existing load of candidate thread j, b representing the target load,/>Indicating average existing load +.>. The lower the first score, the lower the load pressure of the candidate thread, and thus the higher the score assigned to the candidate thread. This->And after the co-journey task to be allocated is allocated to the j candidate thread, the difference between the total load of the j candidate thread and the average existing load is represented, if the difference is smaller than the average load, the allocation score is positively contributed, and if the difference is larger than the average load, the difference is negatively contributed, and the difference is used for controlling load balancing.
The benefit of this embodiment is that in determining the first score, not only the target load and the existing load of the single candidate thread itself are taken into account, but also the influence of the average existing load on the first score is taken into account, further improving the accuracy of determining the first score, thereby helping to improve the accuracy of determining the assigned score.
In one embodiment, the assignment score is determined in step 404 based on the subtraction of the second score and the first score, and the following formula is specifically selected:
equation (1).
Wherein, the liquid crystal display device comprises a liquid crystal display device,and->Is a positive weight. The size of the weight may be set by time requirements, and the embodiment is not particularly limited.
It should be noted that the clock period b must be significantly greater in value than the access number a, soGeneral ratio->Much smaller. For example, to make two orders of magnitude equal, it is possible to +.>10++3->1. Of course this can be controlled by modifying the units, e.g. 10-3 clock cycles to a CPU cost unit, thereby adjusting +.>And->
In step 105 of some embodiments, a target thread is determined from a plurality of candidate threads based on the allocation score. The candidate thread corresponding to the largest allocation score may be the target thread. Candidate threads with an allocation score greater than a score threshold may also be targeted threads.
In one embodiment, the plurality of candidate threads are sequentially provided with thread numbers, step 105 comprising:
ranking the plurality of candidate threads based on the allocation score;
based on the arrangement result, obtaining the thread number corresponding to the maximum allocation score;
if the thread number is a plurality of thread numbers, the candidate thread corresponding to the smallest thread number in the plurality of thread numbers is taken as the target thread.
In one example, assume that there are 3 candidate threads. The thread numbers of these 3 candidate threads are 001, 002, and 003. The assignment scores of candidate threads corresponding to 001 are 90, respectively. 002 the corresponding candidate thread allocation score 90. 003 is assigned a score of 80. The maximum allocation score of 90 is obtained and the thread number for which the allocation score of 90 is obtained includes 001 and 002. Since the smallest thread number among 001 and 002 is 001, the candidate thread corresponding to 001 is taken as the target thread.
The embodiment has the advantages that the candidate threads are sequentially provided with the numbers in consideration of actual application, so that when the largest allocation fraction corresponds to the thread numbers, the target thread is directly determined based on the smallest thread number, some arithmetic logic can be reduced, and processing resources are saved. For example, when initializing, all candidate threads are not allocated to the cooperative task, and the matching scores of all candidate threads are the same, the thread number corresponding to the largest matching score definitely includes all candidate threads, and at this time, the candidate thread corresponding to the smallest thread number is directly used as the target thread, so that the efficiency of determining the target thread is improved.
In step 106 of some embodiments, the to-be-allocated coroutine task is allocated to the target thread, and the partition is accessed by the target thread based on the to-be-allocated coroutine task.
Referring to fig. 5, in an embodiment, after the to-be-allocated coroutine task is allocated to the target thread, the data access method of this embodiment further includes:
step 501, acquiring an initial value aiming at an element corresponding to a target thread in an access preference matrix;
step 502, obtaining the existing access times of the allocated coroutine task to be allocated of the target thread to each partition;
step 503, summing the existing access times and the target access times to obtain a first total partition access times of the target thread to each partition;
step 504, multiplying the initial value by the existing access times, and summing the multiplication result and the target access times to obtain the first single partition access times of the target thread to the single partition;
step 505, obtaining a first target update value based on a ratio between the first single partition access number and the first total partition access number;
step 506 replaces the initial value based on the first target update value to update the access preference matrix.
In one example, assume that the target number of accesses to be allocated to the coroutine task is And the target thread allocated by the cooperative task to be allocated is the j candidate thread. Acquisition element->The initial value is +.>. Acquiring the existing access times of the allocated coroutine task of the candidate thread to each partition, which is equivalent to acquiring the existing access times of all the unopened coroutine tasks on the j-th thread to all the partitions as +.>. Updating access preference degree of jth thread to ith partition in real time. Wherein (1)>Indicating the first total partition access times of all the non-ending coroutine tasks on the j-th thread to all the partitions after the coroutine task to be allocated is allocated to the j-th thread, < >>And the number of accesses of the j-th thread to the first single partition of the i-th partition after allocation is represented. Thread j>Updated to
The method has the advantages that after the to-be-allocated coroutine task is allocated to the target thread, each element corresponding to the target thread is updated according to the allocated to-be-allocated coroutine task on the target thread, and the accuracy of updating the matrix is improved.
Referring to fig. 6, in an embodiment, after step 506, the data access method of the present embodiment further includes:
step 601, responding to the end of the access of the to-be-allocated coroutine task to the database, and subtracting the number of the existing accesses from the number of the target accesses to obtain a second total partition access number of the target thread to each partition;
Step 602, multiplying the first target update value by the existing access times, and subtracting the multiplication result from the target access times to obtain the second single partition access times of the target thread to the single partition;
step 603, obtaining a second target update value based on a ratio between the second single partition access number and the second total partition access number;
step 604 replaces the first target update value based on the second target update value to update the access preference matrix.
In an example, responding to the end of the access of the to-be-allocated coroutine task to the database is equivalent to that when the execution of the to-be-allocated coroutine task is completed, the opposite updating operation is required to be performed on the variables. Taking the jth thread as an example, the second total partition access number isThe second single partition access number is +.>The second target update value is: />. Thread j>Updated to->
In an embodiment, ifIf the j-th thread has no executing coroutine task, then set +.>. This embodiment has the advantage of reducing the presence of infinite element values in the matrix due to the zero number of accesses of the second total partition, thereby affecting the stability of the access preference from the access preference matrix.
In one example, assuming the jth candidate thread is determined to be the target thread, the existing load of the jth thread is updated tob, the average load is updated to +.>. In response to the end of access to the database by the co-program task to be allocated, the existing load of the jth thread is updated to +.>b, the average load is updated to +.>
Specific implementation details of the present application are described in detail below in conjunction with fig. 7.
Referring to fig. 7, the embodiment of the present application specifically includes the following implementation details:
acquiring a query request, and packaging the query request into a cooperative task to be distributed;
according to the database execution optimizer, obtaining the target access times of the to-be-allocated coroutine task to each partitionAnd a target load b to be allocated with the coroutine task; as shown in fig. 7, the thicker the black arrow between the task and the plurality of partitions, the higher the number of target accesses, the target load is not shown;
obtaining the access preference degree of a plurality of candidate threads to each partition from the access preference matrix, wherein as shown in fig. 7, the thicker black arrows between the plurality of threads and the plurality of partitions are, the higher the access preference degree is;
calculating an allocation score of the coroutine task to be allocated for each candidate thread,
the to-be-allocated coroutine task is allocated to a candidate thread corresponding to the maximum allocation score, as shown in fig. 7, the to-be-allocated coroutine task is allocated to a thread 003 pointed by a dotted arrow, and the thread 003 accesses the partition based on the to-be-allocated coroutine task;
Assuming that the coroutine task is assigned to thread j, the parameter value is updated,/>b,/>
When the execution of the coroutine task is finished, updating the corresponding parameter value,/>b,/>
Referring to fig. 8, an embodiment of the present application further provides a data access device for a database, which may implement the data access method for a database, and fig. 8 is a block diagram of a module structure of the data access device for a database provided by the embodiment of the present application, where the database includes a plurality of partitions, and the data access device includes: a first determination module 701, a first acquisition module 702, a second acquisition module 703, a prediction module 704, a second determination module 705, and an allocation module 706. The first determining module 701 is configured to determine, based on a query request to a database, a cooperative task to be allocated; a first obtaining module 702, configured to obtain a target access number of each partition by a coroutine task to be allocated; a second obtaining module 703, configured to obtain access preference degrees of the multiple candidate threads to each partition; a prediction module 704, configured to predict an allocation score of a cooperative task to be allocated to a candidate thread based on the target access times and the access preference; a second determining module 705 for determining a target thread from the plurality of candidate threads based on the allocation score; the allocation module 706 is configured to allocate the to-be-allocated coroutine task to a target thread, and the target thread accesses the partition based on the to-be-allocated coroutine task.
In an embodiment, the data access device further comprises: and updating the module. The updating module is used for:
acquiring an initial value for each element of the access preference matrix; acquiring the existing access times of the allocated coroutine task of the candidate thread to each partition;
summing the existing access times and the target access times to obtain first total partition access times of the target thread to each partition;
multiplying the initial value by the existing access times, and summing the multiplication result and the target access times to obtain the first single partition access times of the target thread to the single partition;
obtaining a first target updating value based on the ratio between the first single partition access times and the first total partition access times; the initial value is replaced based on the first target update value to update the access preference matrix.
In an embodiment, the update module is further configured to:
responding to the end of the access of the to-be-allocated coroutine task to the database, and subtracting the target access times based on the existing access times to obtain a second total partition access times of the target thread to each partition;
multiplying the first target updated value by the existing access times, and subtracting the multiplication result from the target access times to obtain the second single partition access times of the target thread to the single partition;
Obtaining a second target updated value based on a ratio between the second partition access times and the second total partition access times;
the first target update value is replaced based on the second target update value to update the access preference matrix.
It should be noted that, the specific implementation manner of the data access device is substantially the same as the specific embodiment of the data access method of the database, and will not be described herein.
The embodiment of the application also provides electronic equipment, which comprises: the system comprises a memory, a processor, a program stored in the memory and capable of running on the processor, and a data bus for realizing connection communication between the processor and the memory, wherein the program realizes the data access method of the database when being executed by the processor. The electronic equipment can be any intelligent terminal including a tablet personal computer, a vehicle-mounted computer and the like.
Referring to fig. 9, fig. 9 illustrates a hardware structure of an electronic device according to another embodiment, the electronic device includes:
the processor 801 may be implemented by a general purpose CPU (Central Processing Unit ), microprocessor, application specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, etc. for executing relevant programs to implement the technical scheme provided by the embodiments of the present application;
The Memory 802 may be implemented in the form of a Read Only Memory (ROM), a static storage device, a dynamic storage device, or a random access Memory (Random Access Memory, RAM). The memory 802 may store an operating system and other application programs, and when the technical solutions provided in the embodiments of the present disclosure are implemented by software or firmware, relevant program codes are stored in the memory 802, and the processor 801 invokes a data access method for executing the database of the embodiments of the present disclosure;
an input/output interface 803 for implementing information input and output;
the communication interface 804 is configured to implement communication interaction between the device and other devices, and may implement communication in a wired manner (e.g., USB, network cable, etc.), or may implement communication in a wireless manner (e.g., mobile network, WIFI, bluetooth, etc.);
a bus 805 that transfers information between the various components of the device (e.g., the processor 801, the memory 802, the input/output interface 803, and the communication interface 804);
wherein the processor 801, the memory 802, the input/output interface 803, and the communication interface 804 implement communication connection between each other inside the device through a bus 805.
The embodiment of the application also provides a storage medium which is a computer readable storage medium and is used for computer readable storage, the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors so as to realize the data access method of the database.
The memory, as a non-transitory computer readable storage medium, may be used to store non-transitory software programs as well as non-transitory computer executable programs. In addition, the memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, the memory optionally includes memory remotely located relative to the processor, the remote memory being connectable to the processor through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The embodiments described in the embodiments of the present application are for more clearly describing the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application, and those skilled in the art can know that, with the evolution of technology and the appearance of new application scenarios, the technical solutions provided by the embodiments of the present application are equally applicable to similar technical problems.
It will be appreciated by those skilled in the art that the solutions shown in fig. 1-6 are not limiting on the embodiments of the application and may include more or fewer steps than shown, or certain steps may be combined, or different steps.
The above described apparatus embodiments are merely illustrative, wherein the units illustrated as separate components may or may not be physically separate, i.e. may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
Those of ordinary skill in the art will appreciate that all or some of the steps of the methods, systems, functional modules/units in the devices disclosed above may be implemented as software, firmware, hardware, and suitable combinations thereof.
The terms "first," "second," "third," "fourth," and the like in the description of the application and in the above figures, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the application described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It should be understood that in the present application, "at least one (item)" means one or more, and "a plurality" means two or more. "and/or" for describing the association relationship of the association object, the representation may have three relationships, for example, "a and/or B" may represent: only a, only B and both a and B are present, wherein a, B may be singular or plural. The character "/" generally indicates that the context-dependent object is an "or" relationship. "at least one of" or the like means any combination of these items, including any combination of single item(s) or plural items(s). For example, at least one (one) of a, b or c may represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", wherein a, b, c may be single or plural.
In the several embodiments provided by the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution in the form of a software product stored in a storage medium, including multiple instructions for causing an electronic device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing a program.
The preferred embodiments of the present application have been described above with reference to the accompanying drawings, and are not thereby limiting the scope of the claims of the embodiments of the present application. Any modifications, equivalent substitutions and improvements made by those skilled in the art without departing from the scope and spirit of the embodiments of the present application shall fall within the scope of the claims of the embodiments of the present application.

Claims (10)

1. A method of data access to a database, the database comprising a plurality of partitions, the method comprising:
determining a to-be-allocated coroutine task based on a query request to the database;
acquiring target access times of the to-be-allocated coroutine task to each partition;
obtaining access preference degrees of a plurality of candidate threads to each partition;
predicting the allocation score of the coroutine task to be allocated to the candidate thread based on the target access times and the access preference;
determining a target thread from a plurality of the candidate threads based on the allocation score;
and distributing the to-be-distributed coroutine task to the target thread, and accessing the partition by the target thread based on the to-be-distributed coroutine task.
2. The method of claim 1, wherein the obtaining access preference of the plurality of candidate threads to each partition comprises:
Constructing an access preference matrix based on the plurality of partitions and the plurality of candidate threads; wherein each element in the access preference matrix is used for indicating the access preference degree of the candidate thread to the partition;
and acquiring the access preference degree from the access preference matrix.
3. The data access method according to claim 2, wherein after the allocation of the to-be-allocated coroutine task to the target thread, the data access method further comprises:
acquiring an initial value aiming at an element corresponding to the target thread in the access preference matrix;
acquiring the existing access times of the allocated coroutine task to be allocated of the target thread to each partition;
summing the existing access times and the target access times to obtain first total partition access times of the target thread to each partition;
multiplying the initial value by the existing access times, and summing the multiplication result and the target access times to obtain the first single partition access times of the target thread to the single partition;
obtaining a first target updating value based on the ratio between the first single partition access times and the first total partition access times;
Replacing the initial value based on the first target update value to update the access preference matrix.
4. A data access method according to claim 3, wherein after replacing the initial value based on the target update value to update the access preference matrix, the data access method further comprises:
responding to the end of the access of the to-be-allocated coroutine task to the database, and subtracting the target access times from the existing access times to obtain second total partition access times of the target thread to each partition;
multiplying the first target update value by the existing access times, and subtracting the multiplication result from the target access times to obtain the second single partition access times of the target thread to the single partition;
obtaining a second target updated value based on a ratio between the second single partition access number and the second total partition access number;
replacing the first target update value based on the second target update value to update the access preference matrix.
5. The data access method according to any one of claims 1 to 4, wherein predicting an allocation score of the to-be-allocated coroutine task to the candidate thread based on the target access times and the access preference includes:
Acquiring a target load of the cooperative task to be allocated and acquiring the existing load of the candidate thread;
determining a first score based on the target load and the existing load;
determining a second score based on multiplying the target number of accesses by the access preference;
the distribution score is determined based on the subtraction of the second score and the first score.
6. The data access method of claim 5, wherein the determining a first score based on the target load comprises:
summing the target load and the existing load to obtain a total load;
acquiring average existing loads of all candidate threads;
and subtracting the total load from the average existing load to determine a first score.
7. The data access method according to any one of claims 1 to 4, wherein a plurality of the candidate threads are sequentially provided with thread numbers;
the determining a target thread from a plurality of the candidate threads based on the allocation score, comprising:
ranking a plurality of the candidate threads based on the allocation score;
based on the arrangement result, acquiring the thread number corresponding to the largest distribution score;
And if the thread number is a plurality of thread numbers, taking the candidate thread corresponding to the smallest thread number in the plurality of thread numbers as the target thread.
8. A data access apparatus for a database, the database comprising a plurality of partitions, the data access apparatus comprising:
the first determining module is used for determining a cooperative distance task to be distributed based on a query request to the database;
the first acquisition module is used for acquiring the target access times of the to-be-allocated coroutine task to each partition;
the second acquisition module is used for acquiring the access preference degree of a plurality of candidate threads to each partition;
the prediction module is used for predicting the distribution score of the to-be-distributed coroutine task to the candidate thread based on the target access times and the access preference;
a second determining module configured to determine a target thread from a plurality of the candidate threads based on the allocation score;
and the allocation module is used for allocating the to-be-allocated coroutine task to the target thread, and accessing the partition by the target thread based on the to-be-allocated coroutine task.
9. An electronic device comprising a memory, a processor, the memory storing a computer program, the processor implementing the method of accessing data of a database according to any of claims 1 to 7 when executing the computer program.
10. A storage medium storing a computer program, characterized in that the computer program, when executed by a processor, implements the data access method of the database of any one of claims 1 to 7.
CN202311108662.6A 2023-08-31 2023-08-31 Data access method and device of database, electronic equipment and storage medium Active CN116820786B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311108662.6A CN116820786B (en) 2023-08-31 2023-08-31 Data access method and device of database, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311108662.6A CN116820786B (en) 2023-08-31 2023-08-31 Data access method and device of database, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN116820786A true CN116820786A (en) 2023-09-29
CN116820786B CN116820786B (en) 2023-12-19

Family

ID=88141509

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311108662.6A Active CN116820786B (en) 2023-08-31 2023-08-31 Data access method and device of database, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116820786B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117076720A (en) * 2023-10-18 2023-11-17 北京燧原智能科技有限公司 Embedded table access method and device, electronic equipment and storage medium
CN117519931A (en) * 2023-11-09 2024-02-06 中国三峡建工(集团)有限公司 Coroutine scheduling method, system and equipment based on multi-core working thread

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7200721B1 (en) * 2002-10-09 2007-04-03 Unisys Corporation Verification of memory operations by multiple processors to a shared memory
CN107632889A (en) * 2017-06-28 2018-01-26 努比亚技术有限公司 A kind of method, equipment and computer-readable recording medium for realizing service degradation
CN110377416A (en) * 2018-12-04 2019-10-25 天津京东深拓机器人科技有限公司 Distributed subregion method for scheduling task and device
CN110727517A (en) * 2019-10-12 2020-01-24 福建顶点软件股份有限公司 Memory allocation method and device based on partition design
CN111078394A (en) * 2019-11-08 2020-04-28 苏州浪潮智能科技有限公司 GPU thread load balancing method and device
CN115408117A (en) * 2021-05-28 2022-11-29 腾讯科技(深圳)有限公司 Coroutine operation method and device, computer equipment and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7200721B1 (en) * 2002-10-09 2007-04-03 Unisys Corporation Verification of memory operations by multiple processors to a shared memory
CN107632889A (en) * 2017-06-28 2018-01-26 努比亚技术有限公司 A kind of method, equipment and computer-readable recording medium for realizing service degradation
CN110377416A (en) * 2018-12-04 2019-10-25 天津京东深拓机器人科技有限公司 Distributed subregion method for scheduling task and device
CN110727517A (en) * 2019-10-12 2020-01-24 福建顶点软件股份有限公司 Memory allocation method and device based on partition design
CN111078394A (en) * 2019-11-08 2020-04-28 苏州浪潮智能科技有限公司 GPU thread load balancing method and device
CN115408117A (en) * 2021-05-28 2022-11-29 腾讯科技(深圳)有限公司 Coroutine operation method and device, computer equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
宋广华: "多线程内存数据库服务器设计", 计算机工程与应用, no. 18, pages 107 - 110 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117076720A (en) * 2023-10-18 2023-11-17 北京燧原智能科技有限公司 Embedded table access method and device, electronic equipment and storage medium
CN117076720B (en) * 2023-10-18 2024-02-02 北京燧原智能科技有限公司 Embedded table access method and device, electronic equipment and storage medium
CN117519931A (en) * 2023-11-09 2024-02-06 中国三峡建工(集团)有限公司 Coroutine scheduling method, system and equipment based on multi-core working thread

Also Published As

Publication number Publication date
CN116820786B (en) 2023-12-19

Similar Documents

Publication Publication Date Title
CN116820786B (en) Data access method and device of database, electronic equipment and storage medium
US10606654B2 (en) Data processing method and apparatus
US10310908B2 (en) Dynamic usage balance of central processing units and accelerators
Mishra et al. Esp: A machine learning approach to predicting application interference
Nghiem et al. Towards efficient resource provisioning in MapReduce
US20160328273A1 (en) Optimizing workloads in a workload placement system
US20170024242A9 (en) Techniques to manage virtual classes for statistical tests
CN109447274B (en) Distributed system for performing machine learning and method thereof
CN110134516A (en) Finance data processing method, device, equipment and computer readable storage medium
US11030169B1 (en) Data re-sharding
CN104202373A (en) Method and system for migrating mobile cloud computing
CN107729353B (en) Distributed system for performing machine learning and method thereof
CN114667507A (en) Resilient execution of machine learning workload using application-based profiling
CN109032511A (en) Data storage method, server and storage medium
CN106843769A (en) A kind of interface data caching method, device and computing device
KR102543838B1 (en) Method and appartus for obtaining information
JP2009037369A (en) Resource assignment method to database server
US9703573B1 (en) Interposer for dynamic mapping of API calls
US11106670B2 (en) Local identifiers for database objects
Huang et al. Performance and replica consistency simulation for quorum-based NoSQL system cassandra
WO2022267364A1 (en) Information recommendation method and device, and storage medium
Ghazali et al. CLQLMRS: improving cache locality in MapReduce job scheduling using Q-learning
CN110247802B (en) Resource configuration method and device for cloud service single-machine environment
US8521721B2 (en) Custom operators for a parallel query engine
US9348359B2 (en) Updating a desired tick rate for a kernel

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