Data synchronization method and device, equipment and medium
By periodically checking the access time interval of single-segment locks in concurrent scenarios, the existence time of the lock is reasonably controlled, which solves the problem of too long locks and too many useless lock flags, and improves system performance.
Patent Information
- Application Number
- CN202411854372.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-03-04
AI Technical Summary
In concurrent scenarios, the number of locks gradually increases, resulting in the long existence of locks and the increasing number of useless lock flags, affecting system performance.
Periodically check whether the access time interval of a single-segment lock exceeds its existence time, and if it exceeds and is held by a wireless channel, the lock is eliminated. Optionally, if the lock is held by the thread, it is determined whether there is an extension mechanism. If it exists, it will extend the duration of the lock, and if it does not exist, it will unlock.
Effectively control the duration of the lock, avoid useless locks or too many locks with low frequency, and improve system performance.
Smart Images

Figure CN119557114A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data synchronization, and in particular to a data synchronization method, device, equipment and medium. Background Art
[0002] In concurrent scenarios, field updates usually require locks to control so that only the thread that obtains the lock can modify the field to achieve data synchronization. As the business changes and time passes, the number of locks will increase. Over time, the locks will last too long, and there will be more and more useless lock flags, which will affect system performance. Therefore, how to reasonably control the lock duration and improve system performance is a problem that needs to be solved at present. Summary of the invention
[0003] In view of this, the purpose of this application is to provide a data synchronization method, device, equipment and medium, which can reasonably control the existence time of the lock and improve the system performance. The specific scheme is as follows:
[0004] In a first aspect, the present application discloses a data synchronization method, comprising:
[0005] Periodically checking whether the access time interval of the single-segment lock exceeds the existence time of the single-segment lock, wherein the single-segment lock includes a function of controlling concurrency, and is used to lock the target data to be modified by the thread that obtains the single-segment lock from multiple threads, the access time interval is the time interval from the most recent acquisition time of the single-segment lock to the current time, the acquisition time is the time when the thread obtains the single-segment lock, and the existence time is determined based on the access situation of the business corresponding to the single-segment lock;
[0006] If the access time interval of the single-segment lock exceeds the existence time of the single-segment lock, and the single-segment lock is not held by any thread, the single-segment lock is eliminated.
[0007] Optionally, also include:
[0008] If the access time interval of the single-segment lock exceeds the existence time of the single-segment lock, and the single-segment lock is held by any thread, then determine whether there is an extension mechanism for the single-segment lock;
[0009] If the single-stage lock has the extension mechanism, the existence time of the single-stage lock is extended;
[0010] If the single-stage lock does not have the extension mechanism, the single-stage lock is unlocked and the unlocking information is sent to the target terminal.
[0011] Optionally, before extending the existence time of the single-stage lock, the method further includes:
[0012] Check whether the extension times of the single-stage lock reaches a preset times threshold;
[0013] If the extension times do not reach the preset times threshold, triggering the step of extending the existence time of the single-stage lock;
[0014] If the extension times reaches the preset times threshold, corresponding notification information is sent to the target terminal.
[0015] Optionally, also include:
[0016] Counting the number of data reports in a preset time period, wherein the number of data reports is the number of data reports that occur in any business module, the data reports occur based on the access of the business module, and the number of data reports represents the access status of the business module;
[0017] Calculate the ratio of the number of data reports to the total number of data reports corresponding to each business module;
[0018] The existence duration of the single-segment lock corresponding to each business module is determined based on the ratio.
[0019] Optionally, determining the existence duration of the single-segment lock corresponding to each business module based on the ratio includes:
[0020] The existence duration of the single-segment lock corresponding to each business module is determined based on the reporting data time and the ratio, wherein the reporting data time is the generation time of the reported user access data.
[0021] Optionally, also include:
[0022] Determine whether the single-segment lock is held by any thread by identifying the number of objects holding the single-segment lock;
[0023] Among them, the object quantity identifier represents the number of threads currently holding the single-segment lock. After any thread obtains the single-segment lock, the object quantity identifier is increased by one, and after any thread unlocks the single-segment lock, the object quantity identifier is reduced by one.
[0024] Optionally, the process of any thread acquiring a single-segment lock includes:
[0025] Obtain a single-segment lock from the currently existing single-segment lock based on the lock flag of the single-segment lock;
[0026] If the single-segment lock cannot be obtained, a single-segment lock is created based on a default lock, wherein the default lock is the creation logic of the single-segment lock.
[0027] In a second aspect, the present application discloses a data synchronization device, comprising:
[0028] An existence duration check module is used to periodically check whether the access time interval of the single-segment lock exceeds the existence duration of the single-segment lock, wherein the single-segment lock includes a function of controlling concurrency, and is used to lock the target data to be modified by a thread that obtains the single-segment lock from multiple threads, the access time interval is the time interval from the most recent acquisition time of the single-segment lock to the current time, the acquisition time is the time when the thread obtains the single-segment lock, and the existence duration is determined based on the access situation of the business corresponding to the single-segment lock;
[0029] The single-segment lock elimination module is used to eliminate the single-segment lock if the existence duration checking module determines that the access time interval of the single-segment lock exceeds the existence duration of the single-segment lock and the single-segment lock is not held by any thread.
[0030] In a third aspect, the present application discloses an electronic device, including a memory and a processor, wherein:
[0031] The memory is used to store the computer program;
[0032] The processor is used to execute the computer program to implement the aforementioned data synchronization method.
[0033] On the fourth side, the present application discloses a computer-readable storage medium for storing a computer program, wherein the computer program implements the aforementioned data synchronization method when executed by a processor.
[0034] It can be seen from the above scheme that the present application provides a data synchronization method, including: periodically checking whether the access time interval of a single-segment lock exceeds the existence duration of the single-segment lock, wherein the single-segment lock includes a function of controlling concurrency, and is used to lock the target data to be modified by a thread that obtains the single-segment lock from multiple threads, and the access time interval is the time interval from the most recent acquisition time of the single-segment lock to the current time, and the acquisition time is the time when the thread obtains the single-segment lock, and the existence duration is determined based on the access situation of the business corresponding to the single-segment lock; if the access time interval of the single-segment lock exceeds the existence duration of the single-segment lock, and the single-segment lock is not held by any thread, the single-segment lock is eliminated.
[0035] It can be seen that the beneficial effects of the present application are as follows: the existence duration of a single-segment lock is determined based on the access situation of the business corresponding to the single-segment lock, which can ensure that the existence duration of the single-segment lock is more in line with business needs, and periodically check whether the access time interval of the single-segment lock exceeds the existence duration of the single-segment lock. When the access time interval of the single-segment lock exceeds the existence duration of the single-segment lock and the single-segment lock is not held by any thread, the single-segment lock is eliminated to avoid excessive useless locks or locks with too low usage frequency, which leads to a decrease in system performance. In this way, the existence duration of the lock can be reasonably controlled to improve system performance.
[0036] Correspondingly, a data synchronization device, equipment and readable storage medium provided by the present application also have the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0038] Figure 1 A flow chart of a data synchronization method provided in an embodiment of the present application;
[0039] Figure 2 A schematic diagram of multiple types of locks cooperating to synchronize data provided in an embodiment of the present application;
[0040] Figure 3 A specific data synchronization flow chart provided for an embodiment of the present application;
[0041] Figure 4 A schematic diagram of the structure of a data synchronization device provided in an embodiment of the present application;
[0042] Figure 5 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0044] See also Figure 1 As shown, the embodiment of the present application discloses a data synchronization method, including:
[0045] Step S11: Periodically check whether the access time interval of the single-segment lock exceeds the existence time of the single-segment lock, wherein the single-segment lock includes a function of controlling concurrency, which is used to lock the target data to be modified by the thread that obtains the single-segment lock from multiple threads, and the access time interval is the time interval from the most recent acquisition time of the single-segment lock to the current time, and the acquisition time is the time when the thread obtains the single-segment lock, and the existence time is determined based on the access situation of the business corresponding to the single-segment lock.
[0046] This embodiment can check whether the access time interval of the single-segment lock exceeds the existence time of the single-segment lock based on a preset cycle, and the preset cycle size can be set based on experience. The existence time is determined based on the access situation of the business module corresponding to the single-segment lock, and the access situation can be understood as the user access frequency or data that can characterize the user access frequency. For example, in the point-of-care service scenario, the business thread will report the user access data of the business module. The user access data includes but is not limited to browsing, clicking, and commenting on the business module. The number of data reports within a certain period of time can reflect the user access frequency of the business module, and the user access frequency can be characterized by the number of data reports within a certain period of time. Concurrency can be understood as multiple threads wanting to modify the same field. Locking can be understood as the modification of the target data by the thread that obtains the lock, and other threads cannot modify the target data. The target data can be understood as the data corresponding to the business module, for example, the access data corresponding to the business module counted in the point-of-care service, such as the number of browses, etc. Multiple business threads reporting user access data of the business module may trigger lock competition.
[0047] In an optional implementation, the number of data reports in a preset time period can be counted, wherein the number of data reports is the number of data reports occurring in any business module, data reporting occurs based on access to the business module, and the number of data reports represents the access status of the business module; the ratio of the number of data reports to the total number of data reports corresponding to each business module is calculated; and the existence duration of the single-segment lock corresponding to each business module is determined based on the ratio.
[0048] Among them, the preset time period can be determined based on the business situation, such as the past 7 days. The embodiment of the present application can comprehensively determine the existence time of the single-segment lock based on the access situation of the business module corresponding to the single-segment lock and the access situation of each business module. The existence time of the single-segment lock corresponding to the business module with a higher access frequency can be made longer than the existence time of the single-segment lock corresponding to the business module with a lower access frequency, so as to ensure that the single-segment lock with frequent business access exists for a longer time and avoid the overhead caused by frequent lock elimination and creation.
[0049] In an optional implementation, determining the existence duration of the single-segment lock corresponding to each business module based on the ratio may include: determining the existence duration of the single-segment lock corresponding to each business module based on the reported data time and the ratio, wherein the reported data time is the generation time of the reported user access data.
[0050] That is, the embodiment of the present application can comprehensively determine the existence time by combining the access situation of the business module and the time of reporting data, so that the earlier the data is reported, the shorter the existence time of the single-segment lock. The user access data is the access data of the business module, that is, the access record, which needs to be reported to the tracking system. The business system corresponding to the business module can report data to the tracking system containing the monitoring lock through the business thread. The reported data is the user access data, and the generation time of the user access data is the time when the user access data is generated. For example, on June 5, a user accessed a business module and generated a corresponding access record, and the generation time was June 5. For example, the reported data is data from 2 days ago today, that is, the data generation time is 2 days ago today, and the data is earlier. In this way, the existence time is determined based on the interval between the reporting data time and the current time (that is, the time to create the lock and calculate the existence time, which can be a date). The existence time of the single-segment lock corresponding to the earlier data is short, and the single-segment lock can quickly complete the release of the lock, and eliminate the lock as soon as possible when the lock is not needed to provide more single-segment locks for the business module with a later reporting time to use the lock.
[0051] Of course, in some other implementations, the number of times a user accesses a service module within the second preset period can also be counted to obtain the user access frequency. The existence duration can be determined based on the user access frequency of the service module.
[0052] In an optional implementation, the process of any thread acquiring a single-segment lock may include: acquiring the single-segment lock from the currently existing single-segment lock based on the lock flag of the single-segment lock; if the single-segment lock cannot be acquired, creating the single-segment lock based on the default lock, wherein the default lock is the creation logic of the single-segment lock.
[0053] Among them, the lock flag of the single-segment lock can be understood as the unique identifier of the single-segment lock, and can be a lock flag created based on the business module identifier, for example, the business module identifier itself, or the business module identifier and the creation time of the single-segment lock. In this embodiment, the single-segment lock can be first obtained from the currently existing single-segment lock based on the lock flag. If the single-segment lock with the lock flag cannot be obtained, the single-segment lock is created based on the default lock. The process of creating a single-segment lock by the default lock may include: checking whether there is a single-segment lock corresponding to the lock flag, if not, creating a lock according to the lock flag, and initializing the acquisition time and determining the existence duration, for example, based on the interval time from the time corresponding to the reported data to today and the number of data reports corresponding to the business module in the past 7 days to determine the existence duration of the lock. In addition, an unlock flag is generated, which is the unique flag of the thread to ensure that only the thread can unlock the acquired single-segment lock.
[0054] Step S12: If the access time interval of the single-segment lock exceeds the existence time of the single-segment lock, and the single-segment lock is not held by any thread, the single-segment lock is eliminated.
[0055] In an optional implementation, it is possible to determine whether the single-segment lock is held by any thread through the number of objects held by the single-segment lock; wherein the number of objects held indicates the number of threads currently holding the single-segment lock, and after any thread acquires the single-segment lock, the number of objects held is incremented by one, and after any thread unlocks the single-segment lock, the number of objects held is decremented by one.
[0056] For example, the initial value of the number of held objects is 0. After any thread obtains the single-segment lock, the number of held objects is increased by 1, and the number of held objects is 1. After the thread unlocks the single-segment lock, the number of held objects is reduced by one and returns to 0. In this way, by designing the number of held objects, the current held object data of the lock can be clearly reflected. When the number of held objects is abnormal, such as a negative number, the message can be reported to relevant personnel, such as operation and maintenance personnel.
[0057] In an optional implementation, if the access time interval of the single-segment lock exceeds the existence duration of the single-segment lock, and the single-segment lock is held by any thread, it is determined whether there is an extension mechanism for the single-segment lock; if the single-segment lock has the extension mechanism, the existence duration of the single-segment lock is extended; if the single-segment lock does not have the extension mechanism, the single-segment lock is unlocked and the unlocking information is sent to the target terminal.
[0058] That is, in this embodiment, the lock of the frequently accessed business module can be extended through the extension mechanism. An identifier representing whether there is an extension mechanism can be added to the attribute field of the single-segment lock. For example, 1 represents the existence of the extension mechanism, and 0 represents the absence of the extension identifier. The target terminal can be an operation and maintenance personnel terminal to inform the operation and maintenance personnel of relevant information so that the operation and maintenance personnel can analyze and process it.
[0059] In an optional implementation, the existence duration may be extended based on the extension duration, and the extension duration may be determined based on the access status of the service module. For example, the extension duration corresponding to each service module may be determined based on the ratio of the number of data reports to the total number of data reports corresponding to each service module.
[0060] In an optional embodiment, before the single-stage lock is extended, the method further includes: checking whether the number of extensions of the single-stage lock reaches a preset number threshold; if the number of extensions does not reach the preset number threshold, triggering the step of extending the single-stage lock; if the number of extensions reaches the preset number threshold, sending corresponding notification information to the target terminal. The notification information may be information indicating that the number of extensions reaches the preset number threshold.
[0061] That is, the present embodiment can design the extension times of the extension mechanism to ensure a more flexible control lock. The extension times can also be determined according to the access situation of the service module. For example, the extension times corresponding to each service module are determined based on the ratio of the data reporting times to the total data reporting times corresponding to each service module.
[0062] In addition, in the embodiment of the present application, the business module may correspond to a segment lock, and the segment lock may contain multiple single-segment locks. Different business modules correspond to different segment locks to achieve the interval of business module data and ensure that the data reports between the business modules do not affect each other.
[0063] It can be seen that in the embodiment of the present application, the existence time of the single-segment lock is determined based on the access situation of the business corresponding to the single-segment lock, which can ensure that the existence time of the single-segment lock is more in line with the business needs, and periodically check whether the access time interval of the single-segment lock exceeds the existence time of the single-segment lock. When the access time interval of the single-segment lock exceeds the existence time of the single-segment lock and the single-segment lock is not held by any thread, the single-segment lock is eliminated to avoid excessive useless locks or locks with too low usage frequency, resulting in a decrease in system performance. In this way, the existence time of the lock can be reasonably controlled to improve system performance.
[0064] The following is a further explanation of the data synchronization solution provided by this application in combination with the tracking data reporting scenario:
[0065] The data reported by the tracking points are mainly the user access situations reported by each business module. Therefore, the reported data attributes are mainly the user access time and the business module accessed by the user. The closer the access time is to the current time, the more accesses should be made. This embodiment uses previous access data to statistically learn the access frequency of business modules corresponding to different types of businesses for the accessed business modules. The importance of the business leads to different existence times of the single-segment locks corresponding to the business key (key, i.e., business module identifier). For example, the store patrol business is very important, so the corresponding single-segment lock needs to exist for a longer time, because users frequently access the store patrol business module. There are also unimportant businesses such as cloud guarding, and the corresponding single-segment lock does not need to exist for a longer time, because it is not frequent. This embodiment uses statistics to learn whether a business is important and can adapt to changes in the importance of the business. In addition, each business module should have its own concurrency control. For example, the data of the store patrol module cannot affect the data reported by the cloud guard. Based on the overall control requirements, the embodiment of the present application proposes a segmented lock, and the control of the segmented lock requires an overall lock. A default lock is proposed, in which multiple single-segment locks constitute a segmented lock, and the default lock controls the segmented lock; in order to statistically learn the access frequency of the business module, monitor the status of the segmented lock and eliminate useless single-segment locks, a monitoring lock is proposed.
[0066] For example, see Figure 2 As shown, Figure 2 A schematic diagram of multiple types of locks cooperating to synchronize data provided in an embodiment of the present application. The function of the lock is to control the concurrency of data. The embodiment of the present application includes a default lock, a segmented lock, and a monitoring lock.
[0067] The default lock is mainly used for the overall synchronization structure in the segment lock. Because in concurrent situations, multiple threads will create their own single-segment locks in the segment lock. Therefore, an overall lock is needed to control the creation of segment locks, that is, the creation of single-segment locks needs to be controlled.
[0068] The segmented lock contains multiple single-segment locks. The main attributes of each single-segment lock include the internal lock (the main body that actually executes the lock function, controls concurrency, and locks this field data so that it can only be modified by the thread that obtains the lock), the number of objects held (the number of threads that obtain the lock, usually 0 or 1. For example, when the business server reports data, if multiple containers (containers correspond to business threads) are involved in concurrent data reporting, if a container obtains the lock first, the lock holding object +1 and locks it, sets the acquisition time (that is, the moment of locking), generates a unique unlock flag (thread ID (identifier) or the thread uses the snowflake algorithm to generate a UUID (that is, Universally Unique Identifier, universal unique identifier), the unlock flag is the unique ID of the thread, which is mainly used to determine that the lock can only be unlocked by this thread to prevent other threads from unlocking it), until the container completes reporting the data, the lock holder -1, and unlocks at the same time. At this time, the thread is a data modification thread), lock flag (including the creation time of the single-segment lock, module ID, creation time, module ID generation time is simultaneous, global module statistics (related to the access count statistics of each module obtained from the monitoring lock), unlock flag, acquisition time, extension mechanism (whether to extend).
[0069] The lock flag stores the time flag (i.e., acquisition time) and global module statistics to calculate the lock's existence duration. For example, the longest lock existence duration is 1 day and the shortest is 5 minutes. According to the proportion of the target module (the ratio of the number of visits to the target module (which can be the number of visits or reports to the target module) to the total number of visits to all modules (total number of visits or total number of reports) during the statistical period), the number of days from today is calculated, the proportion of the target module * (1 / (number of days away + 1)) * 1440, where the number of days away is the interval between the current date and the reporting date, in minutes, and 1440 is the number of minutes in a day, to get the existence duration of a single-segment lock. The existence duration of the lock is the release time of the single-segment lock. It can be deduced from the formula that the older the record, the shorter the corresponding lock existence duration, that is, the faster the lock is released.
[0070] The monitoring lock can monitor the status of each single-segment lock. Each single-segment lock is checked in turn at regular intervals. When checking the single-segment lock, the single-segment lock cannot be acquired or released. If the single-segment lock is not held by a thread and the access interval has exceeded the lock limit (i.e., the existence time), then the single-segment lock is removed. If the single-segment lock is held by a thread, but the access interval exceeds the lock limit, then check whether the single-segment lock can be extended (when each lock is created, there is a watch (i.e., monitoring) field to monitor it. By default, it can be extended, but this extension is still subject to the number and time limit). If it can, then extend it. If not, then release the lock. If the extension time exceeds a certain limit, then an error alarm is reported to the relevant personnel. The monitoring lock will also record the frequency of module flag access (i.e., the frequency determined by the number of reports of the business module), and the calculation of the existence time of the single-segment lock will be affected by this. Monitor whether there are abnormal situations in the monitoring lock, such as abnormal duration, negative number of acquisitions, etc., which will be alarmed to the relevant personnel.
[0071] When reporting data, threads compete to acquire locks, triggering the acquisition of single-segment locks; each single-segment lock contains a creation date tag and a corresponding module mark (i.e., module identifier); if a thread acquires a single-segment lock that meets the requirements (the creation date and module mark of the single-segment lock meet the business requirements), the single-segment lock is used directly; if a thread does not acquire a single-segment lock that meets the requirements (with a date tag and module mark, and the lock's existence duration is fixed at this time), a single-segment lock that meets the requirements is created based on the default lock for use. One of the threads acquires the lock, and the other threads wait; the thread is unlocked after execution; the lock is eliminated when the lock duration exceeds the lock's existence duration and the extension strategy is not executed (including eliminating the lock's creation date and module log tag). Other threads compete to acquire the lock.
[0072] For further information, see Figure 3 As shown, Figure 3 A specific data synchronization flow chart disclosed in an embodiment of the present application.
[0073] The business thread applies for a lock and reports it to the monitoring lock. The monitoring lock counts the periodic access frequency of the module (it can be the number of business module accesses within the period or the number of data reports within the period). A lock flag is generated based on the date and module ID to obtain a single-segment lock. If the segmented lock currently has a single-segment lock corresponding to the lock flag, the single-segment lock is obtained. If not, the default lock is obtained. It is determined again whether the segmented lock currently has a single-segment lock corresponding to the lock flag. If so, the single-segment lock is successfully created. If not, a single-segment lock is created by default based on the lock flag. The lock access time is initialized, and the lock existence time is calculated based on the module access ratio and the number of days from the beginning. The single-segment lock is successfully created. The business thread obtains the single-segment lock, holds the object +1, sets the access time (i.e., the acquisition time), generates an unlock flag, the business thread completes the processing, holds the object -1, and unlocks according to the unlock flag.
[0074] Monitor the lock period to monitor whether the lock time of a single-segment lock has timed out. If it has timed out, determine whether it supports extension. If it supports, the monitor lock can determine how long the extension will be. The extension time is determined by the business. For example, if the store patrol business is an important and high-frequency business, the extension time is longer. The extension time is set as: (the ratio of the number of visits to the target module in the statistical period (which can be the number of visits or the number of data reports) to the total number of visits to all modules (the total number of visits or the total number of data reports)) * one day (such as 1440 minutes), or the number of times the lock can be extended. If the extension time exceeds the preset number, the lock is eliminated. Specifically, the monitor lock monitors the status of each single-segment lock, checks each single-segment lock in turn at regular intervals, and when checking the single-segment lock, the single-segment lock cannot be acquired or released. If the single-segment lock is not held by a thread and the access interval has exceeded the lock limit, then the single-segment lock is removed. If the single-segment lock is held by a thread, but the access interval exceeds the lock limit, then check whether the single-segment lock can be extended. If it can, then extend it, if not, then unlock it. If the extension time exceeds a certain limit, an error will be reported to the relevant personnel. The monitoring lock will also record the number of data reports from the business module to calculate the existence time of the single-stage lock.
[0075] The number of data reports of the business module can reflect the access frequency of the business module. Of course, in an optional implementation, the number of module accesses can be analyzed based on the embedded data, and the existence duration can be determined based on the number of business module accesses. Specifically, the business reports the embedded data of each module to the server, and the server analyzes the number of accesses of each module from the embedded data of each module. The monitoring lock obtains the number of accesses of each module. The number of accesses of each module can be obtained from the monitoring lock, and the existence duration of the single-segment lock is calculated based on the creation time of the single-segment lock, the number of module accesses corresponding to the single-segment lock, and the total number of module accesses.
[0076] The locks in this embodiment are composed of a default lock, a monitoring lock, and a segmented lock. The segmented lock method is adopted. The existence duration of the lock is determined according to the business and business time. The single-segment lock is obtained through a thread, and the single-segment lock is iterated during the monitoring lock period to control the concurrency of data. This avoids the problem of an increasing number of useless lock flags or the existence duration of the lock cannot be changed according to business changes. It can be applied to the situation of updating unique data under large concurrency. Through various types of synchronous locks, the problem of traditional lock types and single locks being unable to cope with point reporting is solved.
[0077] See also Figure 4 As shown, the embodiment of the present application discloses a data synchronization device, including:
[0078] An existence duration check module 11 is used to periodically check whether the access time interval of the single-segment lock exceeds the existence duration of the single-segment lock, wherein the single-segment lock includes a function of controlling concurrency, and is used to lock the target data to be modified by a thread that obtains the single-segment lock from multiple threads, the access time interval is the time interval from the most recent acquisition time of the single-segment lock to the current time, the acquisition time is the time when the thread obtains the single-segment lock, and the existence duration is determined based on the access situation of the business corresponding to the single-segment lock;
[0079] The single-segment lock elimination module 12 is used to eliminate the single-segment lock if the existence duration checking module determines that the access time interval of the single-segment lock exceeds the existence duration of the single-segment lock and the single-segment lock is not held by any thread.
[0080] Furthermore, the single-segment lock elimination module 12 can also extend the processing submodule, which is used to determine whether there is an extension mechanism for the single-segment lock if the access time interval of the single-segment lock exceeds the existence time of the single-segment lock and the single-segment lock is held by any thread; if the single-segment lock has the extension mechanism, the existence time of the single-segment lock is extended; if the single-segment lock does not have the extension mechanism, the single-segment lock is unlocked and the unlocking information is sent to the target terminal.
[0081] The extension processing submodule is also used to check whether the number of extensions of the single-stage lock reaches a preset number threshold before extending the existence time of the single-stage lock; if the number of extensions does not reach the preset number threshold, triggering the step of extending the existence time of the single-stage lock; if the number of extensions reaches the preset number threshold, sending a corresponding notification message to the target terminal.
[0082] The device also includes:
[0083] A statistics module, used to count the number of data reports in a preset time period, wherein the number of data reports is the number of data reports that occur in any business module, the data reports occur based on the access of the business module, and the number of data reports represents the access status of the business module;
[0084] A ratio calculation module, used to calculate the ratio of the number of data reports to the total number of data reports corresponding to each business module;
[0085] The existence duration determination module is used to determine the existence duration of the single-segment lock corresponding to each business module based on the ratio.
[0086] The existence duration determination module is specifically used to determine the existence duration of the single-segment lock corresponding to each business module based on the reported data time and the ratio, wherein the reported data time is the generation time of the reported user access data.
[0087] The single-segment lock elimination module 12 is also used to: determine whether the single-segment lock is held by any thread through the number of objects held by the single-segment lock; wherein the number of objects held indicates the number of threads currently holding the single-segment lock, and after any thread obtains the single-segment lock, the number of objects held is increased by one, and after any thread unlocks the single-segment lock, the number of objects held is decreased by one.
[0088] The process of any thread acquiring a single-segment lock includes:
[0089] Obtain a single-segment lock from the currently existing single-segment lock based on the lock flag of the single-segment lock;
[0090] If the single-segment lock cannot be obtained, a single-segment lock is created based on a default lock, wherein the default lock is the creation logic of the single-segment lock.
[0091] It can be seen that in the embodiment of the present application, the existence time of the single-segment lock is determined based on the access situation of the business corresponding to the single-segment lock, which can ensure that the existence time of the single-segment lock is more in line with the business needs, and periodically check whether the access time interval of the single-segment lock exceeds the existence time of the single-segment lock. When the access time interval of the single-segment lock exceeds the existence time of the single-segment lock and the single-segment lock is not held by any thread, the single-segment lock is eliminated to avoid excessive useless locks or locks with too low usage frequency, resulting in a decrease in system performance. In this way, the existence time of the lock can be reasonably controlled to improve system performance.
[0092] See also Figure 5 As shown, an embodiment of the present application discloses an electronic device 20, including a processor 21 and a memory 22; wherein the memory 22 is used to store a computer program; the processor 21 is used to execute the computer program, and the data synchronization method disclosed in the above embodiment.
[0093] For the specific process of the above-mentioned data synchronization method, please refer to the corresponding content disclosed in the aforementioned embodiment, which will not be repeated here.
[0094] Furthermore, the memory 22 as a carrier for storing resources may be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., and the storage method may be temporary storage or permanent storage.
[0095] In addition, the electronic device 20 also includes a power supply 23, a communication interface 24, an input / output interface 25 and a communication bus 26; wherein the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and an external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input / output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0096] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the data synchronization method disclosed in the aforementioned embodiment.
[0097] For the specific process of the above-mentioned data synchronization method, please refer to the corresponding content disclosed in the aforementioned embodiment, which will not be repeated here.
[0098] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0099] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0100] The above is a detailed introduction to a data synchronization method, device, equipment and medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A data synchronization method, characterized in that: include: Periodically checking whether the access time interval of the single-segment lock exceeds the existence time of the single-segment lock, wherein the single-segment lock includes a function of controlling concurrency, and is used to lock the target data to be modified by the thread that obtains the single-segment lock from multiple threads, the access time interval is the time interval from the most recent acquisition time of the single-segment lock to the current time, the acquisition time is the time when the thread obtains the single-segment lock, and the existence time is determined based on the access situation of the business corresponding to the single-segment lock; If the access time interval of the single-segment lock exceeds the existence time of the single-segment lock, and the single-segment lock is not held by any thread, the single-segment lock is eliminated.
2. The data synchronization method according to claim 1, characterized in that: Also includes: If the access time interval of the single-segment lock exceeds the existence time of the single-segment lock, and the single-segment lock is held by any thread, then determine whether there is an extension mechanism for the single-segment lock; If the single-stage lock has the extension mechanism, the existence time of the single-stage lock is extended; If the single-stage lock does not have the extension mechanism, the single-stage lock is unlocked and the unlocking information is sent to the target terminal.
3. The data synchronization method according to claim 2, characterized in that: Before extending the existence time of the single-stage lock, the method further includes: Check whether the extension times of the single-stage lock reaches a preset times threshold; If the extension times do not reach the preset times threshold, triggering the step of extending the existence time of the single-stage lock; If the extension times reaches the preset times threshold, corresponding notification information is sent to the target terminal.
4. The data synchronization method according to claim 1, characterized in that: Also includes: Counting the number of data reports in a preset time period, wherein the number of data reports is the number of data reports that occur in any business module, the data reports occur based on the access of the business module, and the number of data reports represents the access status of the business module; Calculate the ratio of the number of data reports to the total number of data reports corresponding to each business module; The existence duration of the single-segment lock corresponding to each business module is determined based on the ratio.
5. The data synchronization method according to claim 4, characterized in that: The determining the existence duration of the single-segment lock corresponding to each business module based on the ratio includes: The existence duration of the single-segment lock corresponding to each business module is determined based on the reporting data time and the ratio, wherein the reporting data time is the generation time of the reported user access data.
6. The data synchronization method according to claim 1, characterized in that: Also includes: Determine whether the single-segment lock is held by any thread by identifying the number of objects holding the single-segment lock; Among them, the object quantity identifier represents the number of threads currently holding the single-segment lock. After any thread obtains the single-segment lock, the object quantity identifier is increased by one, and after any thread unlocks the single-segment lock, the object quantity identifier is reduced by one.
7. The data synchronization method according to any one of claims 1 to 6, characterized in that: The process of any thread acquiring a single-segment lock includes: Obtain a single-segment lock from the currently existing single-segment lock based on the lock flag of the single-segment lock; If the single-segment lock cannot be obtained, a single-segment lock is created based on a default lock, wherein the default lock is the creation logic of the single-segment lock.
8. A data synchronization device, characterized in that: include: An existence duration check module is used to periodically check whether the access time interval of the single-segment lock exceeds the existence duration of the single-segment lock, wherein the single-segment lock includes a function of controlling concurrency, and is used to lock the target data to be modified by a thread that obtains the single-segment lock from multiple threads, the access time interval is the time interval from the most recent acquisition time of the single-segment lock to the current time, the acquisition time is the time when the thread obtains the single-segment lock, and the existence duration is determined based on the access situation of the business corresponding to the single-segment lock; The single-segment lock elimination module is used to eliminate the single-segment lock if the existence duration checking module determines that the access time interval of the single-segment lock exceeds the existence duration of the single-segment lock and the single-segment lock is not held by any thread.
9. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store the computer program; The processor is used to execute the computer program to implement the data synchronization method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the data synchronization method according to any one of claims 1 to 7 is implemented.