Data cache management method and electronic device

By introducing a multi-layer nested object relationship structure and a hierarchical read-write lock mechanism in the data cache system, the problems of lock contention and insufficient scalability in high-concurrency scenarios are solved, achieving efficient data management and improved stability.

CN120508266BActive Publication Date: 2025-09-16SHENZHEN GUORUIXIE CHUANG ENERGY STORAGE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511011215.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-22
Publication Date
2025-09-16
Estimated Expiration
2045-07-22

AI Technical Summary

Technical Problem

Existing data caching systems suffer from lock contention, data consistency issues, and insufficient scalability in high-concurrency scenarios, and are unable to meet high-concurrency requirements.

Method used

It adopts a multi-layer nested object relationship structure, including device nodes, data nodes, device node containers and data node containers. Through hierarchical management and read-write lock mechanism, it realizes multi-threaded parallel access and operation of data nodes, and uses the CAS mechanism of atomic data for concurrent writing.

Benefits of technology

It improves the overall performance and stability of the data cache system in high-concurrency scenarios, reduces lock contention and performance bottlenecks, and improves data management efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120508266B_ABST
    Figure CN120508266B_ABST
Patent Text Reader

Abstract

The present application relates to the field of computer technology and discloses a data cache management method and electronic device. The method is applied to the electronic device and includes: a first thread applying for a first operation lock from an operating system in a device node container; the operating system issuing the first operation lock to the first thread; the first thread receiving the first operation lock and managing the device node using the first operation lock; a second thread applying for a second operation lock from the operating system in a target data node container among multiple data node containers; the operating system issuing the second operation lock to the second thread; the second thread managing the data nodes stored in the target data node container using the second operation lock, and / or the second thread operating on the atomic data stored in the target data node in the target data node container using the second operation lock. The present application improves the efficiency of cache management of data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a data cache management method and electronic device. Background Art

[0002] The increasing demand for high-concurrency data processing and storage, particularly in real-time energy storage monitoring systems, the Industrial Internet of Things, and distributed computing scenarios, places higher demands on efficient data caching design methods. Traditional data caching systems rely primarily on simple locking mechanisms to support data access. However, this traditional data caching approach is not suitable for high-concurrency scenarios. Summary of the Invention

[0003] In view of the above problems, embodiments of the present application provide a data cache management method and an electronic device to solve the problem in the prior art that there is currently a lack of a data cache management method suitable for high-concurrency scenarios.

[0004] According to one aspect of an embodiment of the present application, a data cache management method is provided, which is applied to an electronic device, wherein the electronic device includes a plurality of device nodes, a plurality of groups of data nodes, a device node container, and a plurality of data node containers;

[0005] Each of the device nodes corresponds to a logical device, and each of the logical devices has one or more types of data; each group of the data nodes is associated with a device node and stores the data of the logical device corresponding to the device node, and each group of the data nodes includes one or more data nodes, wherein each data node is used to store one type of atomic data; the multiple device nodes are stored in the device node container; the multiple data node containers correspond one-to-one to the multiple device nodes, and each data node container stores a group of the data nodes associated with the corresponding device node; the method includes: a first thread applies for a first operation lock from the operating system in the device node container; the operating system issues the first operation lock to the first thread; the first thread receives the first operation lock and manages the device node through the first operation lock; a second thread applies for a second operation lock from the operating system in a target data node container among the multiple data node containers; the operating system issues a second operation lock to the second thread; the second thread manages the data nodes stored in the target data node container through the second operation lock, and / or the second thread operates on the atomic data stored on the target data node in the target data node container through the second operation lock.

[0006] In an optional manner, the first thread may manage all device nodes through the first operation lock.

[0007] In an optional manner, the second thread may manage all data nodes stored in the target data node container and read or modify the atomic data stored in the target data node through the second operation lock.

[0008] In an optional manner, when the first operation lock is a first read lock and the second operation lock is a second read lock, the first thread receives the first operation lock and manages the device node through the first operation lock, including: the first thread receives the first read lock and accesses the target device node among the multiple device nodes through the first read lock; the second thread operates the atomic data stored in the target data node in the target data node container through the second operation lock, including: the second thread reads or modifies the atomic data stored in the target data node through the second read lock, wherein the target data node is the data node associated with the target device node.

[0009] In an optional manner, when the first operation lock is a first write lock, the first thread receives the first operation lock and manages device nodes through the first operation lock, including: the first thread receives the first write lock and adds or deletes device nodes through the first write lock.

[0010] In an optional manner, when the first operation lock is a first read lock and the second operation lock is a second write lock, the first thread receives the first operation lock and manages the device node through the first operation lock, including: the first thread receives the first read lock and accesses the target device node among the multiple device nodes through the first read lock; the second thread manages the data nodes stored in the target data node container through the second operation lock, including: the second thread adds or deletes data nodes in a group of data nodes associated with the target device node through the second write lock.

[0011] In an optional manner, when the first operation lock is the first read lock, the operating system issues the first operation lock to the first thread, including: the operating system determining whether the first write lock has been issued to other threads, wherein the first write lock is used to add or delete device nodes; if the operating system has issued the first write lock to a third thread, the operating system issues the first read lock to the first thread after the third thread finishes using the first write lock; if the operating system has not issued the first write lock to other threads, the operating system directly issues the first read lock to the first thread; when the second operation lock is the second read lock, the operating system issues the second operation lock to the second thread, including: the operating system determining whether the second write lock has been issued to other threads, wherein the second write lock is used to add or delete data nodes in a group of data nodes associated with the target device node; if the operating system has issued the second write lock to a fourth thread, the operating system issues the second read lock to the second thread after the fourth thread finishes using the second write lock; if the operating system has not issued the second write lock to other threads, the operating system directly issues the second read lock to the second thread.

[0012] In an optional manner, when the first operation lock is the first write lock, the operating system issues the first operation lock to the first thread, including: the operating system determines whether it has issued the first read lock or the first write lock to other threads, wherein the first read lock is used to access the device node; if the operating system has issued the first read lock to the fifth thread, the operating system issues the first write lock to the first thread after the fifth thread finishes using the first read lock, or if the operating system has issued the first write lock to the fifth thread, the operating system issues the first write lock to the first thread after the fifth thread finishes using the first write lock; if the operating system has not issued the first read lock and the first write lock to other threads, the operating system directly issues the first write lock to the first thread.

[0013] In an optional manner, when the first operation lock is the first read lock, the operating system issues the first operation lock to the first thread, including: the operating system determines whether the first write lock has been issued to other threads, wherein the first write lock is used to add or delete device nodes; if the operating system has issued the first write lock to the sixth thread, the operating system issues the first read lock to the first thread after the sixth thread finishes using the first write lock; if the operating system has not issued the first write lock to other threads, the operating system directly issues the first read lock to the first thread; when the second operation lock is the second write lock, the operating system issues the second operation lock to the second thread, including: The operating system determines whether it has issued the second read lock or the second write lock to other threads, wherein the second read lock is used to access the data node stored in the target data node container; if the operating system has issued the second read lock to the seventh thread, the operating system issues the second write lock to the second thread after the seventh thread finishes using the second read lock, or if the operating system has issued the second write lock to the seventh thread, the operating system issues the second write lock to the second thread after the seventh thread finishes using the second write lock; if the operating system has not issued the second read lock and the second write lock to other threads, the operating system directly issues the second write lock to the second thread.

[0014] According to another aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored on the memory, wherein the electronic device comprises a plurality of device nodes, a plurality of groups of data nodes, a device node container, and a plurality of data node containers; each of the device nodes corresponds to a logical device, and each of the logical devices has one or more types of data; each group of the data nodes is associated with a device node and stores the data of the logical device corresponding to the device node, and each group of the data nodes comprises one or more data nodes, wherein each data node is used to store a type of atomic data; the plurality of device nodes are stored in the device node container; the plurality of data node containers correspond one-to-one to the plurality of device nodes, and each of the data node containers stores a group of the data nodes associated with the corresponding device node; the processor executes the computer program to implement the data cache management method as described above.

[0015] In the embodiments of the present application, by utilizing data nodes to store atomic data and hierarchically managing device nodes and data nodes, multiple threads can access or operate data nodes in different data node containers in parallel, thereby improving the efficiency of managing data nodes. Furthermore, in the embodiments of the present application, through the above-mentioned configuration, multiple threads can read or modify atomic data in parallel, which improves the efficiency of cache management of atomic data stored in data nodes, compared to the method in which multiple threads can only read and write data in turn.

[0016] The above description is only an overview of the technical solutions of the embodiments of the present application. In order to more clearly understand the technical means of the embodiments of the present application, they can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the embodiments of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings are only used to illustrate the embodiments and are not to be considered as limiting the present application. In addition, the same reference symbols are used to represent the same components throughout the drawings. In the drawings:

[0018] Figure 1 A schematic diagram showing the cache management data provided by an embodiment of the present application is shown;

[0019] Figure 2 A schematic diagram illustrating a flow chart of a data cache management method provided in an embodiment of the present application is shown;

[0020] Figure 3 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0021] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application can be implemented in various forms and should not be limited to the embodiments set forth herein.

[0022] High-concurrency scenarios involve systems processing a large number of concurrent requests or tasks within a short period of time. These scenarios are commonly found in real-time energy storage monitoring systems and e-commerce promotions. These scenarios place extremely high demands on system response speed, resource allocation, and stability, while also presenting numerous technical challenges.

[0023] Traditional data caching systems rely primarily on simple locking mechanisms to support data access. These mechanisms control concurrent access to shared cached data by setting mutual exclusion locks, ensuring that only one thread or process can modify or read data at a time, thus avoiding data contention and inconsistencies.

[0024] However, in high-concurrency scenarios, this approach faces problems such as lock contention, data consistency, and insufficient scalability. The lock contention problem refers to the fact that a simple global lock mechanism easily triggers lock contention, leading to performance bottlenecks. Especially in the case of frequent multi-threaded read operations, the granularity of the global lock is too large to meet high concurrency requirements. The data consistency problem refers to the fact that in traditional cache designs, it is usually necessary to lock each data operation to ensure consistency, but this may lead to excessive system overhead and affect overall efficiency. Insufficient scalability means that some existing designs cannot well support hierarchical data organization structures (such as devices, data points, and data attributes), resulting in increased data management complexity and high maintenance costs.

[0025] In order to solve the above problems, the present application proposes an electronic device, which may be a device including one or more processors, such as an energy storage cabinet, a computer, a server, a touch-screen phone, a smart phone, a tablet computer, a portable electronic device or other electronic device. The processor may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application, which are not limited here. The one or more processors included in the electronic device may be processors of the same type, such as one or more CPUs; or they may be processors of different types, such as one or more CPUs and one or more ASICs, which are not limited here.

[0026] The electronic device is provided with a multi-layer nested object relationship structure, specifically including multiple device nodes, multiple groups of data nodes, device node containers and multiple data node containers. Each device node corresponds to a logical device, and each logical device has one or more types of data. Each group of data nodes is associated with a device node and stores the data of the logical device corresponding to the device node. Each group of data nodes includes one or more data nodes, wherein each data node is used to store a type of atomic data. Multiple device nodes are stored in the device node container, and multiple data node containers correspond one-to-one to multiple device nodes. Each data node container stores a group of data nodes associated with the corresponding device node. By setting up the structure in the above-mentioned multi-layer nested manner, the problems of lock contention, performance bottlenecks and insufficient scalability in the prior art can be solved, and the overall performance and stability of the data cache system in complex application scenarios can be significantly improved.

[0027] To better introduce the object relationship structure, Figure 1 FIG. 1 shows a schematic diagram of cache management data provided by an embodiment of the present application. Figure 1As shown, the electronic device includes a node manager, which is responsible for the unified management of the cache resources of the entire system. It is the top-level entry and has a device node container inside. The device node container can use hash or binary tree as a search engine, and its time complexity is lg(n). It can quickly retrieve the target device node in the device node container, and use the device identifier (devId) as the index to store the device node, supporting concurrent access. The device node container stores device node 1 and device node 2, where device node 1 and device node 2 correspond to a logical device respectively, and contain multiple data point sets. For example, the device node container corresponds to an energy storage cabinet, and device node 1 and device node 2 correspond to the industrial air conditioner and fan in the energy storage cabinet respectively. One device node corresponds to one data node container, Figure 1 Device node 1 corresponds to data node container 1, and device node 2 corresponds to data node container 2. The container is protected by a read-write lock. A read lock is set to read the device node, and multi-threaded concurrent reading is supported. A write lock is set to add or delete device nodes to ensure modification security. Similarly, the data node container uses a read-write lock mechanism to implement concurrent reading and modification protection for data nodes. The data node container can use a hash or binary tree as a search engine, with a time complexity of lg(n). The target data node can be quickly retrieved, and the data node identifier (datapointId) is used as the index to store the data node, supporting concurrent access.

[0028] It is understood that a logical device typically includes one or more types of data. For example, an industrial air conditioner includes data such as current and voltage, which are two types of data. To store the data of a logical device, this application stores the data of a logical device by setting up a group of data nodes. Specifically, if only one type of data of a logical device needs to be stored, a corresponding data node is set up; if multiple types of data of a logical device need to be stored, multiple data nodes are set up, and each data node stores one type of data. A data node is the smallest unit of data and is responsible for storing the current value of a specific collection item and its timestamp. Figure 1 In the example, device node 1 is stored in data node container 1 corresponding to device node 1. Data node 1 and data node 2 are each used to store a type of data for the logical device corresponding to device node 1. For example, if the logical device corresponding to device node 1 is an industrial air conditioner, data node 1 and data node 2 can be used to store two types of data, current and voltage, for the industrial air conditioner, respectively.

[0029] For a type of data in a logical device, there may be one or more parameters. These parameters are all valuable for analysis and utilization, so they all need to be stored for subsequent use. Therefore, in this application, these parameters are stored in the data node as atomic data, with one atomic data corresponding to one parameter. Atomic data refers to data that supports atomic operations (Compare-And-Swap, CAS). Atomic data is an encapsulated object of a data point value and time, and is written concurrently through an atomic update mechanism to avoid the performance loss caused by locking.

[0030] by Figure 1 Taking the atomic data 1 and atomic data 2 included in the data node 1 as an example, for example, the logical device corresponding to the device node 1 is an industrial air conditioner, and the data node 1 is used to store the current type data of the industrial air conditioner. For the current of the industrial air conditioner, there may be a current collection frequency and a collected current value. Since the current collection frequency and the current value are two different parameters in the current type data, in the embodiment of the present application, the current collection frequency and the current value are stored in the data node 1 in the form of atomic data 1 and atomic data 2 respectively. Figure 1 For other device nodes, data node containers, data nodes, and atomic data, please refer to the introduction of device node 1, data node container 1, data node 1, atomic data 1, and atomic data 2, which will not be repeated here.

[0031] It is worth mentioning that Figure 1 The example of storing two device nodes in a device node container is used for illustration. This application does not limit the number of device nodes. In some embodiments, a device node container can also store three or more device nodes, which will not be described here. Figure 1 In the example, only two data nodes are included in data node container 1 and data node container 2 respectively. This application does not limit the number of data nodes. In some embodiments, a data node container may include only one data node, or three or more data nodes. Figure 1 In the present invention, only one, two or three atomic data are stored in the data node as an example. This application does not limit the number of atomic data stored in the data node. In some embodiments, the data node can also store four or more atomic data.

[0032] In the settings such as Figure 1 In the electronic device with the object relationship structure shown, in order to solve the problems of read-write conflicts, coarse lock granularity, performance bottlenecks, etc. existing in the traditional cache architecture in high-concurrency data access scenarios, the embodiment of the present application proposes a data cache management method. Figure 2 A flow chart of a data cache management method provided by an embodiment of the present application is shown, which is provided with Figure 1 The electronic device executes the multi-layer nested object relationship structure shown. Figure 2 As shown, the method includes the following steps:

[0033] Step 110: The first thread applies for a first operation lock from the operating system in the device node container.

[0034] A thread is the smallest unit that an operating system can use to schedule operations. In this application, an operating system refers to the system of the electronic device, and a first thread is a thread of the operating system.

[0035] When a thread (for example, thread A) is accessing a device node, if another thread (for example, thread B) is deleting or adding the device node, thread A may be unable to access the device node normally. Therefore, to avoid this situation and ensure that thread A can normally access, delete, and add device nodes, this application uses a locking mechanism to manage device nodes.

[0036] Specifically, if a thread (e.g., thread A) needs to access a device node, thread A must apply for a first read lock from the operating system in the device node container. If thread A needs to delete a device node stored in the device node container, or add a new device node to the device node container, thread A must apply for a first write lock from the operating system in the device node container. Therefore, in this embodiment of the present application, the first operational lock can be either a first read lock or a first write lock.

[0037] To improve the efficiency of device node management, in some embodiments, an operation lock can be set for each device node. For example, if a thread (such as thread C) needs to access device node 1, and a thread (such as thread D) needs to delete device node 2, thread C can request a read lock on device node 1 from the operating system in the device node container, and thread D can request a write lock on device node 2 from the operating system in the device node container. Thus, while thread C accesses device node 1 using the read lock on device node 1, thread D can also simultaneously delete device node 2 using the write lock on device node 2. Since threads C and D can perform read and write tasks in parallel, the efficiency of device node management is improved.

[0038] In the above method, since an operation lock needs to be set for each device node, when the number of device nodes is large, the lock overhead will be large, thereby reducing the performance of the operating system. Therefore, in an embodiment of the present application, in order to reduce the lock overhead and improve the performance of the operating system, preferably, the first thread can manage all device nodes through the first operation lock. That is, if the first operation lock is a first read lock, the first thread can access all device nodes through the first read lock; if the first operation lock is a first write lock, the first thread can delete each device node or add other device nodes through the first write lock.

[0039] Step 120: The operating system issues a first operation lock to the first thread.

[0040] To avoid the situation where a thread (for example, thread A) is unable to access a device node normally because other threads (for example, thread B) delete or add device nodes when a certain thread (for example, thread A) is accessing a certain device node, in this step, if the first operation lock is a first read lock, then before the operating system issues the first read lock to thread A, the operating system first determines whether it has issued a first write lock to other threads. If the operating system has issued the first write lock to other threads (for example, thread B), the operating system issues the first read lock to thread A after thread B finishes using the first write lock. If the operating system has not issued the first write lock to other threads, the operating system directly issues the first read lock to thread A.

[0041] It should be noted that if the first operational lock is a first read lock, before the operating system issues the first read lock to thread A, if the operating system has already issued the first read lock to another thread (such as thread C), but thread C does not delete or add device nodes when accessing the device node through the first read lock, that is, thread C does not change the data of the device node, then when thread C accesses the device node, thread A can also access the device node normally. Therefore, the operating system can also directly issue the first read lock to thread A. In other words, in this embodiment of the present application, multiple threads can access the device node in parallel through the first read lock, rather than multiple threads taking turns to access the device node through the first read lock, thereby improving the efficiency of reading atomic data.

[0042] Similarly, if the first operational lock is the first write lock, before the operating system grants the first write lock to thread A, it first determines whether it has already granted the first read lock or the first write lock to other threads. If the operating system has already granted the first read lock to thread B, it grants the first write lock to thread A after thread B completes its use of the first read lock. Alternatively, if the operating system has already granted the first write lock to thread B, it grants the first write lock to thread A after thread B completes its use of the first write lock. If the operating system has not granted the first read lock or the first write lock to other threads, it directly grants the first write lock to thread A.

[0043] In an embodiment of the present application, the above-mentioned setting can avoid the situation where a certain thread (for example, thread A) adds or deletes a device node while other threads (for example, thread B) are accessing a device node, resulting in thread A being unable to access the device node normally. It can also avoid the situation where thread B adds or deletes a device node while thread A is adding or deleting a device node, resulting in operation conflicts, data inconsistency, or confusion in the status of the device node.

[0044] Step 130: The first thread receives the first operation lock and manages the device node through the first operation lock.

[0045] like Figure 1 As shown, for multiple device nodes, each device node corresponds to a different identifier (i.e., index), so the first thread can distinguish and search for each device node by the identifier of the device node. In this step, if the first operation lock is the first read lock, the first thread can set the first read lock for all device nodes, and then search and determine the target device node from the multiple device nodes by the target device identifier. If the first thread successfully determines the target device node identified as the target device identifier from the multiple device nodes, the subsequent steps can be executed; if the first thread cannot successfully determine the target device node identified as the target device identifier from the multiple device nodes, it means that the target device identifier is wrong, or the target device node has been deleted, and then the process ends.

[0046] It is worth noting that in this application, after the first thread obtains the first read lock, by setting the first read lock for the device node, it can prevent other threads from adding or deleting device nodes during the period when the first thread accesses the device node, resulting in the first thread being unable to access the device node normally. Specifically, when a thread (such as thread A) sets a read lock for the device node, other threads (such as thread B) cannot obtain a write lock, that is, thread B cannot set a write lock for the device node at the same time, thereby ensuring that thread A can access the device node normally. When thread A finishes accessing the device node, thread A will release the read lock it holds. At this time, if there are other threads (such as thread B) waiting to obtain the write lock, the operating system will issue the write lock to thread B, allowing it to safely perform modification operations on the device node (such as adding or deleting device nodes).

[0047] If the first operation lock is the first write lock, the situation is similar to that when the first operation lock is the first read lock, and will not be repeated here. In general, in this application, by setting read-read non-mutually exclusive, read-write mutually exclusive, write-write mutually exclusive, and write-read mutually exclusive mechanisms, the operating system can effectively manage concurrent access and modification to device nodes, ensuring the consistency of device node data and the atomicity of operations, and improving the stability and reliability of the system in a multi-threaded environment.

[0048] Step 140: The second thread applies to the operating system for a second operation lock in a target data node container among the multiple data node containers.

[0049] The second operation lock is similar to the first operation lock. The second operation lock can also be a second read lock and a second write lock. The principle and purpose of the second operation lock are the same as those of the first operation lock. Figure 1 As shown, for multiple data node containers, each data node container corresponds to a different identifier. Therefore, the second thread can distinguish the data node containers by the data node container identifier. The second thread and the first thread can be the same thread or different threads. This example uses the first thread and the second thread as thread A.

[0050] After obtaining the first operation lock, thread A sets the first operation lock for all device nodes and then searches and determines the target device node from multiple device nodes using the target device node identifier. If thread A successfully determines the target device node identified as the target device identifier from the multiple device nodes, in this step, thread A applies to the operating system for a second operation lock in the target data node container corresponding to the target device node.

[0051] Specifically, if thread A needs to access the target data node to manage the atomic data stored there (for example, to read or modify the atomic data), thread A needs to apply for a second read lock from the operating system in the target data node container corresponding to the target device node. If the second thread needs to delete a data node stored in the target data node container or add a new data node to the target data node container, thread A needs to apply for a second write lock from the operating system in the target data node container.

[0052] Similar to device nodes, in some embodiments, to improve the efficiency of data node management, an operation lock can be set for each data node. For example, if a thread (e.g., thread C) needs to access data node 1 stored in data node container 1, and a thread (e.g., thread D) needs to delete data node 2 stored in data node container 1, thread C can request a read lock for data node 1 from the operating system in data node container 1, and thread D can request a write lock for data node 2 from the operating system in data node container 1. This allows thread C to access the atomic data stored on data node 1 using the read lock on data node 1 while thread D can simultaneously delete data node 2 using the write lock on data node 2. This improves the efficiency of data node management because threads C and D can execute read and write tasks in parallel.

[0053] In the above method, since an operation lock needs to be set for each data node, when the number of data nodes is large, the lock overhead will be large, thereby reducing the performance of the operating system. Therefore, in an embodiment of the present application, in order to reduce the lock overhead and improve the performance of the operating system, preferably, the second thread can manage all data nodes stored in the target data node container through the second operation lock, and read or modify the atomic data stored in the target data node. That is, if the second operation lock is a second read lock, the second thread can access all data nodes in the target data node container through the second read lock; if the second operation lock is a second write lock, the second thread can delete any data node in the target data node container through the second write lock, or add other data nodes to the target data node container.

[0054] Step 150: The operating system issues a second operation lock to the second thread.

[0055] This step is similar to step 120. To avoid the situation where thread B deletes or adds a data node when thread A accesses a data node to manage the atomic data stored in the data node, causing thread A to be unable to manage the atomic data normally, in this step, if the second operation lock is a second read lock, then before the operating system issues the second read lock to thread A, the operating system first determines whether it has issued a second write lock to other threads, wherein the second write lock is used to add or delete data nodes in a group of data nodes associated with the target device node. If the operating system has issued the second write lock to thread B, the operating system will issue the second read lock to thread A after thread B finishes using the second write lock; if the operating system has not issued the second write lock to other threads, the operating system will directly issue the second read lock to thread A.

[0056] It should be noted that if the second operation lock is a second read lock, before the operating system issues the second read lock to thread A, if the operating system has already issued the second read lock to other threads (such as thread C), but because thread C accesses the target data node through the second read lock, it will not delete or add the data nodes stored in the target data node container. Then when thread C accesses the data node in the target data node container, thread A can also access the target data node normally. Therefore, at this time, the operating system can also directly issue the second read lock to thread A. In other words, in this embodiment of the present application, multiple threads can access the data nodes stored in the same data node container in parallel through the second read lock, rather than multiple threads taking turns to access the data nodes stored in the same data node container through the second read lock, thereby improving the efficiency of reading atomic data.

[0057] Similarly, if the second operational lock is a second write lock, before the operating system issues the second write lock to thread A, it first determines whether it has already issued a second read lock for accessing the data nodes stored in the target data node container to other threads, or whether it has already issued a second write lock for adding or deleting data nodes from the set of data nodes associated with the target device node to other threads. If the operating system has already issued the second read lock to thread C, the operating system will issue the second write lock to thread A after thread C completes using the second read lock. Alternatively, if the operating system has already issued the second write lock to thread C, the operating system will issue the second write lock to thread A after thread C completes using the second write lock. If the operating system has not issued the second read lock or the second write lock to other threads, the operating system will directly issue the second write lock to thread A.

[0058] In an embodiment of the present application, the above-mentioned setting can avoid the situation where, when a certain thread (for example, thread A) accesses the target data node stored in the target data node container, other threads (for example, thread B) add or delete data nodes in a group of data nodes associated with the target device node, resulting in thread A being unable to access the target data node normally. It can also avoid the situation where, when thread A adds or deletes data nodes in a group of data nodes associated with the target device node, thread B simultaneously adds or deletes data nodes in a group of data nodes associated with the target device node, resulting in operation conflicts, data inconsistency, or data node status confusion.

[0059] Step 160: The second thread operates the atomic data stored in the target data node in the target data node container through the second operation lock.

[0060] This step is similar to step 130 , and therefore, the principle and implementation of this step may refer to step 130 .

[0061] In an embodiment of the present application, based on the characteristics of atomic data, multiple threads can perform read and write operations on atomic data in parallel, and there will be no situation where the atomic data read by the thread is erroneous data. Specifically, if thread A is modifying atomic data, and thread B reads the atomic data at this time, the atomic data read by thread B may be the atomic data before thread A modified it, or it may be the atomic data after thread A modified it, thereby ensuring that the atomic data read by thread B is accurate data, rather than other erroneous data. For example, atomic data 1 is the current value obtained by collecting the current of the industrial air conditioner at the current moment. After collecting the latest current value at the current moment, thread A modifies atomic data 1 to the new current value. If thread B reads atomic data 1 at the same time while thread A is modifying atomic data 1, the current value read by thread B may be the current value collected at the previous moment (i.e., the current value before thread A modified it) or the new current value collected at the current moment (i.e., the current value after thread A modified it).

[0062] Combined with the previous introduction, if the second thread (such as thread A) needs to read or modify the atomic data stored in the target data node in the target data node container, thread A applies to the operating system for and obtains the first read lock in the device node container, sets the first read lock for the device node to access the device node, and then determines the target device node from multiple device nodes through the target device node identifier. Then, after applying to the operating system for and obtaining the second read lock in the target data node container corresponding to the target device node, it sets the second read lock for all data nodes in the target data node container, so that thread A can read or modify the atomic data stored in the data nodes in the target data node container.

[0063] After obtaining the data node object, a new value and time structure is constructed (e.g., value = 123.4, timestamp = 1718181000), and the atomic interface of CAS semantics (e.g., atomic reference encapsulation) is used to assign values ​​to the atomic data object under the data node. This ensures that simultaneous updates under multiple threads are automatically guaranteed consistent by the underlying hardware, and lock contention does not occur. This design is particularly suitable for scenarios such as sensor reporting, real-time monitoring of data streams, and concurrent writing.

[0064] Step 160 may also be the second thread managing the data nodes stored in the target data node container through the second operation lock, in which case the second operation lock is a second write lock. Specifically, if the second thread needs to add or delete a data node in a group of data nodes associated with the target device node, the second thread applies to the operating system for and obtains a first read lock in the device node container, sets a first read lock for the device node to access the device node, then determines the target device node from multiple device nodes using the target device node identifier, and then applies to the operating system for and obtains a second write lock in the target data node container corresponding to the target device node. Then, the data node can be added or deleted in the group of data nodes associated with the target device node.

[0065] In the embodiments of the present application, by utilizing data nodes to store atomic data and hierarchically managing device nodes and data nodes, multiple threads can access or operate data nodes in different data node containers in parallel, thereby improving the efficiency of managing data nodes. Furthermore, in the embodiments of the present application, through the above-mentioned configuration, multiple threads can read or modify atomic data in parallel, which improves the efficiency of cache management of atomic data stored in data nodes, compared to the method in which multiple threads can only read and write data in turn.

[0066] Furthermore, in embodiments of the present application, a hierarchical read-write lock mechanism refines lock granularity to the device node and data node levels, enabling multiple threads to simultaneously operate on different device nodes or data nodes, significantly improving concurrency. Furthermore, the present application utilizes write locks only when adding or deleting device nodes or data nodes. All other update and write operations (i.e., atomic data updates) are handled via concurrent read locks and lock-free mechanisms, significantly improving performance in scenarios with high-frequency atomic data writes. The present application utilizes a container management approach based on a balanced binary tree, using an indexing mechanism to quickly locate device nodes and their data nodes, avoiding performance bottlenecks caused by traversing data structures. Addressing the prior art's reliance on locks for reading and writing single data point attributes, the present application utilizes atomic templates to manage key attributes (such as value and time), ensuring data consistency and efficiency in multi-threaded environments without requiring additional locks, thereby reducing performance overhead. Through a hierarchical design and indexing mechanism, the present application supports the dynamic addition and deletion of device nodes and data nodes, ensuring operational efficiency under high concurrency, making it suitable for a variety of scenarios, including real-time monitoring systems and distributed caching systems.

[0067] In general, through the above improvements, this application solves the problems of lock competition, performance bottlenecks and insufficient scalability in the existing technology while meeting the needs of high concurrent reading and writing, and improves the overall performance and stability of the cache system in complex application scenarios.

[0068] In this application, read-write locks are finely granularly distributed, and read-write locks are deployed at the container level and device level respectively to achieve "control point sinking", greatly reducing the probability of lock contention; the atomic update mechanism is used to avoid the context switching overhead caused by frequent locking, and adapt to high-frequency small data writing scenarios; combined with structural encapsulation decoupling, numerical values ​​and time are independently encapsulated objects, which do not rely on specific languages ​​​​(such as C++) and are more conducive to cross-platform implementation; because the core logic is uniformly controlled by atomic semantics and read-only access, the design is clear and easy to expand, thereby achieving a balance between concurrency safety and maintainability.

[0069] Moreover, in this application, read and write locks are used to distinguish between read and write operations, read operations are concurrent, and write operations are exclusive, thereby improving the overall concurrent access performance. <valuetimepair>, avoiding locking operations and achieving efficient thread-safe data updates. By controlling the thread safety of structural change operations, data structure inconsistencies are prevented. By defining clear data writing paths and data retrieval processes, mutual blocking is avoided, improving system response efficiency.

[0070] Figure 3 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. The specific embodiment of the present application does not limit the specific implementation of the electronic device.

[0071] like Figure 3 As shown, the electronic device 200 may include a processor 202 and a memory 204 .

[0072] The memory 204 is used to store a computer program 206. The memory 204 may include a high-speed RAM memory, or may also include a non-volatile memory (non-volatile memory), such as at least one disk memory. The computer program 206 may include computer-executable instructions.

[0073] The processor 202 is configured to execute the computer program 206 to implement the above-mentioned data cache management method embodiment.

[0074] Processor 202 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in electronic device 200 may be processors of the same type, such as one or more CPUs, or may be processors of different types, such as one or more CPUs and one or more ASICs.

[0075] It is worth noting that the electronic device 200 is also provided with Figure 1 The object relationship structure shown, Figure 3 Not shown in the figure.

[0076] An embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned data cache management method embodiment is implemented.

[0077] An embodiment of the present application provides a computer program, which can be executed by a processor to implement the above-mentioned data cache management method embodiment.

[0078] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the computer program implements the above-mentioned data cache management method embodiment.

[0079] In the several embodiments provided in this application, if any function is implemented in the form of a software function module / unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the technical solution of this application can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, server or other electronic device) to execute all or part of the steps of the method described in each embodiment of this application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store computer program code.

[0080] The algorithm or demonstration provided here are not inherently relevant to any particular computer, virtual system or other equipment. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious that the structure required for constructing this type of system. In addition, the present application embodiment is not directed to any specific programming language yet. It should be understood that various programming languages ​​can be utilized to realize the content of the present application described here, and the above description of specific languages ​​is for the purpose of disclosing the best mode of implementation of the present application.

[0081] It should be noted that the above embodiments illustrate rather than limit the present application, and that a person skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between brackets should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present application may be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In claims that list several means, several units or modules of these means may be embodied by the same item of hardware. The use of the words first, second, and third etc. does not indicate any order. These words may be interpreted as names. The steps in the above embodiments should not be understood as limiting the order of execution unless otherwise specified.

[0082] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.< / valuetimepair>

Claims

1. A data cache management method, applied to an electronic device, characterized in that: The electronic device includes a plurality of device nodes, a plurality of groups of data nodes, a device node container, and a plurality of data node containers; Each of the device nodes corresponds to a logical device, and each of the logical devices has one or more types of data; each group of the data nodes is associated with a device node and stores the data of the logical device corresponding to the device node, and each group of the data nodes includes one or more data nodes, wherein each data node is used to store one type of atomic data; the device node container stores the multiple device nodes; the multiple data node containers correspond one-to-one to the multiple device nodes, and each data node container stores a group of the data nodes associated with the corresponding device node; the method includes: The first thread applies for a first operation lock from the operating system in the device node container; The operating system issues a first operation lock to the first thread; The first thread receives the first operation lock and manages the device node through the first operation lock; The second thread applies for a second operation lock from the operating system in a target data node container among the multiple data node containers; The operating system issues a second operation lock to the second thread; The second thread manages the data nodes stored in the target data node container through the second operation lock, and / or the second thread operates the atomic data stored in the target data node in the target data node container through the second operation lock; When the first operation lock is a first read lock and the second operation lock is a second read lock, the first thread receives the first operation lock and manages the device node through the first operation lock, including: The first thread receives the first read lock and accesses a target device node among the multiple device nodes through the first read lock; The second thread operates the atomic data stored in the target data node in the target data node container through the second operation lock, including: The second thread reads or modifies the atomic data stored in the target data node through the second read lock, wherein the target data node is a data node associated with the target device node; When the first operation lock is a first read lock and the second operation lock is a second write lock, the first thread receives the first operation lock and manages the device node through the first operation lock, including: The first thread receives the first read lock and accesses a target device node among the multiple device nodes through the first read lock; The second thread manages the data nodes stored in the target data node container through the second operation lock, including: The second thread adds or deletes a data node from a group of data nodes associated with the target device node through the second write lock.

2. The method according to claim 1, characterized in that The first thread can manage all device nodes through the first operation lock.

3. The method according to claim 1, characterized in that The second thread can manage all data nodes stored in the target data node container and read or modify the atomic data stored in the target data node through the second operation lock.

4. The method according to claim 1, wherein When the first operation lock is a first write lock, the first thread receives the first operation lock and manages the device node through the first operation lock, including: The first thread receives the first write lock and adds or deletes a device node through the first write lock.

5. The method according to claim 1, characterized in that When the first operation lock is the first read lock, the operating system issues the first operation lock to the first thread, including: The operating system determines whether a first write lock has been issued to other threads, wherein the first write lock is used to add or delete a device node; If the operating system has issued the first write lock to the third thread, the operating system issues the first read lock to the first thread after the third thread finishes using the first write lock; If the operating system does not issue the first write lock to other threads, the operating system directly issues the first read lock to the first thread; When the second operation lock is the second read lock, the operating system issues the second operation lock to the second thread, including: The operating system determines whether a second write lock has been issued to other threads, wherein the second write lock is used to add or delete a data node in a group of data nodes associated with the target device node; If the operating system has issued the second write lock to the fourth thread, the operating system issues the second read lock to the second thread after the fourth thread finishes using the second write lock; If the operating system does not issue the second write lock to other threads, the operating system directly issues the second read lock to the second thread.

6. The method according to claim 4, characterized in that When the first operation lock is the first write lock, the operating system issues the first operation lock to the first thread, including: The operating system determines whether the first read lock or the first write lock has been issued to other threads, wherein the first read lock is used to access the device node; If the operating system has already issued the first read lock to the fifth thread, the operating system issues the first write lock to the first thread after the fifth thread finishes using the first read lock; or if the operating system has already issued the first write lock to the fifth thread, the operating system issues the first write lock to the first thread after the fifth thread finishes using the first write lock; If the operating system does not issue the first read lock and the first write lock to other threads, the operating system directly issues the first write lock to the first thread.

7. The method according to claim 1, characterized in that When the first operation lock is the first read lock, the operating system issues the first operation lock to the first thread, including: The operating system determines whether a first write lock has been issued to other threads, wherein the first write lock is used to add or delete a device node; If the operating system has issued the first write lock to the sixth thread, the operating system issues the first read lock to the first thread after the sixth thread finishes using the first write lock; If the operating system does not issue the first write lock to other threads, the operating system directly issues the first read lock to the first thread; When the second operation lock is the second write lock, the operating system issues the second operation lock to the second thread, including: The operating system determines whether a second read lock or the second write lock has been issued to other threads, wherein the second read lock is used to access the data node stored in the target data node container; If the operating system has already issued the second read lock to the seventh thread, the operating system issues the second write lock to the second thread after the seventh thread finishes using the second read lock; or if the operating system has already issued the second write lock to the seventh thread, the operating system issues the second write lock to the second thread after the seventh thread finishes using the second write lock; If the operating system does not issue the second read lock and the second write lock to other threads, the operating system directly issues the second write lock to the second thread.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory, wherein: The electronic device includes a plurality of device nodes, a plurality of groups of data nodes, a device node container, and a plurality of data node containers; each of the device nodes corresponds to a logical device, and each of the logical devices has one or more types of data; each group of data nodes is associated with a device node and stores the data of the logical device corresponding to the device node, and each group of data nodes includes one or more data nodes, wherein each data node is used to store a type of atomic data; the plurality of device nodes are stored in the device node container; the plurality of data node containers correspond one-to-one to the plurality of device nodes, and each data node container stores a group of data nodes associated with the corresponding device node; The processor executes the computer program to implement the data cache management method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Read lock operation method, write lock operation method and system

    CN104572568A

  • Data system, data access method and device and data processing unit

    CN115981547A