A method for managing elastic metadata
Through the elastic scaling metadata management method, using fixed-length memory pools and shared memory bodies, combined with plug-in memory pools and reference counting mechanisms, the problem of memory waste and CPU resource waste in metadata storage during network traffic decoding is solved, and efficient storage is achieved. and scalability, reducing the performance loss of memory fragmentation and locking mechanisms.
Patent Information
- Application Number
- CN202410039430.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-10
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-01-10
AI Technical Summary
The existing technology has the problems of memory waste, CPU resource waste and low coding efficiency when storing metadata during the network traffic decoding process. Especially when the demand changes, it is necessary to manually modify the code or use the inefficient malloc to dynamically apply for memory, resulting in memory fragmentation. and cache hit rate decreased.
Adopting an elastic scaling metadata management method, it generates a fixed-length memory pool, calculates the memory size based on the metadata description file, uses a shared memory body to store metadata, and realizes flexible memory expansion and cross-thread transfer through plug-in memory pools and reference counting mechanisms. , avoid deep copy and lock mechanism, and control CPU consumption.
It achieves efficient storage of metadata fields in any combination, saves memory resources, improves the scalability of storage space and the elastic scalability of the CPU, solves the problems of memory waste and low coding efficiency, and reduces the problems caused by memory fragmentation and locking mechanisms. Performance loss.
Smart Images

Figure CN117707789B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of metadata management, and in particular to an elastically scalable metadata management method. Background Art
[0002] The program or subsystem used for network decoding is called a network protocol parser. It is also called a parser for short. It is a producer of metadata. In order to achieve network security detection or auditing purposes, a protocol parser is needed to decode network traffic and obtain key information.
[0003] In the field of network monitoring and network security, it is generally necessary to parse network traffic to generate metadata, and then send the metadata to the matching module for monitoring, or to the log module for generating logs, or to the disposal module for deciding the disposal method, etc. During these metadata transfer processes, caching metadata requires a lot of memory space.
[0004] Generally, the industry practice is to fix the number of metadata fields and the storage order through hard coding. Under the premise of hard coding, in order to reduce memory consumption, either malloc is used to dynamically apply for memory on the data plane, or a single memory pool technology is used to pre-allocate memory on the control plane. The following three points briefly describe the disadvantages of this method.
[0005] Disadvantages of hard coding:
[0006] 1) The memory space size of a single set of metadata is fixed. When the demand changes, some fields may be unnecessary, which causes unnecessary waste of memory and CPU resources.
[0007] 2) When requirements change and new metadata fields need to be added, the code needs to be modified manually, increasing the workload.
[0008] Disadvantages of using malloc dynamically allocated data:
[0009] 1) The malloc function is inefficient;
[0010] 2) Memory fragmentation will occur;
[0011] 3) Memory locality is poor and cache hit rate is reduced.
[0012] Disadvantages of separate memory pools:
[0013] 1) The metadata is divided into different combinations according to different network protocols. Each combination uses an independent memory pool. This seems to solve the problem of memory waste, but it also introduces new problems. When the protocol ratio in the target network traffic is uncertain, it is impossible to determine how much total space should be allocated to each memory pool. This will cause the engine to either not work properly or waste memory.
[0014] 2) When writing code, each protocol parser needs to write duplicate code, which leads to low coding efficiency. Summary of the invention
[0015] In view of this, the problem to be solved by the present invention is to provide an elastic metadata management method, which can efficiently store metadata fields in any combination form while saving memory resources.
[0016] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0017] A method for managing elastic scaling metadata, comprising:
[0018] Step 1: Generate a fixed-length memory pool, obtain the description files of all metadata to be transmitted to determine the combination type of metadata, obtain the registration information of metadata through the metadata name through the registration interface and store it in the registration queue, calculate the memory size of the metadata object based on the registration queue and the engine interface to build the first fixed-length memory pool;
[0019] Step 2: Retrieve a memory common body, retrieve a memory common body that can store any metadata from a fixed-length memory pool, and place it in a metadata queue;
[0020] Step 3: storing metadata: the parser parses the network traffic to generate metadata and stores it in the metadata queue and its corresponding memory public body;
[0021] Step 4: Release the metadata, call the shared memory on the metadata queue, and release the metadata through the metadata release interface.
[0022] Furthermore, the step 2 includes calling an external memory according to a metadata storage requirement set manually, wherein the memory common body is used to record the numerical information of the metadata, and the external memory is used to record the binary string of the metadata;
[0023] The common memory body includes pointer information and length information to locate the location and size of the external memory.
[0024] Furthermore, the description file includes type information recording the metadata type, name information recording the metadata name, and length information recording the length of the binary character string.
[0025] Furthermore, the registration information includes metadata type information and memory size information, so that the engine interface calculates the size of each memory common body according to the registration information.
[0026] Furthermore, the step three includes an opening interface of the metadata field to control whether the parser parses.
[0027] Furthermore, the step three includes an assignment interface, the metadata is stored in the memory common body, and the assignment interface is called to assign a value to the metadata, so that the metadata is associated with the memory common body.
[0028] Furthermore, the step four includes releasing metadata on the data plane, including obtaining the memory common body on the metadata queue, determining whether the metadata in the memory common body is complete, if not, waiting to obtain the next round of data packets, if yes, determining whether the metadata is processed across threads, if no, releasing the metadata in the memory common body; if yes, sending the metadata in the memory common body to other threads through the ring queue, and increasing the reference count by one.
[0029] Furthermore, the step 4 includes releasing the control plane metadata, including acquiring the memory common body on the metadata queue, and acquiring and releasing the metadata in the memory common body.
[0030] Furthermore, the external memory is placed in an external memory pool, and the expansion of the external memory pool includes: engine architecture expansion working in a pipeline manner, which can be expanded on only one piece of memory.
[0031] Furthermore, the expansion of the external memory pool includes: expanding the engine architecture by batch processing, and obtaining the optimal external memory pool size by continuously updating the algorithm.
[0032] The advantages and positive effects of the present invention are:
[0033] By obtaining the metadata description file during the program initialization phase and determining the size of the fixed-length memory pool using a combination method for storing metadata, a large amount of memory waste will not be caused. At the same time, metadata corresponding to multiple network protocols share a memory pool. The memory pool size can be directly controlled based on the metadata memory size and the number of concurrent network traffic sessions, without the need to allocate the size of each memory pool in proportion.
[0034] By setting pointer data and length data in a fixed-length memory pool to locate the location and size of the plug-in memory, the scalability of the metadata storage space is improved to match different storage requirements of different metadata.
[0035] By setting the opening interface of the metadata field, whether the parser generates metadata can be controlled according to whether the opening interface is turned on, thereby controlling the running memory of the CPU inside the hub, so as to control the elastic expansion and contraction of the CPU memory.
[0036] When metadata is processed across threads, the metadata is directly passed to other methods by increasing the reference count. Each thread releases only the reference count. When the reference count is cleared, the last release is the actual return of the memory to the memory pool or operating system, solving the problem of adding locking mechanisms or deep copies across threads. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0038] Figure 1 It is a flow chart of engine interface generation in an elastic scaling metadata management method of the present invention;
[0039] Figure 2 It is a flowchart of parser initialization in an elastic scaling metadata management method of the present invention;
[0040] Figure 3 It is a flowchart of parsing metadata in an elastically scalable metadata management method of the present invention;
[0041] Figure 4 This is a flowchart of releasing metadata in an elastic scaling metadata management method of the present invention. DETAILED DESCRIPTION
[0042] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0043] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which the present invention belongs. The terms used herein in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more of the related listed items.
[0044] The present invention provides an elastically scalable metadata management method, wherein the system includes a protocol parser, and the protocol parser is respectively intercommunication with a log module and a detection module. The protocol parser generates metadata, and distributes the metadata to the log module and the detection module according to the demand, and stores the metadata according to the metadata management method in order to save the storage memory of the metadata in the log module and the detection module.
[0045] like Figure 1 As shown, the metadata management method includes:
[0046] Step 1: Generate a fixed-length memory pool, obtain the description files of all metadata to be transmitted to determine the combination type of metadata, obtain the registration information of metadata through the metadata name through the registration interface and store it in the registration queue, calculate the memory size of each metadata object based on the registration queue and the engine interface to build the first fixed-length memory pool;
[0047] Each metadata generated by network traffic corresponds to a description file. Before the parser is initialized, the description file of the metadata is received. An example of a description file is:
[0048] uint8_thttp.method
[0049] uint8_t *http.uri
[0050] uint8_thttp.uri.len512
[0051] The first column indicates the data type of the metadata, the second column is the name of the metadata field, and if there is a binary string, there is a third column indicating the maximum length of the binary string.
[0052] The protocol parser obtains the description file of the metadata to be transmitted, determines the actual combination of the metadata fields to be sent, and builds the engine interface according to the actual combination.
[0053] like Figure 1 As shown in the figure, the generation process of the engine interface is: the program is automatically generated in the parser and the description file is read, the description file is parsed according to the specified format and the target code is output; the target code is saved in the parser process, and a unique ID is generated for all fields through a static hash algorithm, and the engine interface is generated based on the ID (corresponding to the engine source code in the figure).
[0054] like Figure 2 As shown in the figure, the functions of the registration interface are: input the name of the metadata, output the type information and memory size of the metadata, and the registration interface can be called by producers and consumers. The data containing the type information and memory size is defined as registration information, and the information is stored in the registration queue.
[0055] The engine interface calculates the memory size of metadata based on the metadata name, determines the metadata flow based on the number of registered information (metadata combination), calculates the metadata object (memory) size, and then determines the memory pool size. The memory pool does not need to be divided into memory pools for storing metadata of different transport protocols based on the usage ratio of metadata and its transport protocol, which improves the efficiency of memory pool generation without causing a large amount of memory waste.
[0056] After all metadata to be stored in this batch are stored in the fixed-length memory pool, the same method is used to obtain the description file of the next batch of metadata to build a second fixed-length memory pool.
[0057] Step 2: call the memory common body, call the memory common body that can store any metadata, and put it in the metadata queue.
[0058] like Figure 3 As shown, the parser receives and parses network traffic data of different transport protocols, including imap and http. In order to enable all metadata to share a memory pool, a memory common body (corresponding to the memory block in the figure) that can be used by multiple transport protocols is constructed. The type of transport protocol is determined according to the actual type. The memory common body of the corresponding size is called according to the metadata to be parsed, and the memory common body is placed in the metadata queue to facilitate the storage of metadata. The memory common body takes C language as an example:
[0059] union meta
[0060] {
[0061] struct {
[0062] uint8_t http_method;
[0063] uint8_t *http_uri;
[0064] uint8_t http_uri_len;
[0065] };
[0066] struct {
[0067] uint8_timap_method;
[0068] uint8_t *imap_from;
[0069] uint8_timap_from_len;
[0070] };
[0071] };
[0072] When the use requirements of metadata are different, the storage size of metadata is different. In order to improve the storage scalability of metadata, an external memory is provided.
[0073] An embodiment of the present application is: when the external memory is needed, the external memory is obtained and saved in the context of the parser for storing metadata. The metadata includes a binary string and numerical information, the external memory is used to store the binary string, the shared memory is used to store the numerical information, pointer information and length information of the metadata, and the external memory location is determined based on the pointer information and length information.
[0074] The external memory is located in the external memory pool. The construction method of the external memory pool includes: expanding the external memory pool through the engine architecture working in a pipeline manner, which can be expanded only within one piece of memory to save memory; or using the engine architecture of the batch processing architecture to expand the external memory pool.
[0075] Before each batch starts, the batch processing architecture obtains a slightly larger memory space from the memory pool. The memory space is calculated based on the metadata field enabled status when the engine starts. The calculation algorithm needs to be continuously updated to obtain the optimal memory space size. During the operation of the engine architecture, the rationality of the memory pool blocks is recorded and the data is saved. The next time the engine architecture starts, the memory pool size and memory block size will be automatically adjusted to reduce memory waste.
[0076] Step three, storing metadata, parsing network traffic and generating metadata, and storing it in the metadata queue and its corresponding memory common body.
[0077] Before the parser parses the metadata, it includes the metadata field opening interface. According to whether the opening interface is opened, it determines whether this field exists, controls whether the parser parses the metadata of the corresponding field, and then controls the CPU consumption of the parser. It realizes elastic scaling control of the CPU.
[0078] In order to link the memory common body with the metadata, after the metadata is stored in the memory common body, the assignment interface is called, and the assignment interface can generate different assignments according to the field data type. When there is an external memory, the assignment interface assigns values to the metadata fields in the memory common body and the foreign memory respectively.
[0079] After the metadata is stored in the memory common body, call the metadata complete interface to determine whether the metadata is complete. If yes, wait for the next metadata to be parsed. If no, repeat step 3 until the metadata in the memory common body is complete.
[0080] Step 4: Release the metadata, call the shared memory on the metadata queue, and release the metadata through the metadata release interface.
[0081] The detection module releases metadata in real-time processing, and does not need to obtain the metadata completely before releasing it. The log processing module sometimes needs to obtain the complete metadata to trigger processing. Therefore, releasing metadata includes releasing part of the metadata or releasing the complete metadata. The metadata processing methods include cross-thread processing or processing in the current thread. When metadata needs to be transferred across threads, there will be access conflicts. To resolve these conflicts, either a lock mechanism is introduced or a deep copy is performed, but the lock mechanism or deep copy will reduce the processing performance of the engine.
[0082] The data plane metadata release process in step 4 is as follows: obtain the memory common body on the metadata queue, check whether the metadata in the memory common body is complete, if not, wait to obtain the next round of data packets, if yes, check whether the metadata is processed across threads, if not, obtain and release the metadata in the memory common body; if yes, send the metadata in the memory common body to other threads through the ring queue, and increase the reference count by one.
[0083] In single-threaded processing, the process of acquiring and releasing metadata is: calling the metadata acquisition interface to acquire the required metadata fields, and then calling the metadata release interface to release the metadata.
[0084] The ring queue is a lock-free circular queue with the characteristics of batch dequeue and batch enqueue. When cross-thread processing is required, the metadata acquisition interface metadata field is called and stored in the ring queue, and the reference count is increased by one. By increasing the reference count, the metadata is directly passed to other threads, which can solve the problem of adding lock mechanisms or deep copies in cross-thread processing. When releasing metadata, each thread only releases the reference count. When the reference count is cleared, the last release is the actual return of memory to the memory pool or operating system.
[0085] Step 4 includes releasing the control plane metadata, including obtaining the memory common body on the metadata queue, and obtaining and releasing the metadata in the memory common body.
[0086] One embodiment of the present application is: in the field of network traffic processing, in order to ensure the accuracy of metadata, a deep copy is generally performed, which will also increase some performance loss and memory waste. In order to solve the problem of deep copy, metadata is classified into two categories, one is not across message frames (referred to as single packet), and the other is across message frames (referred to as cross-packet). When assigning a binary string in single-packet metadata, the pointer can be pointed to the message body cached by the engine. When the life cycle of the metadata is longer than the message, a deep copy has to be added. When assigning a binary string in cross-packet metadata, the external memory space is directly used during parsing, which can reduce deep copying across message frames, reducing performance loss and memory waste.
[0087] The embodiments of the present invention are described in detail above, but the contents described are only preferred embodiments of the present invention and cannot be considered to limit the scope of implementation of the present invention. All equivalent changes and improvements made within the scope of the present invention should still fall within the scope of this patent.
Claims
1. A method for managing elastic metadata, characterized in that: include, Step 1: Generate a fixed-length memory pool, obtain the description files of all metadata to be transmitted to determine the combination type of metadata, obtain the registration information of metadata through the metadata name through the registration interface and store it in the registration queue, calculate the memory size of the metadata object based on the registration queue and the engine interface to build the first fixed-length memory pool; Step 2: Retrieve a memory common body, retrieve a memory common body that can store any metadata from a fixed-length memory pool, and place it in a metadata queue; Step 3: storing metadata: the parser parses the network traffic to generate metadata and stores it in the metadata queue and its corresponding memory public body; Step 4: Release the metadata, call the shared memory on the metadata queue, and release the metadata through the metadata release interface; The step 4 includes releasing the metadata on the data plane, including obtaining the memory common body on the metadata queue, determining whether the metadata in the memory common body is complete, if not, waiting to obtain the next round of data packets, if yes, determining whether the metadata is processed across threads, if not, releasing the metadata in the memory common body; Yes, the metadata in the common memory is sent to other threads through the ring queue, and the reference count is increased by one.
2. The elastic scaling metadata management method according to claim 1, characterized in that: The step 2 includes calling the external memory according to the metadata storage requirement set manually, wherein the memory common body is used to record the numerical information of the metadata, and the external memory is used to record the binary string of the metadata; The common memory body includes pointer information and length information to locate the location and size of the external memory.
3. The elastic scaling metadata management method according to claim 1, characterized in that: The description file includes type information recording the metadata type, name information recording the metadata name, and length information recording the length of the binary character string.
4. The elastic scaling metadata management method according to claim 1, characterized in that: The registration information includes metadata type information and memory size information, so that the engine interface calculates the size of each memory common body according to the registration information.
5. The elastic scaling metadata management method according to claim 1, characterized in that: The step three includes opening an interface of the metadata field to control whether the parser parses.
6. The elastic scaling metadata management method according to claim 1, characterized in that: The step three includes an assignment interface, the metadata is stored in the memory common body, and the assignment interface is called to assign a value to the metadata, so that the metadata is associated with the memory common body.
7. The elastic scaling metadata management method according to claim 1, characterized in that: The step 4 includes releasing the control plane metadata, including acquiring the memory common body on the metadata queue, and acquiring and releasing the metadata in the memory common body.
8. The elastic scaling metadata management method according to claim 2, characterized in that: The external memory is placed in an external memory pool, and the expansion of the external memory pool includes: engine architecture expansion working in a pipeline manner, which can be expanded on only one piece of memory.
9. The elastic scaling metadata management method according to claim 8, characterized in that: The expansion of the external memory pool includes: expanding the engine architecture through batch processing, and obtaining the optimal external memory pool size by continuously updating the algorithm.
