TW201828119A - Data synchronizing method and device avoiding the situation that some Threads have completed the synchronizing mission, but the other Threads in the same mission are still at the waiting state - Google Patents

Data synchronizing method and device avoiding the situation that some Threads have completed the synchronizing mission, but the other Threads in the same mission are still at the waiting state Download PDF

Info

Publication number
TW201828119A
TW201828119A TW106102729A TW106102729A TW201828119A TW 201828119 A TW201828119 A TW 201828119A TW 106102729 A TW106102729 A TW 106102729A TW 106102729 A TW106102729 A TW 106102729A TW 201828119 A TW201828119 A TW 201828119A
Authority
TW
Taiwan
Prior art keywords
synchronization
data
thread
threads
synchronized
Prior art date
Application number
TW106102729A
Other languages
Chinese (zh)
Other versions
TWI731926B (en
Inventor
賈元喬
蘇艷
Original Assignee
阿里巴巴集團服務有限公司
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 阿里巴巴集團服務有限公司 filed Critical 阿里巴巴集團服務有限公司
Priority to TW106102729A priority Critical patent/TWI731926B/en
Publication of TW201828119A publication Critical patent/TW201828119A/en
Application granted granted Critical
Publication of TWI731926B publication Critical patent/TWI731926B/en

Links

Abstract

The embodiment of the present invention provides a method to generate the synchronized Threads that are expected to operate based on the to-be-synchronized data amount in the source database and the priority grades of the synchronizing mission. Proceed Thread allocation according to the number of synchronized Threads that are expected to operate, and synchronize the allocated Threads for the said to-be-synchronized data to the target database. Based on the embodiment of the present invention, Threads can be dynamically allocated with respect to the practical situation of the synchronizing mission, avoiding the situation that some Threads have completed the synchronizing mission, but the other Threads in the same mission are still at the waiting state, thereby increasing the efficiency and stability of data synchronization.

Description

一種資料同步方法和裝置  Data synchronization method and device  

本申請涉及網際網路技術領域,特別是涉及一種資料同步方法和一種資料同步裝置。 The present application relates to the field of Internet technologies, and in particular, to a data synchronization method and a data synchronization device.

資料同步任務是針對不同資料庫之間的資料同步而創建的一系列週期排程的任務。在一個大型的資料排程系統中,經常會在同一時間運行有大量的資料同步任務。例如將HDFS(Hadoop Distributed File System,Hadoop分佈式文件系統)的資料同步至mySQL(關係型資料庫管理系統),或者從HDFS同步資料至Hbase(Hadoop Database,分佈式儲存系統)。 A data synchronization task is a series of periodic scheduling tasks created for data synchronization between different databases. In a large data scheduling system, there are often a large number of data synchronization tasks running at the same time. For example, the data of HDFS (Hadoop Distributed File System) is synchronized to mySQL (relational database management system), or from HDFS synchronization data to Hbase (Hadoop Database, distributed storage system).

在使用資料同步任務將源資料庫的資料同步至目標資料庫時,用戶通常需要預先設置一個同步執行緒數,同步控制器根據預設的同步執行緒數叫用相應的執行緒,分發到一個或多個同步處理設備,由同步處理設備進行資料同步處理。然而,當某個同步任務的待同步資料的資料量較大,如果將該同步任務的執行緒分發到比較繁忙的同步處理設備,其無法叫用滿足預設的同步執行緒數進行同步, 可能部分執行緒已經完成同步任務,而同一任務的其他執行緒還處於等待狀態,從而導致整個同步任務的平均同步速度較低。因此,目前的資料同步方式無法有效利用同步處理設備的同步處理能力,存在著資料同步效率較低的問題。 When using the data synchronization task to synchronize the data of the source database to the target database, the user usually needs to set a synchronization thread in advance, and the synchronization controller calls the corresponding thread according to the preset synchronization thread number and distributes it to a Or a plurality of synchronous processing devices, and the data processing is performed by the synchronous processing device. However, when the amount of data of the data to be synchronized of a synchronization task is large, if the thread of the synchronization task is distributed to the relatively busy synchronization processing device, it cannot be synchronized by using the preset synchronization thread number. Some threads have completed the synchronization task, while other threads of the same task are still waiting, resulting in a lower average synchronization speed for the entire synchronization task. Therefore, the current data synchronization method cannot effectively utilize the synchronization processing capability of the synchronous processing device, and there is a problem that the data synchronization efficiency is low.

鑒於上述問題,提出了本申請實施例以便提供一種克服上述問題或者至少部分地解決上述問題的一種資料同步方法和相應的一種資料同步裝置。 In view of the above problems, embodiments of the present application have been made in order to provide a data synchronization method and a corresponding data synchronization apparatus that overcome the above problems or at least partially solve the above problems.

為了解決上述問題,本申請公開了一種資料同步方法,包括:根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數;按照期望運行的同步執行緒數進行執行緒配置,並採用配置的執行緒針對所述待同步資料同步至目標資料庫。 In order to solve the above problem, the present application discloses a data synchronization method, including: generating a synchronization execution thread that is expected to run according to the data amount of the data to be synchronized in the source database and the priority of the synchronization task; The number is configured by the thread, and the configured thread is used to synchronize the data to be synchronized to the target database.

可選地,所述按照期望運行的同步執行緒數進行執行緒配置包括:判斷所述期望運行的同步執行緒數是否大於運行所需的同步執行緒數;若是,則根據所述期望運行的同步執行緒數和所述運行所需的同步執行緒數的差值,補充配置相應的執行緒。 Optionally, performing the thread configuration according to the synchronization execution thread that is expected to run includes: determining whether the synchronization execution number of the desired operation is greater than a synchronization execution number required for operation; if yes, operating according to the expected operation The difference between the number of synchronization threads and the number of synchronization threads required for the operation is supplemented by the corresponding thread.

可選地,在所述根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數之 前,所述方法還包括:從用戶提交的資料同步任務中,獲取所述同步任務的優先級,並從保存有待同步資料的所述源資料庫中,獲取所述待同步資料的資料量。 Optionally, before the generating the number of synchronization threads to be run according to the data amount of the data to be synchronized and the priority of the synchronization task in the source database, the method further includes: from the data synchronization task submitted by the user, Obtaining a priority of the synchronization task, and acquiring the data amount of the to-be-synchronized data from the source database in which the data to be synchronized is saved.

可選地,所述根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數包括:查找針對所述待同步資料的資料量和同步任務的優先級的平均同步速率;利用所述平均同步速率、同步處理設備的最大同步速率和所述同步處理設備可供同步處理的執行緒數,計算所述期望運行的同步執行緒數。 Optionally, the generating, according to the data amount of the data to be synchronized in the source database and the priority of the synchronization task, generating the synchronization execution thread that is expected to run includes: searching for the data amount of the to-be-synchronized data and the priority of the synchronization task The average synchronization rate is calculated by using the average synchronization rate, the maximum synchronization rate of the synchronization processing device, and the number of threads that the synchronization processing device can use for synchronization processing.

可選地,在所述判斷所述期望運行的同步執行緒數是否大於運行所需的同步執行緒數之前,所述方法還包括:從待與源資料庫進行資料同步的所述目標資料庫中,獲取所述運行所需的同步執行緒數。 Optionally, before the determining whether the expected number of synchronization threads to be run is greater than the number of synchronization threads required for operation, the method further includes: the target database from which data is to be synchronized with the source database. Get the number of synchronization threads required for the run.

可選地,在所述採用配置的執行緒針對所述待同步資料同步至目標資料庫之前,所述方法還包括:按照所述運行所需的同步執行緒數將所述待同步資料拆分成多個待同步資料塊;所述採用配置的執行緒針對所述待同步資料同步至目標資料庫為:將用於同步各個待同步資料塊的同步執行緒,排程至同步處理設備,以由所述同步處理設備處理所述同步執行緒。 Optionally, before the using the configured thread to synchronize the to-be-synchronized data to the target database, the method further includes: splitting the to-be-synchronized data according to the synchronization execution number required for the operation And a plurality of to-be-synchronized data blocks; wherein the configured thread is synchronized to the target database for the data to be synchronized: a synchronization thread for synchronizing each to-be-synchronized data block is scheduled to a synchronization processing device, The synchronization thread is processed by the synchronization processing device.

可選地,所述採用配置的執行緒針對所述待同步資料同步至目標資料庫包括:將執行緒屬性滿足預設條件的至少一個同步執行緒優先發送至所述同步處理設備。 Optionally, the using the configured thread to synchronize the data to be synchronized to the target database comprises: sending at least one synchronization thread that meets a preset condition to the synchronization processing device to the synchronization processing device.

可選地,所述預設條件包括以下至少一種:所述至少一個同步執行緒屬於同一個資料同步任務、待處理時間大於預設時間閾值、對應同步任務的優先級大於預設優先級閾值、單個同步處理設備可同步處理。 Optionally, the preset condition includes at least one of the following: the at least one synchronization thread belongs to the same data synchronization task, the to-be-processed time is greater than a preset time threshold, the priority of the corresponding synchronization task is greater than a preset priority threshold, A single synchronous processing device can be processed synchronously.

可選地,所述採用配置的執行緒針對所述待同步資料同步至目標資料庫包括:將所述同步執行緒優先發送至可供同步處理的最大執行緒數大於預設執行緒數閾值的同步處理設備。 Optionally, the using the configured thread to synchronize the data to be synchronized to the target database comprises: sending the synchronization thread preferentially to a maximum number of threads available for synchronization processing that is greater than a preset number of threads threshold Synchronize the device.

為了解決上述問題,本申請還公開了一種資料同步裝置,包括:同步執行緒數生成模組,用於根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數;同步處理模組,用於按照期望運行的同步執行緒數進行執行緒配置,並採用配置的執行緒針對所述待同步資料同步至目標資料庫。 In order to solve the above problem, the present application further discloses a data synchronization device, comprising: a synchronization execution number generation module, configured to generate a synchronization of a desired operation according to a data amount of a data to be synchronized in a source database and a priority of a synchronization task. The thread is executed; the synchronization processing module is configured to perform thread configuration according to the number of synchronization threads that are expected to be run, and synchronize the data to be synchronized to the target database by using the configured thread.

可選地,所述同步處理模組包括:同步執行緒數判斷子模組,用於判斷所述期望運行的同步執行緒數是否大於運行所需的同步執行緒數,若是,則叫用執行緒補充子模組; 執行緒補充子模組,用於根據所述期望運行的同步執行緒數和所述運行所需的同步執行緒數的差值,補充配置相應的執行緒。 Optionally, the synchronization processing module includes: a synchronization execution number determination sub-module, configured to determine whether the synchronization execution number of the desired operation is greater than a synchronization execution number required for operation, and if yes, execute the execution The thread complementing the sub-module; the thread complementing the sub-module, configured to supplement the configuration of the corresponding thread according to the difference between the number of synchronization threads that are expected to run and the number of synchronization threads required for the operation.

可選地,所述裝置還包括:優先級及資料量獲取模組,用於從用戶提交的資料同步任務中,獲取所述同步任務的優先級,並從保存有待同步資料的源資料庫中,獲取所述待同步資料的資料量。 Optionally, the device further includes: a priority and a data volume obtaining module, configured to acquire a priority of the synchronization task from a data synchronization task submitted by the user, and from a source database that stores the data to be synchronized Obtaining the amount of data of the data to be synchronized.

可選地,所述同步執行緒數生成模組包括:平均同步速率查找子模組,用於查找針對所述待同步資料的資料量和同步任務的優先級的平均同步速率;同步執行緒數計算子模組,用於利用所述平均同步速率、同步處理設備的最大同步速率和所述同步處理設備可供同步處理的執行緒數,計算所述期望運行的同步執行緒數。 Optionally, the synchronization execution number generation module includes: an average synchronization rate search sub-module, configured to search for an average synchronization rate of the data amount of the to-be-synchronized data and the priority of the synchronization task; And a calculation submodule, configured to calculate the number of synchronization threads of the desired operation by using the average synchronization rate, a maximum synchronization rate of the synchronization processing device, and a number of threads that the synchronization processing device can use for synchronization processing.

可選地,所述裝置還包括:運行所需同步執行緒數獲取模組,用於從待與源資料庫進行資料同步的目標資料庫中,獲取所述運行所需的同步執行緒數。 Optionally, the device further includes: a running synchronization execution number acquisition module, configured to acquire the synchronization execution number required for the operation from the target data database to be synchronized with the source database.

可選地,所述裝置還包括:待同步資料拆分模組,用於按照所述運行所需的同步執行緒數將所述待同步資料拆分成多個待同步資料塊;所述同步處理模組具體用於:將用於同步各個待同步資料塊的同步執行緒,排程至同步處理設備,以由所述同步處理設備處理所述同步執行 緒。 Optionally, the device further includes: a data splitting module to be synchronized, configured to split the to-be-synchronized data into a plurality of to-be-synchronized data blocks according to the synchronization execution number required for the operation; The processing module is specifically configured to: schedule a synchronization thread for synchronizing each data block to be synchronized, and schedule the synchronization thread to the synchronization processing device to process the synchronization thread by the synchronization processing device.

可選地,所述同步處理模組具體用於:將執行緒屬性滿足預設條件的至少一個同步執行緒優先發送至所述同步處理設備。 Optionally, the synchronization processing module is specifically configured to: send the at least one synchronization thread that meets the preset condition to the synchronization processing device.

可選地,所述預設條件包括以下至少一種:所述至少一個同步執行緒屬於同一個資料同步任務、待處理時間大於預設時間閾值、對應同步任務的優先級大於預設優先級閾值、單個同步處理設備可同步處理。 Optionally, the preset condition includes at least one of the following: the at least one synchronization thread belongs to the same data synchronization task, the to-be-processed time is greater than a preset time threshold, the priority of the corresponding synchronization task is greater than a preset priority threshold, A single synchronous processing device can be processed synchronously.

可選地,所述同步處理設備包括多個,所述同步處理模組具體用於:將所述同步執行緒優先發送至可供同步處理的最大執行緒數大於預設執行緒數閾值的同步處理設備。 Optionally, the synchronization processing device includes multiple, the synchronization processing module is specifically configured to: send the synchronization thread preferentially to the synchronization that the maximum number of threads available for synchronization processing is greater than a preset threshold number threshold Processing equipment.

本申請實施例包括以下優點: Embodiments of the present application include the following advantages:

根據本申請實施例,透過根據源資料庫中待同步資料的資料量和同步任務的優先級生成期望運行的同步執行緒數,根據期望運行的同步執行緒數配置相應數量的執行緒進行資料同步,從而可以針對於同步任務的實際情況動態配置執行緒,避免出現部分執行緒已經完成同步任務,而同一任務的其他執行緒還處於等待狀態的情況,提升了資料同步的效率和穩定性。而且,根據同步任務的優先級動態調整期望運行的同步執行緒數,使得重要程度較高的同步任務可以優先得到處理。 According to the embodiment of the present application, the number of synchronization threads expected to run is generated according to the data amount of the data to be synchronized in the source database and the priority of the synchronization task, and the corresponding number of threads are configured according to the number of synchronization execution threads that are expected to be run. Therefore, the thread can be dynamically configured for the actual situation of the synchronization task, to avoid the situation that some threads have completed the synchronization task, and other threads of the same task are still in the waiting state, which improves the efficiency and stability of data synchronization. Moreover, the number of synchronization threads that are expected to run is dynamically adjusted according to the priority of the synchronization task, so that the synchronization tasks with higher importance can be processed preferentially.

301‧‧‧同步執行緒數生成模組 301‧‧‧Synchronous thread generation module

302‧‧‧同步處理模組 302‧‧‧Synchronization Processing Module

401‧‧‧優先級及資料量獲取模組 401‧‧‧Priority and data acquisition module

402‧‧‧同步執行緒數獲取模組 402‧‧‧Synchronous thread acquisition module

403‧‧‧同步執行緒數生成模組 403‧‧‧Synchronous thread generation module

404‧‧‧同步處理模組 404‧‧‧Synchronization Processing Module

圖1是本申請的一種資料同步方法實施例一的步驟流程圖;圖2是本申請的一種資料同步方法實施例二的步驟流程圖;圖3是本申請的一種資料同步裝置實施例一的結構方塊圖;圖4是本申請的一種資料同步裝置實施例二的結構方塊圖。 1 is a flow chart of a first embodiment of a data synchronization method of the present application; FIG. 2 is a flow chart of a second embodiment of a data synchronization method of the present application; FIG. 3 is a first embodiment of a data synchronization device of the present application. Figure 4 is a block diagram showing the structure of a second embodiment of a data synchronizing apparatus of the present application.

為使本申請的上述目的、特徵和優點能夠更加明顯易懂,下面結合附圖和具體實施方式對本申請作進一步詳細的說明。 The above described objects, features and advantages of the present application will become more apparent and understood.

參照圖1,示出了本申請的一種資料同步方法實施例一的步驟流程圖,具體可以包括如下步驟: Referring to FIG. 1 , a flow chart of the steps of the first embodiment of the data synchronization method of the present application is shown, which may specifically include the following steps:

步驟101,根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數。 Step 101: Generate, according to the data volume of the data to be synchronized in the source database and the priority of the synchronization task, the number of synchronization threads that are expected to run.

需要說明的是,期望運行的同步執行緒數可以為由用戶預先設置的首輪同步執行緒數或多輪同步執行緒數。因為用戶無法得知本次同步任務中待同步資料的情況和同步處理設備的運行情況,或者用戶並不瞭解如何設置,所設置的同步執行緒數可能與運行同步時實際所需的同步執行緒數並不匹配,從而導致同步時將同步執行緒分發到繁忙的同步處理設備上;或者用戶將期望運行的同步執行緒數 設置成一個固定值,從而導致同步任務得不到合理的同步處理資源分配而影響同步效率。此外,不同資料的同步任務的重要程式不相同,而同步控制器將各個同步任務平等對待,導致重要的同步執行緒因得不到處理資源而無法優先同步。因此,利用目前的資料同步方式進行資料同步,可能會導致上述的問題,從而最終導致資料同步效率較低,同步任務的處理也缺乏穩定性。 It should be noted that the number of synchronization threads that are expected to run may be the number of first-time synchronization threads or multiple rounds of synchronization threads preset by the user. Because the user cannot know the situation of the data to be synchronized and the running status of the synchronous processing device in this synchronization task, or the user does not know how to set it, the number of synchronization threads set may be the synchronization thread actually needed when running the synchronization. The number does not match, causing the synchronization thread to be distributed to the busy synchronous processing device during synchronization; or the user sets the number of synchronous threads that are expected to run to a fixed value, resulting in a synchronization task not being properly synchronized. Distribution affects synchronization efficiency. In addition, the important programs of the synchronization tasks of different data are different, and the synchronization controller treats each synchronization task equally, resulting in important synchronization threads failing to prioritize synchronization due to lack of processing resources. Therefore, using the current data synchronization method for data synchronization may lead to the above problems, which ultimately leads to low data synchronization efficiency and lack of stability in the processing of synchronization tasks.

本申請實施例的具體實現中,可以利用源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數。實際應用中,用戶可以提交一個資料同步任務中,該資料同步任務通常包含有同步任務優先級的相關資訊,因此可以從中獲取同步任務的優先級。針對用戶提交的資料同步任務,可以從待同步資料來源的源資料庫中,獲取同步資料的資料量。當然,本領域技術人員可以採用其他途徑獲取資料量和優先級等的資訊,例如在資料同步任務中嵌入待同步資料的資料量和同步任務的優先級等的資訊,以便於從提交的資料同步任務中直接獲取資料量和優先級。 In the specific implementation of the embodiment of the present application, the amount of data to be synchronized in the source database and the priority of the synchronization task may be utilized to generate a synchronization execution number of the desired operation. In an actual application, a user can submit a data synchronization task, which usually includes information about the priority of the synchronization task, so that the priority of the synchronization task can be obtained therefrom. For the data synchronization task submitted by the user, the amount of data of the synchronization data can be obtained from the source database of the data source to be synchronized. Of course, those skilled in the art may use other means to obtain information such as the amount of data and priority, such as embedding information of the data to be synchronized and the priority of the synchronization task in the data synchronization task, so as to synchronize from the submitted data. Get the amount of data and priority directly in the task.

根據資料量和優先級生成期望運行的同步執行緒數的具體方式可以有多種。例如,可以預設一個資料量-優先級-平均同步速率的對照表,對照表中不同的資料量和優先級的組合對應一個特定的平均同步速率。根據資料量和優先級查找到對應的平均同步速率。將查找的平均同步速率,處以同步處理設備上每個CPU(Central Processing Unit,中央處理器)可以運行的同步速率,可確定同步所需的CPU數量,可以將該CPU數量作為期望運行的同步執行緒數。 There are many ways to generate the number of synchronous threads that you want to run based on the amount of data and priority. For example, a data amount-priority-average synchronization rate comparison table may be preset, and a combination of different data amounts and priorities in the comparison table corresponds to a specific average synchronization rate. Find the corresponding average synchronization rate based on the amount of data and priority. The average synchronization rate to be searched, at the synchronization rate that each CPU (Central Processing Unit) on the synchronous processing device can run, can determine the number of CPUs required for synchronization, and can execute the number of CPUs as synchronous execution of the desired operation. Number of threads.

步驟102,按照期望運行的同步執行緒數進行執行緒配置,並採用配置的執行緒針對所述待同步資料同步至目標資料庫。 Step 102: Perform thread configuration according to the number of synchronization execution threads that are expected to be run, and synchronize the data to be synchronized to the target database by using the configured thread.

可以按照期望運行的同步執行緒數,對同步執行緒進行配置。配置的方式可以有多種,例如可以根據期望運行的同步執行緒數與同步運行實際所需的同步執行緒數的差值,配置相應的虛擬執行緒,利用配置的虛擬執行緒將同步處理設備上的部分CPU置於待機狀態並暫停處理其他同步任務,以保證同步處理設備有足夠的資源處理該資料同步任務;當期望運行的同步執行緒數與同步運行實際所需的同步執行緒數相同,則可以直接按照期望運行的同步執行緒數,配置相應的實體執行緒。 The synchronization thread can be configured according to the number of synchronization threads that you want to run. There are various ways to configure the configuration. For example, you can configure the corresponding virtual thread according to the difference between the number of synchronous threads that you want to run and the number of synchronous threads that you need to run synchronously. Part of the CPU is placed in the standby state and pauses to process other synchronization tasks to ensure that the synchronization processing device has sufficient resources to process the data synchronization task; when the number of synchronization threads expected to run is the same as the number of synchronization threads actually required for the synchronous operation, You can configure the corresponding entity thread directly according to the number of synchronization threads you want to run.

可以採用配置的實體執行緒和/或虛擬執行緒同步處理待同步資料。實際應用中,可以先將待同步資料拆分成多個待同步資料塊,每個配置的執行緒分別用於同步多個待同步資料塊。根據同步處理設備的剩餘處理資源,將多個執行緒排程至一個或多個同步處理設備,由同步處理設備將多個待同步資料塊同步至目標資料庫。 The configured entity thread and/or virtual thread synchronization can be used to process the data to be synchronized. In an actual application, the data to be synchronized may be first split into a plurality of data blocks to be synchronized, and each configured thread is used to synchronize a plurality of data blocks to be synchronized. According to the remaining processing resources of the synchronization processing device, the plurality of threads are scheduled to one or more synchronization processing devices, and the plurality of to-be-synchronized data blocks are synchronized by the synchronization processing device to the target data library.

在同步控制器將同步執行緒排程至同步處理設備時,可以判斷同步運行實際所需的同步執行緒數是否大於期望運行的同步執行緒數,根據判斷結果進行不同方式的排 程。 When the synchronization controller schedules the synchronization thread to the synchronization processing device, it can be determined whether the number of synchronous execution threads actually required for the synchronous operation is greater than the number of synchronous execution threads that are expected to be run, and the scheduling is performed according to the determination result.

例如,當同步運行實際所需的同步執行緒數大於期望運行的同步執行緒數,同步控制器可以採用多機多執行緒的資料同步模式,準備針對該同步任務配置的第一輪實體執行緒的排程,優先發送等待時間最長、優先級最高且屬於相同同步任務的實體執行緒至多個同步處理設備,以保證該同步任務的各個執行緒的可以得到優先處理,避免某個執行緒已經完成同步,而同屬一個同步任務的其他執行緒還處於等待處理的狀態,影響到該同步任務的平均同步速率。 For example, when the number of synchronization threads actually required for synchronous operation is greater than the number of synchronization threads expected to run, the synchronization controller may adopt a data synchronization mode of multi-machine multi-thread to prepare a first round entity thread configured for the synchronization task. The scheduling of the thread that has the longest waiting time and the highest priority and belongs to the same synchronization task is sent to multiple synchronization processing devices to ensure that the threads of the synchronization task can be preferentially processed to avoid a certain thread having been completed. Synchronization, while other threads that belong to the same synchronization task are still waiting for processing, affecting the average synchronization rate of the synchronization task.

當同步運行實際所需的同步執行緒數小於期望運行的同步執行緒數,同步控制器可以採用單機多執行緒的資料同步模式,準備針對該同步任務配置的實體執行緒和虛擬執行緒的排程,將等待時間最長、優先級最高且屬於相同同步任務的執行緒,優先發送至某一個剩餘處理資源可以支持期望運行的同步執行緒數的同步處理設備上;如果沒有滿足條件的同步處理設備,可以優先選擇剩餘處理資源最多的一個同步處理設備作為發送對象。 When the number of synchronous threads required for synchronous operation is smaller than the number of synchronous threads that are expected to run, the synchronous controller can use the data synchronization mode of the single-machine multi-thread to prepare the physical thread and the virtual thread row configured for the synchronization task. The thread that has the longest waiting time, the highest priority, and belongs to the same synchronous task, is preferentially sent to a synchronous processing device that can support the number of synchronous threads that are expected to run; if there is no synchronous processing device that satisfies the condition , a synchronization processing device with the most remaining processing resources can be preferentially selected as the transmission target.

當然,本領域技術人員可以根據實際情況採用單機單執行緒、多機單執行緒等的資料同步模式進行排程,排程時可以根據同步處理設備的處理資源進行負載均衡排程,也可以隨機排程,本申請實施例對此不作限制。 Certainly, those skilled in the art can use the data synchronization mode of a single machine single thread and a single machine single thread to perform scheduling according to actual conditions, and the load balancing schedule can be performed according to the processing resources of the synchronous processing device during scheduling, or can be randomized. The scheduling is not limited in this embodiment of the present application.

根據本申請實施例,透過根據源資料庫中待同步資料的資料量和同步任務的優先級生成期望運行的同步執行緒 數,根據期望運行的同步執行緒數配置相應數量的執行緒進行資料同步,從而可以針對於同步任務的實際情況動態配置執行緒,避免出現部分執行緒已經完成同步任務,而同一任務的其他執行緒還處於等待狀態的情況,提升了資料同步的效率和穩定性。而且,根據同步任務的優先級動態調整期望運行的同步執行緒數,使得重要程度較高的同步任務可以優先得到處理。 According to the embodiment of the present application, the number of synchronization threads expected to run is generated according to the data amount of the data to be synchronized in the source database and the priority of the synchronization task, and the corresponding number of threads are configured according to the number of synchronization execution threads that are expected to be run. Therefore, the thread can be dynamically configured for the actual situation of the synchronization task, to avoid the situation that some threads have completed the synchronization task, and other threads of the same task are still in the waiting state, which improves the efficiency and stability of data synchronization. Moreover, the number of synchronization threads that are expected to run is dynamically adjusted according to the priority of the synchronization task, so that the synchronization tasks with higher importance can be processed preferentially.

參照圖2,示出了本申請的一種資料同步方法實施例二的步驟流程圖,具體可以包括如下步驟: Referring to FIG. 2, a flow chart of the steps of the second embodiment of the data synchronization method of the present application is shown. Specifically, the method may include the following steps:

步驟201,從用戶提交的資料同步任務中,獲取所述同步任務的優先級,並從保存有待同步資料的源資料庫中,獲取所述待同步資料的資料量。 In step 201, the priority of the synchronization task is obtained from the data synchronization task submitted by the user, and the data amount of the to-be-synchronized data is obtained from the source database in which the data to be synchronized is saved.

具體的實現中,在需要進行資料同步時,用戶可以在客戶端創建資料同步任務並提交給相應的同步處理伺服器。在創建資料同步任務時,客戶端可以根據待同步資料的重要程度生成相應的優先級,並包含在資料同步任務中,因此同步處理伺服器可以從提交的資料同步任務中獲取同步任務的優先級。此外,還可以從保存有待同步資料的源資料庫的後設資料中讀取待同步資料的資料量。例如從HDFS同步至Hbase時,透過讀取HDFS的資訊獲取待同步資料的資料量,其他類型的資料庫也可以透過類似的方式獲取資料量。 In a specific implementation, when data synchronization is required, the user can create a data synchronization task on the client and submit it to the corresponding synchronization processing server. When creating a data synchronization task, the client can generate a corresponding priority according to the importance of the data to be synchronized, and is included in the data synchronization task, so the synchronization processing server can obtain the priority of the synchronization task from the submitted data synchronization task. . In addition, the amount of data of the data to be synchronized can also be read from the post data of the source database in which the data to be synchronized is stored. For example, when HDFS is synchronized to Hbase, the amount of data of the data to be synchronized is obtained by reading the information of the HDFS, and other types of databases can also obtain the amount of data in a similar manner.

步驟202,查找針對所述待同步資料的資料量和同步任務的優先級的平均同步速率。 Step 202: Find an average synchronization rate for the data amount of the to-be-synchronized data and the priority of the synchronization task.

步驟203,利用所述平均同步速率、同步處理設備的最大同步速率和所述同步處理設備可供同步處理的執行緒數,計算所述期望運行的同步執行緒數。 Step 203: Calculate the number of synchronization threads expected to run by using the average synchronization rate, the maximum synchronization rate of the synchronization processing device, and the number of threads that the synchronization processing device can use for synchronization processing.

可以根據獲取到的待同步資料的資料量和同步任務的優先級,查找同步任務的平均同步速率。具體地,可以預先根據資料量和優先級初始化同步任務的期望平均同步速率,例如: The average synchronization rate of the synchronization task can be found according to the acquired data amount of the data to be synchronized and the priority of the synchronization task. Specifically, the expected average synchronization rate of the synchronization task may be initialized in advance according to the amount of data and the priority, for example:

根據當前的同步任務中待同步資料的資料量和同步任務的優先級進行查找,例如,資料量為0-10G,優先級為8的同步任務,可以查找到其對應的平均同步任務為30mb/s。 According to the data volume of the data to be synchronized and the priority of the synchronization task in the current synchronization task, for example, a synchronization task with a data volume of 0-10G and a priority of 8 can find that the corresponding average synchronization task is 30 mb/ s.

然後根據每個同步處理設備的處理資源,計算同步所需的CPU數量。例如,每個同步處理設備具有6個CPU內核,其最大同步速率為60mb/s,則可以計算得到每個CPU可以運行的最大同步速率為10mb/s。 Then, according to the processing resources of each synchronous processing device, the number of CPUs required for synchronization is calculated. For example, each synchronous processing device has 6 CPU cores with a maximum synchronization rate of 60 mb/s, and it can be calculated that the maximum synchronization rate that each CPU can run is 10 mb/s.

將查找的同步任務的期望平均同步速率30mb/s除以每個CPU可以運行的最大同步速率為10mb/s,可以計算出所需的CPU個數為3,即為期望運行的同步執行緒數。 Dividing the expected average synchronization rate of the found synchronization task by 30 mb/s by the maximum synchronization rate that each CPU can run is 10 mb/s, and the number of CPUs required to be calculated is 3, that is, the number of synchronization threads expected to run. .

步驟204,從待與源資料庫進行資料同步的目標資料 庫中,獲取所述運行所需的同步執行緒數。 Step 204: Obtain the number of synchronization threads required for the operation from the target database to be synchronized with the source database.

可以從目標資料庫的源資料讀取運行所需的同步執行緒數,例如從HDFS同步至HBase時,可以讀取HBase目標表的Region個數,以Hbase目標表的Region個數作為運行所需的同步執行緒數。Region是HBase資料儲存和管理的基本單位,通常由Region確定目標資料庫在同步時採用的執行緒數。 The number of synchronization threads required for the operation can be read from the source data of the target database. For example, when the HDFS is synchronized to HBase, the number of Regions of the HBase target table can be read, and the number of Regions of the Hbase target table is required for operation. Synchronous thread count. Region is the basic unit of HBase data storage and management. Usually, Region determines the number of threads used by the target database during synchronization.

步驟205,判斷所述期望運行的同步執行緒數是否大於運行所需的同步執行緒數;若是,則進行步驟206。 Step 205: Determine whether the number of synchronization executions of the desired operation is greater than the number of synchronization execution threads required for operation; if yes, proceed to step 206.

步驟206,根據所述期望運行的同步執行緒數和所述運行所需的同步執行緒數的差值,補充配置相應的執行緒。 Step 206: Supplemental configuration of the corresponding thread according to the difference between the expected number of synchronization executions and the synchronization execution number required for the operation.

當期望運行的同步執行緒數大於同步運行實際所需的同步執行緒數,可以根據期望運行的同步執行緒數減去運行所需的同步執行緒數的差值,補充配置相應的虛擬執行緒,利用配置的虛擬執行緒將同步處理設備上的部分CPU置於待機狀態並暫停處理其他同步任務,以保證同步處理設備有足夠的資源處理該資料同步任務。 When the number of synchronous threads expected to run is greater than the number of synchronous threads actually required for synchronous operation, the difference between the number of synchronous threads required to run and the number of synchronized threads required for running may be subtracted, and the corresponding virtual thread may be supplemented. The configured virtual thread is used to put some CPUs on the synchronous processing device into a standby state and suspend processing other synchronization tasks to ensure that the synchronous processing device has sufficient resources to process the data synchronization task.

步驟207,按照所述運行所需的同步執行緒數將所述待同步資料拆分成多個待同步資料塊。 Step 207: Split the data to be synchronized into a plurality of data blocks to be synchronized according to the synchronization execution number required for the operation.

步驟208,採用配置的執行緒針對所述待同步資料同步至目標資料庫。 Step 208: Synchronize the data to be synchronized to the target database by using the configured thread.

作為本申請實施例的優選示例,所述步驟208可以具體為: As a preferred example of the embodiment of the present application, the step 208 may be specifically:

將用於同步各個待同步資料塊的同步執行緒,排程至同步處理設備,以由所述同步處理設備處理所述同步執行緒。 The synchronization thread for synchronizing the respective data blocks to be synchronized is scheduled to the synchronization processing device to process the synchronization thread by the synchronization processing device.

可以將待同步資料拆分成多個待同步資料塊,每個配置的執行緒分別用於同步多個待同步資料塊。根據同步處理設備的剩餘處理資源,將多個執行緒排程至一個或多個同步處理設備,由同步處理設備將多個待同步資料塊同步至目標資料庫。 The data to be synchronized can be split into a plurality of data blocks to be synchronized, and each configured thread is used to synchronize a plurality of data blocks to be synchronized. According to the remaining processing resources of the synchronization processing device, the plurality of threads are scheduled to one or more synchronization processing devices, and the plurality of to-be-synchronized data blocks are synchronized by the synchronization processing device to the target data library.

在實際的應用中,可以將資料同步任務對應的多個執行緒提交至同步控制器,由同步控制器進行期望運行的同步執行緒數是否大於運行所需的同步執行緒數的判斷處理,並根據判斷結果相應地補充配置執行緒和將執行緒排程至多個同步處理設備。 In an actual application, multiple threads corresponding to the data synchronization task may be submitted to the synchronization controller, and the synchronous controller performs the judgment process of whether the number of synchronous execution threads required to be run is greater than the number of synchronous execution threads required for the operation, and According to the judgment result, the configuration thread is supplemented correspondingly and the thread is scheduled to a plurality of synchronization processing devices.

作為本申請實施例的優選示例,所述步驟208可以包括: As a preferred example of the embodiment of the present application, the step 208 may include:

將執行緒屬性滿足預設條件的至少一個同步執行緒優先發送至所述同步處理設備;其中,所述預設條件可以包括以下至少一種: Transmitting, by the synchronization processing device, the at least one synchronization thread that meets the preset condition to the synchronization processing device; wherein the preset condition may include at least one of the following:

所述至少一個同步執行緒屬於同一個資料同步任務、待處理時間大於預設時間閾值、對應同步任務的優先級大於預設優先級閾值、單個同步處理設備可同步處理。 The at least one synchronization thread belongs to the same data synchronization task, the to-be-processed time is greater than the preset time threshold, the priority of the corresponding synchronization task is greater than the preset priority threshold, and the single synchronization processing device can be processed synchronously.

針對期望運行的同步執行緒數大於同步運行實際所需的同步執行緒數的情況,同步控制器可以採用單機多執行緒的資料同步模式,準備針對該同步任務配置的實體執行 緒和虛擬執行緒的排程,將待處理時間大於預設時間閾值、優先級大於預設優先級閾值且屬於同一個資料同步任務的執行緒,優先發送至單個同步處理設備可同步處理的同步處理設備上;如果沒有滿足條件的同步處理設備,可以優先選擇剩餘處理資源最多的一個同步處理設備作為發送對象。 For the case where the number of synchronous threads expected to run is greater than the number of synchronous threads actually required for the synchronous operation, the synchronous controller may adopt the data synchronization mode of the single-machine multi-thread to prepare the entity thread and the virtual thread configured for the synchronization task. The schedule of the processing of the same data synchronization task whose priority is greater than the preset time threshold and whose priority is greater than the preset priority threshold is preferentially sent to the synchronization processing device that can be synchronously processed by a single synchronization processing device; The synchronization processing device that does not satisfy the condition may preferentially select one synchronization processing device with the largest remaining processing resource as the transmission target.

作為本申請實施例的優選示例,所述同步處理設備包括多個,所述步驟208可以包括:將所述同步執行緒優先發送至可供同步處理的最大執行緒數大於預設執行緒數閾值的同步處理設備。 As a preferred example of the embodiment of the present application, the synchronization processing device includes multiple, and the step 208 may include: sending the synchronization thread preferentially to the maximum number of threads available for synchronization processing is greater than a preset thread threshold. Synchronous processing device.

實際應用中,可能暫時沒有能滿足單個同步處理設備可同步處理的該預設條件的同步處理設備,此時可以將同步執行緒優先發送至可供同步處理的最大執行緒數大於預設執行緒數閾值的多個同步處理設備上,即選擇CPU剩餘處理資源較多的同步處理設備進行首輪或多輪的資料同步。針對多個同步處理設備的排程,可以根據同步處理設備的處理資源進行負載均衡排程,也可以隨機排程,本申請實施例對此不作限制。 In actual applications, there may be no synchronization processing device that can satisfy the preset condition that can be synchronously processed by a single synchronization processing device. In this case, the synchronization thread can be preferentially sent to the maximum number of threads available for synchronization processing, which is greater than the preset thread. On the plurality of synchronization processing devices of the threshold, that is, the synchronization processing device that selects more CPU processing resources performs the first or more rounds of data synchronization. For the scheduling of the multiple synchronous processing devices, the load balancing scheduling may be performed according to the processing resources of the synchronous processing device, or may be randomly scheduled, which is not limited in this embodiment of the present application.

根據本申請實施例,根據期望運行的同步執行緒數和運行所需的同步執行緒數的差值補充配置相應的虛擬執行緒,利用虛擬執行緒將同步處理設備上的部分CPU置於待機狀態並暫停處理其他同步任務,以保證同步處理設備有足夠的資源處理該資料同步任務,提升了資料同步的效率和穩定性。而且,不需要從系統層面控制CPU的使 用,提升了資料同步的靈活性。 According to the embodiment of the present application, the corresponding virtual thread is supplemented according to the difference between the number of synchronization threads that are expected to run and the number of synchronization threads required for the operation, and some CPUs on the synchronous processing device are placed in the standby state by using the virtual thread. The other synchronization tasks are suspended to ensure that the synchronization processing device has sufficient resources to process the data synchronization task, thereby improving the efficiency and stability of data synchronization. Moreover, there is no need to control the use of the CPU from the system level, which increases the flexibility of data synchronization.

需要說明的是,對於方法實施例,為了簡單描述,故將其都表述為一系列的動作組合,但是本領域技術人員應該知悉,本申請實施例並不受所描述的動作順序的限制,因為依據本申請實施例,某些步驟可以採用其他順序或者同時進行。其次,本領域技術人員也應該知悉,說明書中所描述的實施例均屬於優選實施例,所涉及的動作並不一定是本申請實施例所必須的。 It should be noted that, for the method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should understand that the embodiments of the present application are not limited by the described action sequence, because In accordance with embodiments of the present application, certain steps may be performed in other sequences or concurrently. In the following, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required in the embodiments of the present application.

參照圖3,示出了本申請的一種資料同步裝置實施例一的結構方塊圖,具體可以包括如下模組: Referring to FIG. 3, a block diagram of a first embodiment of a data synchronizing apparatus of the present application is shown. Specifically, the following modules may be included:

同步執行緒數生成模組301,用於根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數。 The synchronization execution number generation module 301 is configured to generate a synchronization execution thread number to be operated according to the data amount of the data to be synchronized and the priority of the synchronization task in the source database.

同步處理模組302,用於按照期望運行的同步執行緒數進行執行緒配置,並採用配置的執行緒針對所述待同步資料同步至目標資料庫。 The synchronization processing module 302 is configured to perform thread configuration according to the number of synchronization execution threads that are expected to be run, and synchronize the data to be synchronized to the target data library by using the configured thread.

根據本申請實施例,透過根據源資料庫中待同步資料的資料量和同步任務的優先級生成期望運行的同步執行緒數,根據期望運行的同步執行緒數配置相應數量的執行緒進行資料同步,從而可以針對於同步任務的實際情況動態配置執行緒,避免出現部分執行緒已經完成同步任務,而同一任務的其他執行緒還處於等待狀態的情況,提升了資料同步的效率和穩定性。而且,根據同步任務的優先級動態調整期望運行的同步執行緒數,使得重要程度較高的同 步任務可以優先得到處理。 According to the embodiment of the present application, the number of synchronization threads expected to run is generated according to the data amount of the data to be synchronized in the source database and the priority of the synchronization task, and the corresponding number of threads are configured according to the number of synchronization execution threads that are expected to be run. Therefore, the thread can be dynamically configured for the actual situation of the synchronization task, to avoid the situation that some threads have completed the synchronization task, and other threads of the same task are still in the waiting state, which improves the efficiency and stability of data synchronization. Moreover, the number of synchronization threads expected to run is dynamically adjusted according to the priority of the synchronization task, so that the more important synchronization tasks can be processed preferentially.

參照圖4,示出了本申請的一種資料同步裝置實施例二的結構方塊圖,具體可以包括如下模組: Referring to FIG. 4, a block diagram of a second embodiment of a data synchronization device of the present application is shown. Specifically, the following modules may be included:

優先級及資料量獲取模組401,用於從用戶提交的資料同步任務中,獲取所述同步任務的優先級,並從保存有待同步資料的源資料庫中,獲取所述待同步資料的資料量。 The priority and data volume obtaining module 401 is configured to obtain the priority of the synchronization task from the data synchronization task submitted by the user, and obtain the data of the to-be-synchronized data from the source database that stores the data to be synchronized. the amount.

運行所需同步執行緒數獲取模組402,用於從待與源資料庫進行資料同步的目標資料庫中,獲取所述運行所需的同步執行緒數。 The running synchronization execution number acquisition module 402 is configured to obtain the synchronization execution number required for the operation from the target data base to be synchronized with the source database.

同步執行緒數生成模組403,用於根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數。 The synchronization execution number generation module 403 is configured to generate a synchronization execution thread number to be operated according to the data amount of the data to be synchronized in the source database and the priority of the synchronization task.

同步處理模組404,用於按照期望運行的同步執行緒數進行執行緒配置,並採用配置的執行緒針對所述待同步資料同步至目標資料庫。 The synchronization processing module 404 is configured to perform thread configuration according to the number of synchronization threads that are expected to be run, and synchronize the data to be synchronized to the target database by using the configured thread.

作為本申請實施例的優選示例,所述同步執行緒數生成模組403可以包括:平均同步速率查找子模組,用於查找針對所述待同步資料的資料量和同步任務的優先級的平均同步速率;同步執行緒數計算子模組,用於利用所述平均同步速率、同步處理設備的最大同步速率和所述同步處理設備可供同步處理的執行緒數,計算所述期望運行的同步執行緒數。 As a preferred example of the embodiment of the present application, the synchronization execution number generation module 403 may include: an average synchronization rate search sub-module, configured to search for an average of the data amount of the to-be-synchronized data and the priority of the synchronization task. a synchronization rate calculation sub-module, configured to calculate the synchronization of the desired operation by using the average synchronization rate, a maximum synchronization rate of the synchronization processing device, and a number of threads that the synchronization processing device can process synchronously The number of threads.

作為本申請實施例的優選示例,所述同步處理模組404可以包括:同步執行緒數判斷子模組,用於判斷所述期望運行的同步執行緒數是否大於運行所需的同步執行緒數,若是,則叫用執行緒補充子模組。 As a preferred example of the embodiment of the present application, the synchronization processing module 404 may include: a synchronization execution number determination sub-module, configured to determine whether the expected number of synchronization execution threads is greater than the number of synchronization execution threads required for operation If it is, it is called using the thread to supplement the sub-module.

執行緒補充子模組,用於根據所述期望運行的同步執行緒數和所述運行所需的同步執行緒數的差值,補充配置相應的執行緒。 The thread complementing sub-module is configured to supplement the configuration of the corresponding thread according to the difference between the number of synchronization threads that are expected to run and the number of synchronization threads required for the operation.

作為本申請實施例的優選示例,所述裝置可以還包括:待同步資料拆分模組,用於按照所述運行所需的同步執行緒數將所述待同步資料拆分成多個待同步資料塊。 As a preferred example of the embodiment of the present application, the device may further include: a data splitting module to be synchronized, configured to split the data to be synchronized into multiple to be synchronized according to the number of synchronization threads required for the operation Data block.

作為本申請實施例的優選示例一,所述同步處理模組404可以具體用於:將用於同步各個待同步資料塊的同步執行緒,排程至同步處理設備,以由所述同步處理設備處理所述同步執行緒。 As a preferred example 1 of the embodiment of the present application, the synchronization processing module 404 may be specifically configured to: schedule a synchronization thread for synchronizing each to-be-synchronized data block to a synchronization processing device, to be used by the synchronization processing device Processing the synchronization thread.

作為本申請實施例的優選示例二,所述同步處理模組404可以具體用於:將執行緒屬性滿足預設條件的至少一個同步執行緒優先發送至所述同步處理設備。 As a preferred example 2 of the embodiment of the present application, the synchronization processing module 404 may be specifically configured to: send the at least one synchronization thread that meets the preset condition to the synchronization processing device.

作為本申請實施例的優選示例,所述預設條件包括以下至少一種: As a preferred example of the embodiment of the present application, the preset condition includes at least one of the following:

所述至少一個同步執行緒屬於同一個資料同步任務、 待處理時間大於預設時間閾值、對應同步任務的優先級大於預設優先級閾值、單個同步處理設備可同步處理。 The at least one synchronization thread belongs to the same data synchronization task, the to-be-processed time is greater than the preset time threshold, the priority of the corresponding synchronization task is greater than the preset priority threshold, and the single synchronization processing device can be processed synchronously.

作為本申請實施例的優選示例三,所述同步處理設備包括多個,所述同步處理模組404可以具體用於:將所述同步執行緒優先發送至可供同步處理的最大執行緒數大於預設執行緒數閾值的同步處理設備。 As a preferred example 3 of the embodiment of the present application, the synchronization processing device includes a plurality, and the synchronization processing module 404 may be specifically configured to: send the synchronization thread preferentially to a maximum number of threads available for synchronization processing, which is greater than A synchronization processing device that presets the threshold number of threads.

根據本申請實施例,根據期望運行的同步執行緒數和運行所需的同步執行緒數的差值補充配置相應的虛擬執行緒,利用虛擬執行緒將同步處理設備上的部分CPU置於待機狀態並暫停處理其他同步任務,以保證同步處理設備有足夠的資源處理該資料同步任務,提升了資料同步的效率和穩定性。而且,不需要從系統層面控制CPU的使用,提升了資料同步的靈活性。 According to the embodiment of the present application, the corresponding virtual thread is supplemented according to the difference between the number of synchronization threads that are expected to run and the number of synchronization threads required for the operation, and some CPUs on the synchronous processing device are placed in the standby state by using the virtual thread. The other synchronization tasks are suspended to ensure that the synchronization processing device has sufficient resources to process the data synchronization task, thereby improving the efficiency and stability of data synchronization. Moreover, there is no need to control the use of the CPU from the system level, which increases the flexibility of data synchronization.

對於裝置實施例而言,由於其與方法實施例基本相似,所以描述的比較簡單,相關之處參見方法實施例的部分說明即可。 For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.

本說明書中的各個實施例均採用遞進的方式描述,每個實施例重點說明的都是與其他實施例的不同之處,各個實施例之間相同相似的部分互相參見即可。 The various embodiments in the present specification are described in a progressive manner, and each embodiment focuses on differences from other embodiments, and the same similar parts between the various embodiments can be referred to each other.

本領域內的技術人員應明白,本申請實施例的實施例可提供為方法、裝置、或計算機程式產品。因此,本申請實施例可採用完全硬體實施例、完全軟體實施例、或結合軟體和硬體方面的實施例的形式。而且,本申請實施例可採用在一個或多個其中包含有計算機可用程式代碼的計算 機可用儲存媒體(包括但不限於磁碟儲存器、CD-ROM、光學儲存器等)上實施的計算機程式產品的形式。 Those skilled in the art will appreciate that embodiments of the embodiments of the present application can be provided as a method, apparatus, or computer program product. Thus, embodiments of the present application may take the form of a complete hardware embodiment, a fully software embodiment, or an embodiment combining soft and hardware aspects. Moreover, embodiments of the present application may employ computer program products embodied on one or more computer usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer usable code therein. form.

在一個典型的配置中,所述計算機設備包括一個或多個處理器(CPU)、輸入/輸出介面、網路介面和內存記憶體。內存記憶體可能包括計算機可讀媒體中的非永久性記憶體,隨機存取記憶體(RAM)和/或非揮發性內存記憶體等形式,如唯讀記憶體(ROM)或快閃內存記憶體(flash RAM)。內存記憶體是計算機可讀媒體的示例。計算機可讀媒體包括永久性和非永久性、可移動和非可移動媒體可以由任何方法或技術來實現資訊儲存。資訊可以是計算機可讀指令、資料結構、程式的模組或其他資料。計算機的儲存媒體的例子包括,但不限於相變內存記憶體(PRAM)、靜態隨機存取記憶體(SRAM)、動態隨機存取記憶體(DRAM)、其他類型的隨機存取記憶體(RAM)、唯讀儲存器(ROM)、電可抹除可編程唯讀記憶體(EEPROM)、快閃記憶體或其他內存技術、只讀光碟唯讀記憶體(CD-ROM)、數位多功能光碟(DVD)或其他光學儲存、磁盒式磁帶,磁帶磁磁盤儲存或其他磁性儲存設備或任何其他非傳輸媒體,可用於儲存可以被計算設備存取的資訊。按照本文中的界定,計算機可讀媒體不包括非持續性的電腦可讀媒體(transitory media),如調變的資料信號和載波。 In a typical configuration, the computer device includes one or more processors (CPUs), input/output interfaces, a network interface, and memory. Memory memory may include non-persistent memory, random access memory (RAM) and/or non-volatile memory memory in computer readable media, such as read only memory (ROM) or flash memory. Body (flash RAM). Memory memory is an example of a computer readable medium. Computer readable media including both permanent and non-permanent, removable and non-removable media can be stored by any method or technology. The information can be computer readable instructions, data structures, modules of programs, or other materials. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), and other types of random access memory (RAM). ), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only optical disk read-only memory (CD-ROM), digital versatile CD-ROM (DVD) or other optical storage, magnetic tape cartridge, magnetic tape storage or other magnetic storage device or any other non-transportable media that can be used to store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include non-persistent computer readable media, such as modulated data signals and carrier waves.

本申請實施例是參照根據本申請實施例的方法、終端設備(系統)、和計算機程式產品的流程圖及/或方方塊圖 來描述的。應理解可由計算機程式指令實現流程圖及/或方方塊圖中的每一流程及/或方塊、以及流程圖及/或方方塊圖中的流程及/或方塊的結合。可提供這些計算機程式指令到通用計算機、專用計算機、嵌入式處理機或其他可編程資料處理終端設備的處理器以產生一個機器,使得透過計算機或其他可編程資料處理終端設備的處理器執行的指令產生用於實現在流程圖一個流程或多個流程及/或方方塊圖一個方塊或多個方塊中指定的功能的裝置。 The embodiments of the present application are described with reference to flowcharts and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the present application. It will be understood that each flow and/or block of the flowcharts and/or block diagrams, and combinations of flows and/or blocks in the flowcharts and/or block diagrams can be implemented by computer program instructions. The computer program instructions can be provided to a processor of a general purpose computer, a special purpose computer, an embedded processor or other programmable data processing terminal device to generate a machine such that instructions are executed by a processor of a computer or other programmable data processing terminal device Means are provided for implementing the functions specified in one or more blocks of a flowchart or a plurality of processes and/or square blocks.

這些計算機程式指令也可儲存在能引導計算機或其他可編程資料處理終端設備以特定方式工作的計算機可讀儲存器中,使得儲存在該計算機可讀儲存器中的指令產生包括指令裝置的製造品,該指令裝置實現在流程圖一個流程或多個流程及/或方方塊圖一個方塊或多個方塊中指定的功能。 The computer program instructions can also be stored in a computer readable storage that can direct a computer or other programmable data processing terminal device to operate in a particular manner such that instructions stored in the computer readable storage produce an article of manufacture including the instruction device. The instruction device implements the functions specified in one or more blocks of a flowchart or a plurality of flows and/or square blocks of the flowchart.

這些計算機程式指令也可裝載到計算機或其他可編程資料處理終端設備上,使得在計算機或其他可編程終端設備上執行一系列操作步驟以產生計算機實現的處理,從而在計算機或其他可編程終端設備上執行的指令提供用於實現在流程圖一個流程或多個流程及/或方方塊圖一個方塊或多個方塊中指定的功能的步驟。 These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device such that a series of operational steps are performed on a computer or other programmable terminal device to produce computer implemented processing for use in a computer or other programmable terminal device The instructions executed on the steps provide steps for implementing the functions specified in one or more blocks of a flowchart or a plurality of flows and/or square blocks of the flowchart.

儘管已描述了本申請實施例的優選實施例,但本領域內的技術人員一旦得知了基本創造性概念,則可對這些實施例做出另外的變更和修改。所以,所附權利要求意欲解釋為包括優選實施例以及落入本申請實施例範圍的所有變 更和修改。 While a preferred embodiment of the embodiments of the present application has been described, those skilled in the art can make further changes and modifications to the embodiments once they are aware of the basic inventive concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and the modifications and

最後,還需要說明的是,在本文中,諸如第一和第二等之類的關係術語僅僅用來將一個實體或者操作與另一個實體或操作區分開來,而不一定要求或者暗示這些實體或操作之間存在任何這種實際的關係或者順序。而且,術語“包括”、“包含”或者其任何其他變體意在涵蓋非排他性的包含,從而使得包括一系列要件的過程、方法、物品或者終端設備不僅包括那些要件,而且還包括沒有明確列出的其他要件,或者是還包括為這種過程、方法、物品或者終端設備所固有的要件。在沒有更多限制的情況下,由語句“包括一個......”限定的要件,並不排除在包括所述要件的過程、方法、物品或者終端設備中還存在另外的相同要件。 Finally, it should also be noted that in this context, relational terms such as first and second are used merely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply these entities. There is any such actual relationship or order between operations. Moreover, the terms "comprise," "comprise," or "include" or "include" or "include" or "include" or "includes" Other requirements are also included in the process, method, article or terminal equipment. In the absence of further limitations, the requirement defined by the phrase "comprising a ..." does not exclude the presence of additional equivalents in the process, method, article, or terminal device that includes the claim.

以上對本申請所提供的一種資料同步方法和一種資料同步裝置,進行了詳細介紹,本文中應用了具體個例對本申請的原理及實施方式進行了闡述,以上實施例的說明只是用於幫助理解本申請的方法及其核心思想;同時,對於本領域的一般技術人員,依據本申請的思想,在具體實施方式及應用範圍上均會有改變之處,綜上所述,本說明書內容不應理解為對本申請的限制。 The above is a detailed description of a data synchronization method and a data synchronization device provided by the present application. The principles and implementation manners of the present application are described in the specific examples. The description of the above embodiments is only for helping to understand the present application. The method of application and its core idea; at the same time, for those of ordinary skill in the art, according to the idea of the present application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be understood. To limit the application.

Claims (18)

一種資料同步方法,其特徵在於,包括:根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數;按照期望運行的同步執行緒數進行執行緒配置,並採用配置的執行緒針對該待同步資料同步至目標資料庫。  A data synchronization method includes: generating, according to a data amount of a data to be synchronized in a source database and a priority of a synchronization task, a number of synchronous execution threads to be executed; performing thread configuration according to a desired number of synchronous execution threads And use the configured thread to synchronize the data to be synchronized to the target database.   根據申請專利範圍第1項所述的方法,其中,該按照期望運行的同步執行緒數進行執行緒配置包括:判斷該期望運行的同步執行緒數是否大於運行所需的同步執行緒數;若是,則根據該期望運行的同步執行緒數和該運行所需的同步執行緒數的差值,補充配置相應的執行緒。  The method of claim 1, wherein the performing thread configuration according to the expected number of synchronized execution threads comprises: determining whether the number of synchronization executions of the desired operation is greater than a number of synchronization execution threads required for operation; Then, according to the difference between the number of synchronous execution threads that are expected to run and the number of synchronous execution threads required for the operation, the corresponding thread is additionally configured.   根據申請專利範圍第1項所述的方法,其中,在該根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數之前,該方法還包括:從用戶提交的資料同步任務中,獲取該同步任務的優先級,並從保存有待同步資料的該源資料庫中,獲取該待同步資料的資料量。  The method of claim 1, wherein the method further comprises: before generating the number of synchronization threads to be run according to the amount of data to be synchronized in the source database and the priority of the synchronization task. In the data synchronization task submitted by the user, the priority of the synchronization task is obtained, and the data volume of the data to be synchronized is obtained from the source database in which the data to be synchronized is saved.   根據申請專利範圍第1項所述的方法,其中,該根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數包括:查找針對該待同步資料的資料量和同步任務的優先級的平均同步速率;利用該平均同步速率、同步處理設備的最大同步速率 和該同步處理設備可供同步處理的執行緒數,計算該期望運行的同步執行緒數。  The method of claim 1, wherein the generating the synchronization thread to be run according to the data amount of the data to be synchronized in the source database and the priority of the synchronization task comprises: searching for the data to be synchronized The average synchronization rate of the data volume and the priority of the synchronization task; using the average synchronization rate, the maximum synchronization rate of the synchronization processing device, and the number of threads that the synchronization processing device can use for synchronization processing, calculate the number of synchronization threads that are expected to run.   根據申請專利範圍第2項所述的方法,其中,在所述判斷該期望運行的同步執行緒數是否大於運行所需的同步執行緒數之前,該方法還包括:從待與源資料庫進行資料同步的該目標資料庫中,獲取該運行所需的同步執行緒數。  The method of claim 2, wherein before the determining whether the expected number of synchronization executions is greater than the number of synchronization threads required for operation, the method further comprises: proceeding from the source database In the target database of data synchronization, obtain the number of synchronization threads required for the operation.   根據申請專利範圍第1項所述的方法,其中,在該採用配置的執行緒針對該待同步資料同步至目標資料庫之前,該方法還包括:按照該運行所需的同步執行緒數將該待同步資料拆分成多個待同步資料塊;該採用配置的執行緒針對該待同步資料同步至目標資料庫為:將用於同步各個待同步資料塊的同步執行緒,排程至同步處理設備,以由該同步處理設備處理該同步執行緒。  The method of claim 1, wherein before the thread configured to synchronize to the target database, the method further comprises: following the synchronization execution number required for the operation The data to be synchronized is split into a plurality of data blocks to be synchronized; the thread configured to synchronize the data to be synchronized to the target database is: a synchronization thread that is used to synchronize each data block to be synchronized, and scheduled to be synchronized. The device processes the synchronization thread by the synchronization processing device.   根據申請專利範圍第1項所述的方法,其中,該採用配置的執行緒針對該待同步資料同步至目標資料庫包括:將執行緒屬性滿足預設條件的至少一個同步執行緒優先發送至該同步處理設備。  The method of claim 1, wherein the using the configured thread to synchronize the data to be synchronized to the target database comprises: sending at least one synchronization thread that satisfies a preset condition to the preset condition to the Synchronize the device.   根據申請專利範圍第7項所述的方法,該預設條件包括以下至少一種:該至少一個同步執行緒屬於同一個資料同步任務、待 處理時間大於預設時間閾值、對應同步任務的優先級大於預設優先級閾值、單個同步處理設備可同步處理。  According to the method of claim 7, the preset condition includes at least one of the following: the at least one synchronization thread belongs to the same data synchronization task, the to-be-processed time is greater than the preset time threshold, and the priority of the corresponding synchronization task is greater than The preset priority threshold and a single synchronous processing device can be processed synchronously.   根據申請專利範圍第1項所述的方法,其中,該同步處理設備包括多個,該採用配置的執行緒針對該待同步資料同步至目標資料庫包括:將該同步執行緒優先發送至可供同步處理的最大執行緒數大於預設執行緒數閾值的同步處理設備。  According to the method of claim 1, wherein the synchronization processing device includes a plurality of, the configured thread for synchronizing the data to be synchronized to the target database includes: sending the synchronization thread to the priority The synchronous processing device whose maximum number of threads processed by synchronization is greater than the preset number of threads threshold.   一種資料同步裝置,其特徵在於,包括:同步執行緒數生成模組,用於根據源資料庫中待同步資料的資料量和同步任務的優先級,生成期望運行的同步執行緒數;同步處理模組,用於按照期望運行的同步執行緒數進行執行緒配置,並採用配置的執行緒針對該待同步資料同步至目標資料庫。  A data synchronization device, comprising: a synchronization execution number generation module, configured to generate a synchronization execution number of a desired operation according to a data amount of a data to be synchronized in a source database and a priority of a synchronization task; The module is configured to perform thread configuration according to the number of synchronization threads that are expected to run, and uses the configured thread to synchronize the data to be synchronized to the target database.   根據申請專利範圍第10項所述的裝置,其中,該同步處理模組包括:同步執行緒數判斷子模組,用於判斷該期望運行的同步執行緒數是否大於運行所需的同步執行緒數,若是,則叫用執行緒補充子模組;執行緒補充子模組,用於根據該期望運行的同步執行緒數和該運行所需的同步執行緒數的差值,補充配置相應的執行緒。  The device of claim 10, wherein the synchronization processing module comprises: a synchronization execution number determination sub-module, configured to determine whether the synchronization execution number of the desired operation is greater than a synchronization execution thread required for operation The number, if it is, is called using the thread to supplement the sub-module; the thread complementing the sub-module is used to supplement the corresponding configuration according to the difference between the number of synchronization threads that are expected to run and the number of synchronization threads required for the operation. Thread.   根據申請專利範圍第10項所述的裝置,其中,該裝置還包括: 優先級及資料量獲取模組,用於從用戶提交的資料同步任務中,獲取該同步任務的優先級,並從保存有待同步資料的源資料庫中,獲取該待同步資料的資料量。  The device of claim 10, wherein the device further comprises: a priority and a data volume acquisition module, configured to acquire a priority of the synchronization task from a data synchronization task submitted by the user, and save the In the source database of the data to be synchronized, the amount of data of the data to be synchronized is obtained.   根據申請專利範圍第10項所述的裝置,其中,該同步執行緒數生成模組包括:平均同步速率查找子模組,用於查找針對該待同步資料的資料量和同步任務的優先級的平均同步速率;同步執行緒數計算子模組,用於利用該平均同步速率、同步處理設備的最大同步速率和該同步處理設備可供同步處理的執行緒數,計算該期望運行的同步執行緒數。  The device according to claim 10, wherein the synchronization execution number generation module comprises: an average synchronization rate search sub-module, configured to search for a data amount of the to-be-synchronized data and a priority of the synchronization task. An average synchronization rate; a synchronization execution number calculation sub-module for calculating the synchronization thread of the desired operation by using the average synchronization rate, the maximum synchronization rate of the synchronization processing device, and the number of threads that the synchronization processing device can process synchronously number.   根據申請專利範圍第11項所述的裝置,其中,該裝置還包括:運行所需同步執行緒數獲取模組,用於從待與源資料庫進行資料同步的目標資料庫中,獲取該運行所需的同步執行緒數。  The device of claim 11, wherein the device further comprises: a running synchronization execution number acquisition module, configured to acquire the operation from a target database to be synchronized with the source database The number of synchronization threads required.   根據申請專利範圍第10項所述的裝置,其中,該裝置還包括:待同步資料拆分模組,用於按照該運行所需的同步執行緒數將該待同步資料拆分成多個待同步資料塊;該同步處理模組具體用於:將用於同步各個待同步資料塊的同步執行緒,排程至同步處理設備,以由該同步處理設備處理該同步執行緒。  The device of claim 10, wherein the device further comprises: a data splitting module to be synchronized, configured to split the data to be synchronized into a plurality of to-be-scheduled according to the synchronization execution number required for the operation The synchronization processing module is configured to: synchronize the synchronization thread used for synchronizing the data blocks to be synchronized to the synchronization processing device, so that the synchronization processing device processes the synchronization thread.   根據申請專利範圍第10項所述的裝置,其中,該同步處理模組具體用於: 將執行緒屬性滿足預設條件的至少一個同步執行緒優先發送至該同步處理設備。  The device of claim 10, wherein the synchronization processing module is configured to: preferentially send at least one synchronization thread that meets a preset condition to the synchronization processing device.   根據申請專利範圍第16項所述的裝置,該預設條件包括以下至少一種:該至少一個同步執行緒屬於同一個資料同步任務、待處理時間大於預設時間閾值、對應同步任務的優先級大於預設優先級閾值、單個同步處理設備可同步處理。  According to the device of claim 16, the preset condition includes at least one of the following: the at least one synchronization thread belongs to the same data synchronization task, the to-be-processed time is greater than the preset time threshold, and the priority of the corresponding synchronization task is greater than The preset priority threshold and a single synchronous processing device can be processed synchronously.   根據申請專利範圍第10項所述的裝置,其中,該同步處理設備包括多個,該同步處理模組具體用於:將該同步執行緒優先發送至可供同步處理的最大執行緒數大於預設執行緒數閾值的同步處理設備。  The device of claim 10, wherein the synchronization processing device comprises a plurality of, the synchronization processing module is specifically configured to: send the synchronization thread preferentially to the maximum number of threads available for synchronization processing is greater than Set the synchronization processing device of the thread number threshold.  
TW106102729A 2017-01-24 2017-01-24 Data synchronization method and device TWI731926B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
TW106102729A TWI731926B (en) 2017-01-24 2017-01-24 Data synchronization method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
TW106102729A TWI731926B (en) 2017-01-24 2017-01-24 Data synchronization method and device

Publications (2)

Publication Number Publication Date
TW201828119A true TW201828119A (en) 2018-08-01
TWI731926B TWI731926B (en) 2021-07-01

Family

ID=63960275

Family Applications (1)

Application Number Title Priority Date Filing Date
TW106102729A TWI731926B (en) 2017-01-24 2017-01-24 Data synchronization method and device

Country Status (1)

Country Link
TW (1) TWI731926B (en)

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8499305B2 (en) * 2010-10-15 2013-07-30 Via Technologies, Inc. Systems and methods for performing multi-program general purpose shader kickoff
US9830372B2 (en) * 2013-07-24 2017-11-28 Oracle International Corporation Scalable coordination aware static partitioning for database replication
CN103678718A (en) * 2013-12-31 2014-03-26 金蝶软件(中国)有限公司 Database synchronization method and system
CN104731956B (en) * 2015-04-02 2019-07-23 北京奇虎科技有限公司 Method, system and the Relational database of synchrodata

Also Published As

Publication number Publication date
TWI731926B (en) 2021-07-01

Similar Documents

Publication Publication Date Title
WO2017114199A1 (en) Data synchronisation method and apparatus
US9916183B2 (en) Scheduling mapreduce jobs in a cluster of dynamically available servers
US9436739B2 (en) Dynamic priority-based query scheduling
US20150295970A1 (en) Method and device for augmenting and releasing capacity of computing resources in real-time stream computing system
TWI660274B (en) Data processing method and equipment based on blockchain
CN106598705B (en) Asynchronous task scheduling method, device and system and electronic equipment
US20170024251A1 (en) Scheduling method and apparatus for distributed computing system
WO2017016421A1 (en) Method of executing tasks in a cluster and device utilizing same
Boutaba et al. On cloud computational models and the heterogeneity challenge
WO2018120991A1 (en) Resource scheduling method and device
WO2018113533A1 (en) Method, apparatus and system for metadata migration, and device
US20170068574A1 (en) Multiple pools in a multi-core system
TW201818261A (en) Application capacity enlargement method, apparatus and system
JP2015144020A5 (en)
WO2019024508A1 (en) Resource allocation method, master device, slave device, and distributed computing system
CN107818012B (en) Data processing method and device and electronic equipment
WO2017114176A1 (en) Method and apparatus for coordinating consumption queue in distributed environment
US20130205141A1 (en) Quality of Service Targets in Multicore Processors
CN103873587A (en) Method and device for achieving dispatching based on cloud platform
Komarasamy et al. A novel approach for Dynamic Load Balancing with effective Bin Packing and VM Reconfiguration in cloud
CN110716813A (en) Data stream processing method and device, readable storage medium and processor
TW202008762A (en) Data processing method and device, client, and server
CN114116173A (en) Method, device and system for dynamically adjusting task allocation
CN109032779B (en) Task processing method and device, computer equipment and readable storage medium
CN111338803A (en) Thread processing method and device