Method and system for memory management in a timing engine

By managing the timing engine's memory using Apache Arrow, and dividing the storage space using Buffer and ArrayData to generate Block and ImmuMemTable, the problems of memory fragmentation and leakage are solved, improving memory management efficiency and performance.

CN115437787BActive Publication Date: 2026-11-27上海沄熹科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211038992.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-29
Publication Date
2026-11-27
Estimated Expiration
2042-08-29

AI Technical Summary

Technical Problem

How to improve the efficiency of memory allocation and release in timing engines, avoid memory fragmentation and memory leaks, especially how to share memory in multi-process communication between cloud, edge and device.

Method used

Apache Arrow is used for memory management. By allocating a data buffer for ObjectTable and casting it to a different type of ArrayData when writing data, the storage space is divided by moving the pointer to the right, and Block and ImmuMemTable are generated to avoid memory fragmentation and leaks.

Benefits of technology

It improved the efficiency of memory allocation and deallocation, reduced memory fragmentation and leaks, and improved write and query performance by 10% and 15%, respectively.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115437787B_ABST
    Figure CN115437787B_ABST
Patent Text Reader

Abstract

The application discloses a time sequence engine memory management method and system, belongs to the technical field of distributed databases, and aims to solve the technical problem of how to improve the efficiency of time sequence engine memory application and release and avoid memory fragmentation and memory leakage.The method comprises the following steps: allocating a data buffer area Buffer for an ObjectTable through Apache Arrow; converting the data buffer area Buffer into different types of ArrayData; and writing data into the data buffer area Buffer based on a right shift of a pointer, and the following is executed when the data is written: after the current storage space is full, a Block generated by the current storage space is added to an ObjectBlock container; when the MemTable is full of data, an ImmuMemTable is generated by the MemTable, disk flushing is waited for, and a new MemTable is created after the writing process is completed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of distributed database technology, specifically to a time-series engine memory management method and system. Background Technology

[0002] my country is currently in a crucial stage of rapid economic and social development. In the process of industrialization, informatization, and urbanization, it faces numerous challenges, such as the contradiction between energy and the environment and greenhouse gas emissions, and the balance between resource and energy development and utilization efficiency. Addressing the energy conservation and emission reduction needs of industrial parks, hospitals, universities, airports, and other similar institutions in their operation and management, this platform utilizes big data, IoT, and cloud computing technologies to create a digital energy management platform for users. The platform focuses on application scenarios such as new energy microgrid control, energy conservation and low carbon emissions, energy storage and utilization, multi-energy complementarity, intelligent operation and maintenance, real-time monitoring, charging network energy management, and carbon asset management. This enhances users' comprehensive energy and carbon asset management capabilities, helping enterprises reduce costs and increase efficiency. The digital energy management platform is a cloud-edge-device collaborative distributed new energy microgrid management platform. ZDP, as the core component of the digital energy management platform, uses the distributed multi-mode database ZNBase as its core, providing data and algorithm support for both the cloud-based multi-tenant energy management SaaS service and the edge-end energy router microgrid management system.

[0003] Based on the above scenario, ZNBase currently supports multiple modes of OLTP and OLAP, requiring the development of time-series engines, each deployed on the cloud and edge, to complete the storage and synchronization of time-series data. The cloud-edge architecture dictates that the system is a multi-process task, and communication between these processes requires shared memory. Therefore, improving the efficiency of memory allocation and deallocation for the time-series engine, and avoiding memory fragmentation and leaks, are technical challenges that need to be addressed. Summary of the Invention

[0004] The technical objective of this invention is to address the above-mentioned shortcomings by providing a timing engine memory management method and system to solve the technical problems of how to improve the efficiency of timing engine memory allocation and release, and avoid memory fragmentation and memory leaks.

[0005] In a first aspect, the present invention provides a memory management method for a timing engine, which manages the memory of the timing engine based on Apache Arrow, and includes the following steps:

[0006] In the memory module of the timing engine, a data buffer is allocated for the ObjectTable via Apache Arrow. The ObjectTable is used to store the timing data of objects.

[0007] When writing data to the data buffer, the data buffer is cast to a different type of ArrayData;

[0008] The data buffer is divided into multiple storage spaces. Data is written to the data buffer by moving the pointer to the right. The following steps are performed when writing data:

[0009] Once the current storage space is full, a Block is generated from the current storage space and added to the ObjectBlock container. A Block is the basic unit that constitutes a MemTable. During the data writing process, the ObjectTable is marked as a MemTable and is in a writable state.

[0010] Once the MemTable is full of data, it generates an ImmuMemTable, which is in a non-writable state. The ImmuMemTable is then written into a vector and is left to be flushed to disk for persistence. After the write process is complete, a new MemTable is created.

[0011] Preferably, a data buffer is allocated to the ObjectTable using a first allocation method, wherein the first allocation method is:

[0012] Use Apache Arrow to request an entire memory region;

[0013] The memory region is divided using Allocate() and used by ObjectTables of different schemas.

[0014] Preferably, a data buffer is allocated to the ObjectTable using a second allocation method, wherein the second allocation method is:

[0015] Memory is allocated using Arrow.Allocate(), and the amount of memory allocated to Arrow is recorded in MemTable.

[0016] Preferably, after allocating a data buffer for the ObjectTable using the second allocation method, when writing data into the data buffer, an index of the data is constructed and the index is written into the data buffer as a head pointer.

[0017] In a second aspect, the present invention provides a timing engine memory management system that executes the timing engine memory management method as described in any one of the first aspects, the system comprising:

[0018] A memory allocation module is used to allocate a data buffer for ObjectTable in the memory module of the timing engine via Apache Arrow. ObjectTable is used to store the timing data of objects.

[0019] A type conversion module is provided, which is used to cast the data buffer to a different type of ArrayData when writing data to the data buffer.

[0020] The data writing module is used to write data to the data buffer, which has multiple storage spaces, based on a right-moving pointer. During data writing, the module performs the following:

[0021] Once the current storage space is full, a Block is generated from the current storage space and added to the ObjectBlock container. A Block is the basic unit that constitutes a MemTable. During the data writing process, the ObjectTable is marked as a MemTable and is in a writable state.

[0022] Once the MemTable is full of data, it generates an ImmuMemTable, which is in a non-writable state. The ImmuMemTable is then written into a vector and is left to be flushed to disk for persistence. After the write process is complete, a new MemTable is created.

[0023] Preferably, the memory allocation module is used to allocate a data buffer for the ObjectTable using a first allocation method, wherein the first allocation method is:

[0024] Use Apache Arrow to request an entire memory region;

[0025] The memory region is divided using Allocate() and used by ObjectTables of different schemas.

[0026] Preferably, the memory allocation module is used to allocate a data buffer for the ObjectTable using a second allocation method, wherein the second allocation method is:

[0027] Memory is allocated using Arrow.Allocate(), and the amount of memory allocated to Arrow is recorded in MemTable.

[0028] Preferably, when writing data to the data buffer allocated to the ObjectTable using the second allocation method, the writing module constructs an index for the data and writes the index as a head pointer into the data buffer.

[0029] The timing engine memory management method and system of the present invention have the following advantages:

[0030] 1. Apache Arrow's memory usage reflects a coarse-grained, on-demand allocation. The data to be processed is in large blocks, so there is no need for frequent memory allocation and deletion, and there is almost no memory fragmentation.

[0031] 2. Apache Arrow's unique memory array collection (record batch processing) can be used for message passing and inter-process communication, facilitating the implementation of shared memory;

[0032] 3. Based on Apache Arrow's timing engine memory management, this method has been tested and shows that, compared with the previous custom-encapsulated memory method, the performance of writing and querying is improved by 10% and 15%, respectively. Attached Figure Description

[0033] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0034] The invention will be further described below with reference to the accompanying drawings.

[0035] Figure 1 A structural diagram of Apache Arrow's memory management;

[0036] Figure 2 This is a flowchart of a timing engine memory management method according to Example 1. Detailed Implementation

[0037] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.

[0038] This invention provides a timing engine memory management method and system to solve the technical problems of how to improve the efficiency of timing engine memory allocation and release, and avoid memory fragmentation and memory leaks.

[0039] Example 1:

[0040] Apache Arrow is implemented based on Value Vector, which reduces the cost of repeatedly accessing data during computation. This storage method has an O(1) access speed, can be effectively cached, and information in the Value Vector can be directly transferred between different items, regardless of the programming language used.

[0041] In Arrow, the specific strategies for allocating and freeing memory in the system are still based on ptmalloc, tcmalloc, and jemalloc. These can be selected via parameters to encapsulate a memory pool and provide interfaces for allocating and freeing memory. If you need to implement your own memory pool for memory management, you only need to inherit the base class MemoryPool and implement the defined interfaces. Each time memory is allocated and freed, the variable bytes_allocated_ records the size of the memory allocated by that memory pool.

[0042] In Arrow, a Buffer is an abstraction of a block of memory data, containing a pointer to the memory block and its length. Memory areas used to store data for higher-level concrete types can all be represented using Buffers. The base class for these higher-level concrete types is encapsulated as ArrayData. See the detailed implementation class diagram. Figure 1 .

[0043] From a data integration perspective, Apache Arrow abstracts memory pools and buffers, encapsulating a series of interfaces. Developers can directly call these interfaces to request and use memory, and reclaim the memory after use by calling the interfaces. This eliminates the need to directly interact with system memory during development, greatly reducing the risk of memory fragmentation and leaks.

[0044] This invention discloses a memory management method for a timing engine, based on Apache Arrow for managing the memory of the timing engine, comprising the following steps:

[0045] S100. In the memory module of the timing engine, a data buffer is allocated for the ObjectTable through Apache Arrow. The ObjectTable is used to store the timing data of objects.

[0046] Step S100 allocates memory for Apache Arrow within the timing engine's memory module. There are two allocation schemes.

[0047] The first allocation method involves first requesting a whole memory region using `arrow`, and then using `Allocate()` to divide that memory region for use by ObjectTables in different schemas. The advantage is contiguous memory, but the disadvantage is that it's prone to memory allocation failures.

[0048] The second allocation method is as follows: when each ObjectTable is used, memory is requested using arrow.Allocate(), and the amount of memory already allocated for arrows is recorded in MemTable. The advantage is that when memory is insufficient, memory allocation for the next MemTable can be performed directly without failure. The disadvantage is that the memory areas in MemTable are not contiguous.

[0049] S200: When writing data to the data buffer, the data buffer is forcibly cast to a different type of ArrayData.

[0050] S300: The data buffer is divided into multiple storage spaces, and data is written to the data buffer by moving the pointer to the right.

[0051] During the data writing process, once the memory block is full, a Block is generated and added to the ObjectBlock container (used to store time-series data of an object within a certain time period). The Block is the basic unit that constitutes the MemTable. After the MemTable is full, an ImmuMemTable is generated and written to a vector, waiting to be flushed to disk for persistence. Once the writing process is complete, a new MemTable is created. This is the entire memory management process of the time-series engine based on Apache Arrow.

[0052] Considering the drawbacks of the second memory allocation method, after allocating a data buffer for ObjectTable using the second allocation method, when writing data into the data buffer, an index is constructed for the data and written into the data buffer as a head pointer. The index can accelerate data retrieval.

[0053] The method in this embodiment first calls AllocateBuffer to allocate a portion of memory in the system memory to store a fixed number of rows of data. After obtaining the head pointer of this memory block, the data is first written into this memory block to generate ActiveMemTable (writable). After ActiveMemTable is full, ImuMemTable (non-writable) is generated, and the data is then written to disk and saved to a file.

[0054] Example 2:

[0055] The present invention discloses a timing engine memory management system, including a memory allocation module, a type conversion module, and a data writing module. The system can perform memory management of the timing engine by executing the method disclosed in Embodiment 1.

[0056] The memory allocation module is used to allocate a data buffer for the ObjectTable in the memory module of the timing engine via Apache Arrow. The ObjectTable is used to store the timing data of objects.

[0057] In this embodiment, the memory allocation module supports two allocation schemes.

[0058] The first allocation method involves first requesting a whole memory region using `arrow`, and then using `Allocate()` to divide that memory region for use by ObjectTables in different schemas. The advantage is contiguous memory, but the disadvantage is that it's prone to memory allocation failures.

[0059] The second allocation method is as follows: when each ObjectTable is used, memory is requested using arrow.Allocate(), and the amount of memory already allocated for arrows is recorded in MemTable. The advantage is that when memory is insufficient, memory allocation for the next MemTable can be performed directly without failure. The disadvantage is that the memory areas in MemTable are not contiguous.

[0060] The type conversion module is used to cast the data buffer to a different type of ArrayData when writing data to the data buffer.

[0061] The data writing module is used to divide the data buffer into multiple storage spaces and write data to the data buffer based on a right-moving pointer. When writing data, it performs the following operations:

[0062] (1) After the current storage space is full, the current storage space generates a Block and adds it to the ObjectBlock container. The Block is the basic unit that constitutes the MemTable. During the data writing process, the ObjectTable is marked as MemTable and is in a writable state.

[0063] (2) When the MemTable is full of data, the MemTable is generated into an ImmuMemTable. The ImmuMemTable is in a non-writable state and is written into a vector, waiting to be flushed to disk for persistence. After the writing process ends, a new MemTable is created.

[0064] Considering the drawbacks of the second memory allocation method, if the data writing module writes data to the data buffer allocated through the second allocation method, it constructs an index for the data and writes the index as a head pointer into the data buffer. The index can accelerate data retrieval.

[0065] In this embodiment, the system call AllocateBuffer allocates a portion of memory in the system memory to store a fixed number of rows of data. After obtaining the head pointer of this memory block, the data is first written into this memory block to generate ActiveMemTable (writable). After ActiveMemTable is full, ImuMemTable (non-writable) is generated, waiting to be written to disk and then to a file.

[0066] The present invention has been shown and described in detail above with reference to the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art will know that more embodiments of the present invention can be obtained by combining the means in the different embodiments described above, and these embodiments are also within the protection scope of the present invention.

Claims

1. A timing engine memory management method, characterized in that, Managing the memory of the timing engine using Apache Arrow involves the following steps: In the memory module of the timing engine, a data buffer is allocated for an ObjectTable using Apache Arrow. The ObjectTable is used to store the timing data of objects. The allocation of the data buffer for the ObjectTable is carried out through a first allocation method, which involves: requesting a whole memory region using Apache Arrow; and then dividing the memory region into different Schema ObjectTables using Allocate(). The allocation of the data buffer for the ObjectTable is carried out through a second allocation method, which involves: requesting memory using Arrow.Allocate() and recording the amount of memory allocated for Arrow in MemTable. When writing data to the data buffer, the data buffer is cast to a different type of ArrayData; The data buffer is divided into multiple storage spaces. Data is written to the data buffer by moving the pointer to the right. The following steps are performed when writing data: Once the current storage space is full, a Block is generated from the current storage space and added to the ObjectBlock container. A Block is the basic unit that constitutes a MemTable. During the data writing process, the ObjectTable is marked as a MemTable and is in a writable state. Once the MemTable is full of data, it generates an ImmuMemTable, which is in a non-writable state. The ImmuMemTable is then written into a vector and is left to be flushed to disk for persistence. After the write process is complete, a new MemTable is created.

2. The timing engine memory management method according to claim 1, characterized in that, After allocating a data buffer for the ObjectTable using the second allocation method, when writing data into the data buffer, an index is constructed for the data and the index is written into the data buffer as a head pointer.

3. A timing engine memory management system, characterized in that, The system, which performs the timing engine memory management method as described in any one of claims 1-2, comprises: A memory allocation module is used to allocate a data buffer for ObjectTable in the memory module of the timing engine via Apache Arrow. ObjectTable is used to store the timing data of objects. A type conversion module is provided, which is used to cast the data buffer to a different type of ArrayData when writing data to the data buffer. The data writing module is used to write data to the data buffer, which has multiple storage spaces, based on a right-moving pointer. During data writing, the module performs the following: Once the current storage space is full, a Block is generated from the current storage space and added to the ObjectBlock container. A Block is the basic unit that constitutes a MemTable. During the data writing process, the ObjectTable is marked as a MemTable and is in a writable state. When MemTable is full of data, it generates ImmuMemTable, which is in a non-writable state. ImmuMemTable is written into a vector and waits for it to be flushed to disk for persistence. After the writing process is completed, a new MemTable is created. The memory allocation module is used to allocate a data buffer for the ObjectTable using a first allocation method, which is: to request a whole memory region using Apache Arrow; and to divide the memory region into different Schema ObjectTables using Allocate(). The memory allocation module is used to allocate a data buffer for the ObjectTable using a second allocation method, which is to request memory using Arrow.Allocate() and record the amount of memory allocated for Arrow in MemTable.

4. The timing engine memory management system according to claim 3, characterized in that, When writing data to the data buffer allocated to the ObjectTable using the second allocation method, the writing module constructs an index for the data and writes the index as a head pointer into the data buffer.

Citation Information

Patent Citations

  • Hybrid index memory database storage engine management method

    CN112667644A

  • Projection column query method and system based on Apache Arrow file format

    CN114896243A