Data packet caching method and apparatus, electronic device, and storage medium

By parsing and matching request packets in the kernel cache to construct response packets, the problems of poor scalability and low hit rate of existing caching mechanisms are solved, achieving efficient multi-application caching support and fast response.

CN117082142BActive Publication Date: 2026-02-03PENG CHENG LAB
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310967232.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-03
Publication Date
2026-02-03
Estimated Expiration
2043-08-03

AI Technical Summary

Technical Problem

Existing caching technologies involve data copying between user space and kernel space, leading to excessive machine resource consumption, performance degradation, poor scalability of kernel-mode caching mechanisms, inability to support multiple applications using it simultaneously, low cache hit rate, and inflexible configuration.

Method used

It retrieves request packets from the kernel cache, performs first parsing and matching, performs second parsing using pre-configured processing logic, queries the data hash value of the cache table, constructs response packets, and initializes updates when the cache table is not found. It supports the processing and construction logic configuration of various applications.

Benefits of technology

It improves the scalability and response speed of the caching mechanism, enhances the cache hit rate, reduces the data copying overhead between user space and kernel space, and supports flexible cache management for various applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117082142B_ABST
    Figure CN117082142B_ABST
Patent Text Reader

Abstract

The embodiment of the application discloses a data packet caching method and device, electronic equipment and a storage medium, and relates to the technical field of data processing. The data packet caching method processes a request data packet according to a preconfigured matching condition and processing logic, quickly responds in a cache, and constructs a response data packet according to a preset construction logic. The matching condition, processing logic and construction logic of different application programs can be configured according to actual requirements, the scalability and response speed of the kernel caching mechanism are effectively improved, and the cache is updated in time after the application program responds when the cache table does not have corresponding response data, so that the cache hit rate is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a data packet caching method, apparatus, electronic device, and storage medium. Background Technology

[0002] With the maturation and widespread application of network technology simulation verification platforms, more and more experimental tasks are concentrated on a few ultra-large-scale simulation platforms, which will lead to a sharp increase in the concurrent requests that the simulation platforms need to handle. In order to reduce response time, many applications currently use caching technology to cache the processed results. However, current caching technology generally exists in user space. From the time the request data packet enters to the time the result is determined, it needs to go through the complex network protocol stack in kernel space, and there may even be multiple data copies between user space and kernel space, which will consume a lot of machine resources. Ultimately, the performance of the application will drop sharply in the case of big data streams.

[0003] However, kernel-mode caching mechanisms allow request packets to bypass the network protocol stack and user space, reducing the overhead of data copying between user and kernel spaces. Therefore, applications can leverage kernel caching to further improve system performance and response speed. However, kernel-mode caching mechanisms in related technologies suffer from poor scalability, do not support multiple applications using the caching framework simultaneously, and exhibit problems such as inflexible caching settings for different applications, low cache hit rates, and redundant processing flows. Summary of the Invention

[0004] This application aims to address at least one of the technical problems existing in the prior art. To this end, embodiments of this application provide a data packet caching method, apparatus, electronic device, and storage medium, capable of processing request data packets according to pre-configured logic, quickly responding to and updating the cache in the kernel cache, effectively improving cache hit rate and kernel cache scalability.

[0005] In a first aspect, embodiments of this application provide a data packet caching method, including:

[0006] Responding to the user's request command, retrieve the request data packet;

[0007] The request data packet is parsed to obtain matching parameters, and the matching parameters are matched with preset matching conditions to obtain a matching result;

[0008] If the matching result indicates that the request data packet matches the target application, the request data packet is parsed a second time using the pre-configured processing logic of the target application to obtain parsed data;

[0009] Based on the parsed data, query the cache table to see if the data hash value of the request data packet is cached, and obtain the cache identifier;

[0010] If the cache identifier indicates that the cache table has cached the data hash value of the request data packet, construct the response data packet of the request data packet according to the cache table and the pre-configured construction logic of the target application;

[0011] If the cache identifier indicates that the cache table does not cache the data hash value of the request data packet, the cache table is initialized based on the parsed data, the request data packet is sent to the target application to receive a response data packet, and the cache table is updated based on the response data packet.

[0012] In some embodiments of this application, the first parsing of the request data packet to obtain matching parameters, and matching the matching parameters with preset matching conditions to obtain a matching result, includes:

[0013] The header information of the request data packet is parsed using network protocols to obtain the matching parameters; the matching parameters include at least one of the following: source port, source address, destination port, destination address, and protocol information;

[0014] The source address, destination address, source port, destination port, and protocol information are sequentially matched with the matching conditions, and the application identifier is obtained according to the longest matching principle.

[0015] Determine whether the application identifier matches the target application to obtain a matching result.

[0016] In some embodiments of this application, if the matching result indicates that the request data packet matches the target application, the request data packet is parsed a second time using the pre-configured processing logic of the target application to obtain parsed data, including:

[0017] If the matching result is that the application identifier matches the target application, the processing logic name is obtained based on the application identifier; the application identifier and the processing logic name satisfy a first mapping relationship.

[0018] Based on the processing logic name, the pre-configured processing logic of the target application is invoked to perform a second parsing on the request data packet to obtain the parsed data; the parsed data includes at least one of the following: request information, protocol information, source port, source address, destination port, and destination address, wherein the request information includes URL information.

[0019] In some embodiments of this application, the cache table includes a first hash table, wherein the key attributes of the first hash table include at least one of the following: request source port, request source address, request destination port, request protocol information, and request URL information, and the value attributes of the first hash table include: request data hash value; the step of querying the cache table to determine whether the data hash value of the request data packet is cached based on the parsed data to obtain a cache identifier includes:

[0020] The source port in the parsed data is used as the request source port, the source address is used as the request source address, the destination port is used as the request destination port, the protocol information is used as the request protocol information, and the URL information is used as the request URL information.

[0021] By combining the request source port, the request source address, the request destination port, the request protocol information, and the request URL information, a matching key is obtained;

[0022] Based on the key to be matched, query whether the first hash table caches the corresponding request data hash value to obtain a cache identifier; the request data hash value corresponds to the data hash value of the request data packet.

[0023] In some embodiments of this application, the value attribute of the first hash table further includes: response caching; the step of constructing a response data packet for the request data packet based on the cache table and the pre-configured construction logic of the target application, if the cache identifier indicates that the cache table has cached the data hash value of the request data packet, includes:

[0024] If the cache identifier indicates that the first hash table has cached the data hash value of the request data packet, the response cache corresponding to the request data packet in the first hash table is obtained based on the key to be matched;

[0025] The construction logic name is obtained based on the application identifier; the application identifier and the construction logic name satisfy a second mapping relationship;

[0026] Based on the construction logic name, the pre-configured construction logic of the target application is invoked to construct the response cache, thereby obtaining the initial response data packet;

[0027] The source port and destination port, source address and destination address in the parsed data are swapped, and the verification information is calculated to obtain the redirection information;

[0028] The response data packet is obtained based on the initial response data packet and the redirection information.

[0029] In some embodiments of this application, the value attributes of the first hash table further include: cache status and response cache; the cache table further includes a second hash table, the key attribute of the second hash table is the request data hash value, and the value attributes of the second hash table include at least one of the following: request source port, request source address, request destination port, request protocol information, and request URL information; the step of initializing the cache table based on the parsed data, sending the request data packet to the target application for response, obtaining a response data packet, and updating the cache table based on the response data packet if the cache identifier indicates that the cache table does not cache the data hash value of the request data packet, sending the request data packet to the target application for response, obtaining a response data packet, and updating the cache table based on the response data packet includes:

[0030] If the cache identifier indicates that the first hash table does not cache the data hash value of the request data packet, calculate the data hash value of the request data packet;

[0031] The source port in the parsed data is used as the request source port, the source address is used as the request source address, the destination port is used as the request destination port, the protocol information is used as the request protocol information, and the URL information is used as the request URL information.

[0032] The initial key is obtained by combining the request source port, the request source address, the request destination port, the request protocol information, and the request URL information;

[0033] Based on the initial key, the data hash value is cached in the first hash table as the request data hash value, and the cache state is initialized to an unavailable state, while the response cache is empty;

[0034] The request data packet is sent to the target application to receive a response, and the response data packet is obtained.

[0035] The response data packet is acquired and parsed to obtain response data; the response data includes at least one of the following: response information, the source port, the source address, the destination port, and the destination address;

[0036] Obtain the corresponding request data packet based on the source port, the source address, the destination port, and the destination address, and calculate the corresponding data hash value based on the request data packet;

[0037] The data hash value is used as the request data hash value, and the request data hash value is used as the matching key of the second hash table to retrieve the corresponding parsed data.

[0038] The parsed data is used as the key to be matched in the first hash table, the response information is used as the response cache and cached in the first hash table, and the cache status is updated to an available status.

[0039] In some embodiments of this application, before sending the request data packet to the target application for a response and obtaining the response data packet, the method further includes:

[0040] The data hash value is used as the request data hash value, and the request data hash value is used as the key attribute of the second hash table, while the initial key is used as the value attribute of the second hash table;

[0041] The key attribute and the value attribute are stored in the second hash table.

[0042] In some embodiments of this application, the method further includes: predicting the probability of obtaining subsequent request instructions from different request data based on the parsed data, and updating the cache table based on the request probability, including:

[0043] The parsed data is preprocessed to obtain the request data to be predicted; the request data includes at least one of the following: application identifier, source port, source address, request information, request time, and hit status. The first hit status indicates that the request data packet has a response cache in the cache table, the second hit status indicates that the request data packet has no response cache in the cache table, and the third hit status indicates that the request data packet is not in the cache table.

[0044] The request data to be predicted and historical request data are input into the prediction model for prediction, and the request probability of the request instruction corresponding to each request data is obtained; the prediction model is a pre-trained LSTM prediction model.

[0045] Based on the request probability, the weight of each cached item in the cache table is calculated to obtain weight information; the cache table stores multiple cached items, and each cached item includes a key attribute and a value attribute;

[0046] Based on the weight information, the cache item with the smallest weight is replaced to update the cache table.

[0047] In some embodiments of this application, there are multiple applications, each with a unique application identifier; before obtaining the request data packet in response to the request instruction, the method further includes: configuring the matching conditions, the processing logic, and the construction logic according to a preset interface and the application identifier, including:

[0048] Based on the first interface and the application identifier, the matching conditions for the corresponding application are configured, and the matching conditions for different applications are stored in a tree structure; the matching conditions include the application identifier and protocol information;

[0049] Based on the second interface and the application identifier, the corresponding processing logic of the application is configured, and the processing logic is named to obtain a processing logic name; the application identifier and the processing logic name satisfy a first mapping relationship;

[0050] Based on the third interface and the application identifier, the corresponding construction logic of the application is configured, and the construction logic is named to obtain the construction logic name; the application identifier and the construction logic name satisfy the second mapping relationship.

[0051] Secondly, embodiments of this application also provide a data packet caching device, which applies the data packet caching method described in the first aspect of this application, including:

[0052] The data packet response module is used to respond to user request commands and obtain request data packets;

[0053] The first parsing module is used to perform a first parsing on the request data packet to obtain matching parameters, and to match the matching parameters with preset matching conditions to obtain a matching result;

[0054] The second parsing module is used to perform a second parsing on the request data packet using the pre-configured processing logic of the target application if the matching result indicates that the request data packet matches the target application, so as to obtain parsed data.

[0055] The cache query module is used to query the cache table based on the parsed data to determine whether the data hash value of the request data packet is cached, and to obtain the cache identifier.

[0056] A data packet construction module is used to construct a response data packet for the request data packet based on the cache table and the pre-configured construction logic of the target application if the cache identifier indicates that the cache table has cached the data hash value of the request data packet;

[0057] The cache update module is used to initialize the cache table based on the parsed data if the cache identifier represents the data hash value of the request data packet not cached in the cache table, send the request data packet to the target application to respond, obtain the response data packet, and update the cache table based on the response data packet.

[0058] In some embodiments of this application, the apparatus further includes:

[0059] The cache prediction module is used to predict the probability of obtaining subsequent request instructions based on the parsed data, and update the cache table based on the request probability.

[0060] In some embodiments of this application, the apparatus further includes:

[0061] The pre-configuration module is used to configure the matching conditions, the processing logic, and the construction logic according to the preset interface and application identifier.

[0062] Thirdly, embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the data packet caching method as described in the first aspect of this application.

[0063] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a program that is executed by a processor to implement the data packet caching method as described in the first aspect of this application.

[0064] The embodiments of this application include at least the following beneficial effects:

[0065] This application provides a data packet caching method, apparatus, electronic device, and storage medium. The method, in response to a user's request instruction, acquires a request data packet and performs a first parsing to obtain matching parameters, which are then matched against preset matching conditions. If the matching result indicates that the request data packet matches a target application, a second parsing is performed using pre-configured processing logic to obtain parsed data. This parsed data is then further queried to determine if the cache table corresponding to the target application has cached the data hash value of the request data packet. If the obtained cache identifier indicates that the cache table has cached the data hash value, a response data packet for the request data packet is constructed based on the cache table and pre-configured construction logic. If the cache identifier indicates that the cache table has not cached the data hash value, the cache table is initialized based on the parsed data, and the request data packet is sent to the target application for a response. After receiving the response data packet, the cache table is updated accordingly. Thus, by processing the request data packet according to the pre-configured processing logic, a rapid response is achieved in the cache, and a response data packet is constructed according to the preset construction logic. This allows for configuration of processing and construction logic for different applications, improving the scalability and response speed of the caching mechanism. Furthermore, timely updates to the cache when no corresponding response data is available in the cache table effectively improve the cache hit rate.

[0066] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0067] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:

[0068] Figure 1This is a flowchart illustrating a data packet caching method provided in one embodiment of this application;

[0069] Figure 2 yes Figure 1 A flowchart illustrating the process prior to step S101.

[0070] Figure 3 This is a schematic diagram of a matching condition tree structure provided in one embodiment of this application;

[0071] Figure 4 yes Figure 1 A flowchart illustrating step S102;

[0072] Figure 5 yes Figure 1 A flowchart illustrating step S103;

[0073] Figure 6 yes Figure 1 A flowchart illustrating step S104;

[0074] Figure 7 yes Figure 1 A flowchart illustrating step S105;

[0075] Figure 8 yes Figure 1 A flowchart illustrating step S106;

[0076] Figure 9 yes Figure 8 A flowchart illustrating the process before step S705.

[0077] Figure 10 This is a flowchart illustrating a data packet caching method provided in another embodiment of this application;

[0078] Figure 11 This is a schematic diagram of an e-cache caching framework provided in one embodiment of this application;

[0079] Figure 12 This is a flowchart of the inbound processing module provided in one embodiment of this application;

[0080] Figure 13 This is a flowchart of a cache update process provided in one embodiment of this application;

[0081] Figure 14 This is a flowchart of an intelligent memory management module provided in one embodiment of this application;

[0082] Figure 15 This is a schematic diagram of a data packet caching device module provided in one embodiment of this application;

[0083] Figure 16This is a schematic diagram of a data packet caching device module provided in another embodiment of this application;

[0084] Figure 17 This is a schematic diagram of the structure of an electronic device provided in one embodiment of this application.

[0085] Reference numerals: data packet response module 100, first parsing module 200, second parsing module 300, cache query module 400, data packet construction module 500, cache update module 600, cache prediction module 700, pre-configuration module 800, electronic device 1000, processor 1001, memory 1002. Detailed Implementation

[0086] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0087] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.

[0088] In the description of this application, it should be understood that the orientation descriptions, such as up, down, front, back, left, right, etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application.

[0089] In the description of this application, "several" means one or more, "more than" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. The use of "first" and "second" in the description is merely for distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.

[0090] In the description of this application, unless otherwise expressly defined, terms such as "setup," "installation," and "connection" should be interpreted broadly, and those skilled in the art can reasonably determine the specific meaning of the above terms in this application in conjunction with the specific content of the technical solution.

[0091] With the maturation and widespread application of network technology simulation verification platforms, an increasing number of experimental tasks are concentrated on a few ultra-large-scale simulation platforms. This leads to a sharp increase in the concurrent requests that the simulation platforms need to handle. To reduce response time, many applications currently use caching technology to cache processed results. When the same request occurs, computation and response time are reduced, and the cached result is returned directly to the requester. However, current caching technologies generally exist in user space. From the time the request data packet enters until the result is determined, it needs to pass through a complex network protocol stack in kernel space, and may even involve multiple data copies between user space and kernel space. This results in the consumption of a lot of machine resources, and ultimately, the performance of the application drops sharply in scenarios with large data flows.

[0092] Currently, the common approach is to build a cluster to address the insufficient processing power of a single machine. While this improves the overall performance of application services, it still doesn't fully unleash the processing power of a single machine. Furthermore, clustering only reduces response latency caused by request queuing, but it cannot further improve response speed for individual requests. Therefore, related technologies utilize XDP to add a caching mechanism to MemCache within the kernel, allowing request packets to bypass the kernel-mode network protocol stack and user-mode, reducing the overhead of data copying between user and kernel modes. However, this approach is limited to MemCache applications, has poor scalability, does not support multiple applications using the caching framework simultaneously, and suffers from inflexible caching settings for different applications, low cache hit rates, redundant processing flows, and an inability to support intelligent cache management for multiple applications.

[0093] Based on this, embodiments of this application provide a data packet caching method, apparatus, electronic device, and storage medium, which can process request data packets according to pre-configured processing logic, quickly respond in the cache, and construct response data packets according to preset construction logic. The processing logic and construction logic of different applications can be configured, improving the scalability and response speed of the caching mechanism, and timely updating the cache when there is no corresponding response data in the cache table, thus improving the cache hit rate.

[0094] This application provides a data packet caching method, apparatus, electronic device, and storage medium, which are specifically described through the following embodiments. First, the data packet caching method in this application is described.

[0095] The data packet caching method provided in this application relates to the field of network communication technology, and more particularly to the field of data processing technology. The data packet caching method provided in this application can be applied to a terminal, a server, or a computer program running on either the terminal or the server. For example, the computer program can be a native program or software module in an operating system; it can be a native application (APP), i.e., a program that needs to be installed in the operating system to run, such as a client that supports data packet caching, i.e., a program that only needs to be downloaded to a browser environment to run. In short, the above-mentioned computer program can be any form of application, module, or plugin. The terminal communicates with the server through a network. The data packet caching method can be executed by the terminal or the server, or by the terminal and the server working together.

[0096] In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, or smartwatch, etc. The server can be a standalone server, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms; it can also be a service node in a blockchain system, where the service nodes form a peer-to-peer (P2P) network. The P2P protocol is an application layer protocol running on top of the Transmission Control Protocol (TCP). A packet caching system server can be installed on the server, allowing interaction with the terminal. For example, corresponding software can be installed on the server; the software could be an application implementing packet caching methods, but is not limited to these forms. The terminal and server can connect via Bluetooth, USB (Universal Serial Bus), or a network, etc., and this embodiment does not impose any limitations.

[0097] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. The invention can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0098] The data packet caching method in the embodiments of the present invention is described below.

[0099] Reference Figure 1 As shown, this application embodiment provides a data packet caching method applied to the kernel caching mechanism, including but not limited to the following steps S101 to S106.

[0100] Step S101: In response to the user's request instruction, obtain the request data packet.

[0101] In some embodiments, in response to a user's request command, the corresponding request data packet is obtained through an XDP hook function. It is understood that XDP (eXpress Data Path) is a high-performance packet processing technology that can process data packets within the network interface driver. Specifically, the XDP hook function obtains, filters, and processes the request data packet before it reaches the kernel-mode network protocol stack; this embodiment does not impose any limitations on this.

[0102] In some embodiments, the user's request instruction is issued based on the application the user is using. For example, when a user searches using a browser, a search-related request instruction will be generated; similarly, when a user logs into software, a login-related request instruction will be generated. It is understood that the application can be any application that requires kernel caching, such as a browser or software, and this embodiment does not limit this.

[0103] Step S102: Perform a first parsing on the request data packet to obtain matching parameters, and match the matching parameters with preset matching conditions to obtain matching results.

[0104] In some embodiments, after obtaining the request packet via the XDP hook function, the request packet is first parsed in kernel mode to obtain matching parameters. It is understood that the first parsing only retrieves and parses the header information within the basic network protocol, and does not parse the payload information or special protocols or encryption protocols used by the application. Specifically, the parsing of the request packet starts from the first physical layer, then sequentially parses the data link layer, network layer, transport layer, and application layer. In this implementation, the first parsing proceeds from the physical layer to the transport layer, and can be completed using the kernel-level built-in parsing tools to obtain the matching parameters.

[0105] In some embodiments, matching parameters are matched against preset matching conditions to obtain a matching result, which is used to characterize whether the request data packet matches the target application. It is understood that since different applications correspond to different kernel caches, different matching conditions are preset for different applications to determine whether the application is the one requesting the data packet, so that it can continue to respond in its kernel cache.

[0106] Step S103: If the matching result indicates that the request data packet matches the target application, the request data packet is parsed a second time using the pre-configured processing logic of the target application to obtain parsed data.

[0107] In some embodiments, if the matching result indicates that the request packet matches the target application, it means that the request object of the request packet is the target application, and therefore the response can continue in the kernel cache of the target application. Specifically, the request packet is parsed a second time using the pre-configured processing logic of the target application to obtain parsed data. In this embodiment, the second parsing is application-layer parsing. By pre-configuring different processing logic for different applications for the second parsing, the scalability of the kernel caching mechanism is effectively improved.

[0108] Step S104: Based on the parsed data, query the cache table to see if the data hash value of the request data packet is cached, and obtain the cache identifier.

[0109] In some embodiments, based on the parsed data, the cache table is queried to determine whether the data hash value of the request data packet is cached, thereby obtaining a cache identifier. The data hash value can be obtained by hashing the request data packet, for example, using common hash functions such as MD5, SHA1, and SHA256, or by using feature extraction algorithms, such as extracting keywords, specific fields, or feature vectors from the request data packet and then using a hash function. It is understood that identical data request packets have the same data hash value; therefore, using the parsed data as an index to the cache table allows a query to determine whether the cache table caches the data hash value of the request data packet.

[0110] Step S105: If the cache identifier represents the data hash value of the request data packet that has been cached in the cache table, construct the response data packet of the request data packet according to the cache table and the construction logic of the pre-configured target application.

[0111] In some embodiments, if the cache identifier represents the hash value of the data packet for which the cache table has cached the request packet, it means that the kernel cache of the target application has cached the response data for the request packet. Therefore, the corresponding response data can be obtained according to the cache table, and the response can be quickly constructed according to the pre-configured construction logic of the target application. It is understood that different applications can pre-configure different construction logic for response packets, thereby effectively improving the scalability of the kernel caching mechanism and increasing the response speed of requests.

[0112] Step S106: If the cache identifier represents the data hash value of the request data packet that is not cached in the cache table, initialize the cache table based on the parsed data, send the request data packet to the target application to respond, obtain the response data packet, and update the cache table based on the response data packet.

[0113] In some embodiments, if the cache identifier represents the data hash value of the request packet that is not cached in the cache table, it means that the kernel cache of the target application does not cache the response data of the request packet. Therefore, the request packet needs to be sent to the target application for response. Specifically, the request packet is uploaded to the kernel-mode network protocol stack and then transmitted to the target application for response, thereby obtaining the response packet.

[0114] In some embodiments, the cache table is initialized based on the parsed data of the request packet. After the target application responds, the response packet is obtained to update the cache table, thereby caching the request packet and its response data in the cache, realizing timely updates of the cache table and effectively improving the kernel cache hit rate.

[0115] In some embodiments of this application, each application has a unique application identifier. In this embodiment, App_key is used to represent the application identifier, thereby identifying the corresponding application through App_key. (See also...) Figure 2 As shown, before step S101, the process may further include configuring the matching conditions, processing logic, and construction logic according to the preset interface and application identifier, including but not limited to the following steps S201 to S203.

[0116] Step S201: Based on the first interface and the application identifier, configure the matching conditions for the corresponding application, and store the matching conditions for different applications in a tree structure.

[0117] In some embodiments, the first interface is a matching condition configuration function, which can configure the matching conditions for the corresponding application by receiving relevant parameters input by the user, such as application identifier and matching conditions. Specifically, the matching conditions for the corresponding application can be configured according to the first interface and the application identifier. Specifically, the matching conditions include the application identifier and protocol information. The protocol information used can be protocol information from the network layer to the application layer. The matching conditions may also include one or more of the following: source port, source address, destination port, destination address, and request information. It is understood that those skilled in the art can set the matching conditions for the application through the first interface according to actual needs, and this embodiment does not limit this.

[0118] In some embodiments, to respond quickly and accurately to user requests, the matching conditions for each application are stored in a tree structure. For example, if three applications need to use the kernel cache, and the matching conditions for app1 are configured as {App_key:”app1”,Dest_IP:”192:10:2:1”,Dest_port:123,Protocols:”IP-TCP”}; the matching conditions for app2 are configured as {App_key:”app2”,Dest_port:13,Protocols:”IP-UDP”}; and the matching conditions for app3 are configured as {App_key:”app3”,Dest_IP:”192:10:2:1”,Protocols:”IP-TCP”}, then the following structure is formed: Figure 3 The diagram shows a tree structure of matching conditions. It can be understood that in this embodiment, Protocols represents protocol information, Source_port represents the source port, Source_IP represents the source address, Dest_port represents the destination port, Dest_IP represents the destination address, and URL represents the request information. Specifically, the matching conditions are analyzed layer by layer based on the protocol information. If a matching condition exists, a new branch is added to the tree structure for matching. If a matching condition is missing, it is uniformly set to unconstrained; this embodiment does not impose any restrictions on this.

[0119] Step S202: Based on the second interface and the application identifier, configure the processing logic of the corresponding application and name the processing logic to obtain the processing logic name.

[0120] In some embodiments, the second interface is a processing logic configuration function. By receiving relevant parameters input by the user, such as application identifier, processing logic name, and processing logic, the processing logic of the corresponding application can be configured. Specifically, the processing logic of the corresponding application can be configured through the second interface and the application identifier. Specifically, the App_key identifies which application the configured processing logic belongs to, and the processing logic Process is named using the processing logic name Process_name, that is, the Process is named with Process_name, and App_key and Process_name satisfy the first mapping relationship.

[0121] In some embodiments, the first mapping relationship is a hash table, with App_key as the key and Process_name as the value. Thus, Process_name can be obtained through App_key, and the corresponding Process can be invoked to process the application's request data packet. It is understood that the request parameters of the second interface include App_key, Process_name, and Process, thereby enabling different processing logic to be configured for different applications.

[0122] Step S203: Based on the third interface and the application identifier, configure the construction logic of the corresponding application and name the construction logic to obtain the construction logic name.

[0123] In some embodiments, the second interface is a construction logic configuration function. By receiving relevant parameters input by the user, such as the application identifier, construction logic name, and construction logic, the configuration of the corresponding application's construction logic can be completed. Specifically, based on the third interface and the application identifier, the construction logic of the corresponding application can be configured. Specifically, the App_key identifies which application the configured construction logic belongs to, and the construction logic Data_Structure is named using the construction logic name Data_Structure_name, that is, Data_Structure is named with Data_Structure_name, and App_key and Data_Structure_name satisfy the second mapping relationship.

[0124] In some embodiments, the second mapping relationship is a hash table, with App_key as the key and Data_Structure_name as the value. Thus, Data_Structure_name can be obtained through App_key, and the corresponding Data_Structure can be invoked to construct the response data packet for the application's request data packet. It is understood that the request parameters of the third interface include App_key, Data_Structure_name, and Data_Structure, thereby enabling different construction logic to be configured for different applications.

[0125] In some embodiments, each preset interface exists in user space. After naming the processing and construction logic, it is sent to the eBPF's `prog_array` for storage. In subsequent processes, it can be invoked by the relevant calling interfaces using the processing and construction logic names. It is understood that `prog_array` is a special array structure that can be used to store multiple eBPF programs and invoke them according to the program's index value and the `bpf_tail_call` method. The matching conditions, the first mapping relationship, and the second mapping relationship are passed to the kernel via eBPF. Upon receiving the request packet, matching and response can be performed quickly and accurately, effectively improving response speed.

[0126] Reference Figure 4 As shown, in some embodiments of this application, step S102 may include, but is not limited to, steps S301 to S303.

[0127] Step S301: Perform network protocol parsing on the header information of the request data packet to obtain matching parameters.

[0128] In some embodiments, network protocol parsing is performed on the header information of the request data packet, specifically parsing from the physical layer to the transport layer to obtain matching parameters. Specifically, the matching parameters include, but are not limited to: source port, source address, destination port, destination address, and protocol information; this embodiment does not impose any limitations on these. Step S302: The source address, destination address, source port, destination port, and protocol information are sequentially matched with the matching conditions, and the application identifier is obtained according to the longest match principle.

[0129] In some embodiments, the source address, destination address, source port, destination port, and protocol information are sequentially matched with preset matching conditions. Specifically, the source address can be matched first. If the source address is the same as a preset matching condition, the destination address is matched. It can be understood that if the destination address is empty, the "unconstrained" option in the tree structure is matched, and then the source port is matched, and so on, until all matching parameters are matched with the preset matching conditions. Finally, the corresponding application identifier is obtained according to the longest matching principle.

[0130] For example, refer to Figure 3 As shown, if there is no source address in the matching parameters, the first node "source_IP: no constraint" is matched. Then the destination address is matched. If the destination address is 192:10:2:1, the right node "dest_IP:192:10:2:1" in the second level of the tree structure is matched. If the matched protocol information is TCP and there is no source port in the matching parameters, the node "TCP source_port: no constraint" is matched. The destination port is matched. If the destination port is 123, the final matched application is identified as app1. If there is no destination port in the matching parameters, the final matched application is identified as app3.

[0131] Step S303: Determine whether the application identifier matches the target application and obtain the matching result.

[0132] In some embodiments, the application identifier obtained from the matching parameters is used to determine whether it matches the target application. That is, it is determined whether the request object of the request data packet is the target application corresponding to the current kernel cache, thereby obtaining a matching result. For example, if the application corresponding to the matched application identifier is app2, but the target application corresponding to the kernel cache is app1, the matching result will indicate that the request data packet does not match the target application.

[0133] Reference Figure 5 As shown, in some embodiments of this application, step S103 may include, but is not limited to, steps S401 to S402.

[0134] Step S401: If the matching result is that the application identifier matches the target application, obtain the processing logic name based on the application identifier.

[0135] In some embodiments, if the matching result is that the application identifier matches the target application, then the corresponding Process_name is obtained by using the App_key as an index according to the first mapping relationship between the application identifier App_key and the processing logic name Process_name.

[0136] Step S402: Based on the processing logic name, the pre-configured processing logic of the target application is invoked to perform a second parsing of the request data packet to obtain parsed data.

[0137] In some embodiments, the `bpf_tail_call` method and `Process_name` are used to invoke the pre-configured target application's processing logic `Process` to perform a second parsing of the request packet. It is understood that the `bpf_tail_call` method is a jump operation in eBPF used to execute another eBPF program in the kernel and transfer control to that program. This simplifies program logic, reduces memory usage and instruction count, and improves program execution efficiency.

[0138] In some embodiments, the second parsing is application-layer parsing, and the parsed data includes at least one of the following: request information, protocol information, source port, source address, destination port, and destination address, wherein the request information includes URL information.

[0139] In some embodiments of this application, the cache table includes a first hash table. The key attributes of the first hash table include at least one of the following: request source port, request source address, request destination port, request protocol information, and request URL information. The value attributes of the first hash table include: request data hash value. (See also...) Figure 6 As shown, step S104 may also include, but is not limited to, steps S501 to S503.

[0140] Step S501: Use the source port in the parsed data as the request source port, the source address as the request source address, the destination port as the request destination port, the protocol information as the request protocol information, and the URL information as the request URL information.

[0141] In some embodiments, each parameter in the parsed data is used as a component parameter of the key attribute in the cache table. Specifically, the source port in the parsed data is used as the request source port of the cache table, the source address in the parsed data is used as the request source address of the cache table, the destination port in the parsed data is used as the request destination port of the cache table, the protocol information in the parsed data is used as the request protocol information of the cache table, and the URL information in the parsed data is used as the request URL information of the cache table.

[0142] Step S502: Combine the request source port, request source address, request destination port, request protocol information, and request URL information to obtain the key to be matched.

[0143] In some embodiments, the request source port, request source address, request destination port, request protocol information, and request URL information are combined to form a matching key, which can then be used as an index for querying in the first hash table.

[0144] Step S503: Based on the key to be matched, query the first hash table to see if the corresponding request data hash value is cached, and obtain the cache identifier.

[0145] In some embodiments, based on the key to be matched, the first hash table is queried to see if the corresponding request data hash value is cached. It can be understood that the request data hash value corresponds to the data hash value of the request data packet, thereby obtaining the cache identifier.

[0146] Reference Figure 7 As shown, in some embodiments of this application, the value attribute of the first hash table further includes: response cache, and the above step S105 may also include, but is not limited to, the following steps S601 to S605.

[0147] Step S601: If the cache identifier represents the data hash value of the request data packet that has been cached in the first hash table, obtain the response cache corresponding to the request data packet in the first hash table based on the key to be matched.

[0148] In some embodiments, the application's response data is stored in the response cache of the first hash table. If the cache identifier represents the data hash value of the request data packet that has been cached in the first hash table, it means that the response data corresponding to the request data packet is cached in the kernel cache. Thus, the corresponding response cache can be retrieved from the first hash table based on the key to be matched as an index.

[0149] Step S602: Obtain the construct logic name based on the application identifier.

[0150] In some embodiments, the corresponding structure name data_structure_name can be obtained by using the application identifier APP_key as an index, based on the second mapping relationship between the application identifier and the structure name stored in the kernel.

[0151] Step S603: Based on the construction logic name, the pre-configured construction logic of the target application is called to construct the response cache and obtain the initial response data packet.

[0152] In some embodiments, the pre-configured target application's data packet construction logic data_structure is called in prog_array according to the construction logic name data_structure_name to construct the response cache, thereby completing the construction of the application-level return data packet and obtaining the initial response data packet.

[0153] Step S604: Exchange the source port and destination port, source address and destination address in the parsed data, and calculate the check information to obtain the redirection information.

[0154] In some embodiments, based on the initial response data packet, the source port and destination port, source address and destination address in the parsed data of the request data packet are swapped, that is, the original source port is used as the new destination port, the original destination port is used as the new source port, the original source address is used as the new destination address, and the original destination address is used as the new source address. The checksum information of the data packet header is then recalculated to obtain the redirection information.

[0155] Step S605: Obtain the response data packet based on the initial response data packet and the redirection information.

[0156] In some embodiments, the final response data packet is obtained based on the initial response data packet and redirection information, and the data packet is redirected to complete the response to the request data packet. This eliminates the need for a lengthy and complex kernel network protocol stack and reduces unnecessary data copying between kernel mode and user mode, thus greatly improving response performance.

[0157] In some embodiments of this application, the value attributes of the first hash table further include: cache status and response cache; the cache table further includes a second hash table, the key attribute of the second hash table being the hash value of the request data, and the value attributes of the second hash table including at least one of the following: request source port, request source address, request destination port, request protocol information, and request URL information. (Refer to...) Figure 8 As shown, step S106 may also include, but is not limited to, steps S701 to S709.

[0158] Step S701: If the cache identifier represents the data hash value of the request data packet that is not cached in the cache table, calculate the data hash value of the request data packet.

[0159] In some embodiments, if the cache identifier represents the data hash value of a request packet that is not cached in the first hash table, indicating that the response data corresponding to the request packet is not cached in the kernel cache, then the first hash table is initialized based on the request packet so that the response data of the request packet can be updated and stored in the first hash table in a timely manner. Specifically, the same fields are selected according to the same hash calculation method to calculate the data hash value of the request packet, thereby ensuring that the same request packets have the same data hash value.

[0160] Step S702: Use the source port in the parsed data as the request source port, the source address as the request source address, the destination port as the request destination port, the protocol information as the request protocol information, and the URL information as the request URL information.

[0161] In some embodiments, each parameter in the parsed data is used as a component parameter of the key attribute in the cache table. Specifically, the source port in the parsed data is used as the request source port of the cache table, the source address in the parsed data is used as the request source address of the cache table, the destination port in the parsed data is used as the request destination port of the cache table, the protocol information in the parsed data is used as the request protocol information of the cache table, and the URL information in the parsed data is used as the request URL information of the cache table.

[0162] Step S703: Combine the request source port, request source address, request destination port, request protocol information, and request URL information to obtain the initial key.

[0163] In some embodiments, the request source port, request source address, request destination port, request protocol information, and request URL information are combined to form an initial key, which serves as an index to store the corresponding value attribute in the first hash table.

[0164] Step S704: Based on the initial key, cache the data hash value as the request data hash value in the first hash table, and initialize the cache state to an unavailable state, and the response cache is empty.

[0165] In some embodiments, based on the initial key as an index, the data hash value of the request data packet is cached in the first hash table as the request data hash value, and the cache state is initialized to an unavailable state, while the response cache is empty. It is understood that since the value attributes in the first hash table need to be composed of relevant information from both the request and response data packets, setting the valid field to indicate whether the current data is available effectively avoids the misuse of incomplete buffered data when there is no response data packet, thus improving response performance.

[0166] Step S705: Send the request data packet to the target application to receive a response data packet.

[0167] In some embodiments, the request packet is uploaded to the kernel-mode network protocol stack and then transmitted to the target application for a response. The application then returns the response packet to the kernel-mode network protocol stack.

[0168] Step S706: Obtain and parse the response data packet to obtain the response data.

[0169] In some embodiments, the response data packet is obtained through the TC hook function. It is understood that the TC hook function is a network traffic control mechanism in the kernel that can limit, divert, and optimize network traffic. It is used to implement custom network traffic control policies to filter and manipulate network traffic.

[0170] In some embodiments, the process of parsing the response data packet is the same as the process of parsing the request data packet. First, the response data packet is parsed to obtain matching parameters and match them with the matching conditions of the target application. It can be understood that the source port and target port, source address and destination address in the matching conditions are exchanged. Then, the corresponding pre-configured processing logic is called to perform a second parsing to obtain the response data.

[0171] In some embodiments, the response data packet carries relevant request information, so the parsed response data includes at least one of the following: response information, source port, source address, destination port, and destination address. Specifically, the response information is a response to the request information in the request data packet, and the source port, source address, destination port, and destination address are the source port, source address, destination port, and destination address in the request data packet.

[0172] Step S707: Obtain the corresponding request data packet based on the source port, source address, destination port, and destination address, and calculate the corresponding data hash value based on the request data packet.

[0173] In some embodiments, the request data packet and information such as whether the first hash table is hit are cached, so that the corresponding request data packet can be obtained according to the source port, source address, destination port and destination address in the response data, and the corresponding data hash value can be calculated based on the request data packet.

[0174] Step S708: Use the data hash value as the request data hash value and the request data hash value as the matching key of the second hash table to retrieve the corresponding parsed data.

[0175] In some embodiments, the data hash value is used as the request data hash value, and the request data hash value is used as the matching key of the second hash table, and the corresponding parsed data is obtained by index query. Specifically, it includes at least one of the following value attributes: request source port, request source address, request destination port, request protocol information, and request URL information.

[0176] Step S709: Use the parsed data as the matching key in the first hash table, use the response information as the response cache and cache it in the first hash table, and update the cache status to the available status.

[0177] In some embodiments, the parsed data retrieved from the second hash table is used as the matching key in the first hash table, serving as an index to find the corresponding position in the first hash table. The response information is then cached as a response in the first hash table, and the cache status is updated to an available state. This allows for a faster response from the kernel cache the next time the same request data packet is received. The response data packet is accurately constructed based on the response cache, and the timely cache update effectively improves the kernel cache hit rate and response speed.

[0178] Reference Figure 9 As shown, in some embodiments of this application, steps S801 to S802 may be included before step S705.

[0179] Step S801: Use the data hash value as the request data hash value, and use the request data hash value as the key attribute of the second hash table, and use the initial key as the value attribute of the second hash table.

[0180] In some embodiments, the data hash value is used as the request data hash value, and the request data hash value is used as the key attribute of the second hash table, while the request source port, request source address, request destination port, request protocol information, and request URL information in the initial key are used as the value attributes of the second hash table.

[0181] Step S802: Store the key attribute and value attribute in the second hash table.

[0182] In some embodiments, the key attribute is used as an index to store the value attribute in a second hash table, thereby facilitating subsequent lookup of the corresponding value attribute based on the data hash value.

[0183] Understandably, since different request packets may calculate the same data hash value, resulting in a hash collision, this implementation sets up a second hash table to map and store the data hash value and parsed data of the request packet before it is sent to the target application for a response. Therefore, when retrieving the request packet based on the response data later, even if different request packets have the same data hash value, further confirmation can be made by comparing fields such as source port, source address, destination port, destination address, and protocol information, thereby ensuring that the response data is cached in the correct buffer corresponding to the request packet.

[0184] In some embodiments of this application, to better manage the kernel cache, request packets and hit / miss information are passed to user space using an eBPF map to predict subsequent request instructions and optimize kernel cache allocation. It is understood that an eBPF map is a special type of shared memory used to transfer data between kernel space and user space. (See also...) Figure 10 As shown, the data packet caching method may also include predicting the probability of obtaining subsequent request instructions based on parsed data and updating the cache table based on the request probability, specifically including but not limited to the following steps S901 to S904.

[0185] Step S901: Preprocess the parsed data to obtain the request data to be predicted.

[0186] In some embodiments, to ensure prediction based on the latest and most comprehensive data, after the request data packet is parsed a second time to obtain parsed data, the parsed data is passed to the user space via an eBPF map. In the user space, the parsed data is preprocessed to obtain the request data to be predicted. Specifically, the preprocessing includes normalization and other processing. The request data includes at least one of the following: application identifier, source port, source address, request information, request time, and hit status. A first hit status indicates that the request data packet has a response cached in the cache table; a second hit status indicates that the request data packet does not have a response cached in the cache table; and a third hit status indicates that the request data packet is not in the cache table. For example, the first status is represented by 1, the second status by 0, and the third status by -1; this embodiment does not impose any limitations on this.

[0187] Step S902: Input the request data to be predicted and the historical request data into the prediction model to make a prediction and obtain the request probability of the request instruction corresponding to each request data.

[0188] In some embodiments, the request data to be predicted and historical request data are input into a prediction model for prediction. Specifically, the prediction model is a pre-trained LSTM prediction model. It is understood that when the prediction model receives the request data to be predicted, it records it in memory and passes multiple historical request data sets most recent to the current time to the prediction model to predict the probability of subsequent request instructions. For example, the request data from 30 historical request data packets can be predicted to obtain the probability of the request instruction corresponding to each request data set.

[0189] In some embodiments, the request probability, i.e., the corresponding request URL information, is stored in a hash table `probability_map`, where the key attribute is the URL information that may occur, and the value attribute is the probability of the URL occurring. To avoid consuming too much memory space, the request data will be written to disk every 30 seconds to facilitate subsequent offline optimization of the prediction model; this embodiment does not impose any restrictions on this.

[0190] Step S903: Based on the request probability, calculate the weight of each buffer item in the cache table to obtain weight information.

[0191] In some embodiments, the weight of each cached item in the cache table is calculated based on a hash table of request probabilities to obtain weight information. Specifically, the cache table contains multiple cached items, and the weights are determined according to the formula... Calculate the weight of each cache item, where Q represents the weight of the cache item. This represents the weighting coefficient, in this embodiment p represents the request probability. It's understandable that for a newly added cached item or a cached item that was hit this time, the prediction model predicts a request probability of p = 1; for a request that doesn't appear in the hash table probability_map but does appear in the cached item, p = 0.

[0192] Step S904: Replace the cache item with the smallest weight according to the weight information to update the cache table.

[0193] In some embodiments, when the cache table is full, the cache item with the lowest weight is replaced according to the weight information of the cache item, that is, the cache item that is least likely to appear in the future is replaced, thereby updating the cache items in real time and effectively improving the hit rate of the kernel cache.

[0194] The data packet caching method of this application is illustrated below through a complete embodiment:

[0195] Reference Figure 11 As shown, the caching framework of the data packet caching method in this implementation is named e-cache, which has four modules: inbound processing module, outbound processing module, user-customized module, and intelligent memory management module. The inbound processing module and outbound processing module are located in kernel mode, while the user-customized module and intelligent memory management module are located in user mode.

[0196] Developers can configure matching conditions, processing logic, and construction logic through the interface provided by the user customization module. Based on the user's settings, the user customization module records the matching conditions, processing logic, and response packet construction method for each application, and passes them to the inbound processing module using the `prog_array` and `map` structures in eBPF. See Table 1 below for the relevant parameters of the matching conditions.

[0197] Table 1 Matching conditions

[0198]

[0199] Referring to Tables 2 and 3 below, the Process_map structure represents the request parameters and first mapping relationship of the second interface for configuring the processing logic.

[0200] Table 2 Second Interface Request Parameters

[0201] Fields illustrate Required App_key App unique identifier yes Process_name Processing logic name yes Process Processing logic yes

[0202] Table 3 Process_map Structure

[0203] Key composition illustrate Value composition illustrate App_key App unique identifier Process_name Processing logic name

[0204] Referring to Tables 4 and 5 below, the Data_Structure_map structure represents the request parameters of the third interface for configuring the construction logic and the second mapping relationship.

[0205] Table 4 Third Interface Request Parameters

[0206] Fields illustrate Required App_key App unique identifier yes Data_Structure_name Data packet construction logical name yes Data_Structure Data packet construction logic yes

[0207] Table 5 Data_Structure_map structure

[0208] Key composition illustrate Value composition illustrate App_key App unique identifier Data_Structure name Construct logic name

[0209] After the user-customized module processes the user's configuration information, it transmits the information to the kernel through the eBPF map. When the kernel subsequently captures the request data packet, it can quickly and accurately select the most matching processing and construction logic to complete the parsing of the request data packet and the construction of the response data packet.

[0210] Specifically, in response to a user's request, the XDP hook function retrieves the request data packet from network devices such as the network card, and then... Figure 12 The flowchart of the inbound processing module shown below illustrates the first parsing process to obtain matching parameters. Based on the longest match principle, the most matching application identifier is obtained from the matching conditions. Then, it is determined whether the application identifier matches the target application. If they do not match, the request data packet is processed according to the general process. If they match, the corresponding processing logic name Process_name is found in the Process_map based on the application identifier App_key. Then, the corresponding processing logic Process is found in the prog_array using Process_name. Finally, the corresponding processing logic Process is called using the bpf_tail_call method to perform a second parsing of the request data packet.

[0211] After the request data packet completes its second parsing, the parsed data is obtained. The source port, source address, destination port, protocol information, and URL information are combined to form a matching key, which is then used to query the first hash table. Refer to Table 6 below for the structure of the first hash table, Response_cache_Map.

[0212] Table 6 Response_cache_Map Structure

[0213] Key composition illustrate Value composition illustrate Source_port Source port valid Is it available? Source_IP Source address Content_hash Data hash value Dest_port Destination port Response Response caching Protocol Agreement Information URL Request information

[0214] This involves checking the first hash table to see if the response cache corresponding to the request packet exists. If a cache hit is found, a response packet is constructed based on the pre-configured construction logic and the corresponding response cache. Specifically, the App_key is used to find the construction logic name Data_Structure_name in Data_Structure_map, and then the corresponding construction logic Data_Structure is found in prog_array based on Data_Structure_name to construct the response packet. Simultaneously, the source and destination ports, source and destination addresses of the original data are replaced, and the checksum information in the packet header is recalculated. Finally, the packet is redirected. This eliminates the need for a lengthy and complex kernel network protocol stack and reduces unnecessary data copying between kernel and user space, significantly improving response performance.

[0215] If the response to the request packet is not cached in the first hash table, the first hash table is initialized, and the data corresponding to the request packet is stored in the first hash table. Specifically, the data hash value of the request packet is calculated, and based on the initial key obtained from parsing the data, the data hash value is stored in the first hash table. Simultaneously, the `valid` field is set to an unavailable state, and the response cache `Response` is set to empty, thus preventing e-cache from misusing incomplete cached data. Referring to the second hash table `Key_content_map` structure shown in Table 7 below, updating it before the request packet is sent to the target application for a response effectively resolves hash collisions and helps the outgoing chain processing module find the request packet information, thereby updating the cached first hash table.

[0216] Table 7 Key_content_map structure

[0217] Key composition illustrate Value composition illustrate Content_hash Data hash value URL Request information Source_port Source port Source_IP Source address Protocol Agreement Information Dest_port Destination port

[0218] If the kernel's first hash table does not have a cached response to the request packet, the request packet is sent to the network protocol stack, which then transmits it to the target application in user space for a response. After receiving the response packet, it is obtained by the TC hook function and processed in the outgoing chain processing module when it passes through the network protocol stack.

[0219] Specifically, similar to the inbound processing module, the response data packet undergoes a first parsing to obtain matching parameters and conditions. This involves swapping the source and destination ports and addresses to obtain the corresponding application identifier based on the longest match principle. The appropriate processing logic is then selected to perform a second parsing of the response data packet, yielding the response data. (Refer to...) Figure 13The cache update flowchart shown illustrates that the response data contains the source address, source port, destination address, and destination port information from the request data packet. Based on this, the corresponding request data packet can be retrieved, and a data hash value can be calculated. Using the data hash value as an index, the corresponding parsed data is queried according to the second hash table. It is then determined whether the URL information in the parsed data and the URL information in the request data packet are the same request, effectively resolving the hash collision problem. Finally, the response information is updated as the response cache to the corresponding position in the first hash table, and the `vail` field is set to available. Timely cache updates effectively improve the cache hit rate.

[0220] The intelligent memory management module, including data preprocessing and prediction models, specifically utilizes the LSTM algorithm to predict subsequent user request commands, thereby determining the allowable cache size for each application. After the inbound processing module performs a second parsing of the request data packet, the parsed data is passed to the intelligent memory management module in user space via an eBPF map, referring to... Figure 14 The flowchart of the intelligent memory management module shown first processes the parsed data through data cleaning and normalization, then records it in memory. Next, it checks if the memory data exceeds a threshold. If it does, the request data is written to disk and expired data in memory is cleaned up. Otherwise, the request data and historical request data in memory are directly input into the prediction model. The model then obtains the request probability of each request instruction, stores the probability and corresponding request URL information in a hash table `probability_map`, and passes it to the kernel for timely updates to the cache. Understandably, if the prediction model becomes outdated, it can be optimized and updated based on the latest request data, such as request data from the last 7 days or 1 day, thus ensuring the timeliness of the prediction model.

[0221] Therefore, in the embodiments of this application, only the application developers need to configure the required matching conditions, processing logic, and construction logic in user space using the interface of the user-customized module, flexibly adapting to various applications. For the two paths of data input and output, this application uses XDP hook functions and TC hook functions respectively for acquisition, and performs initial parsing on the acquired data packets to find the corresponding processing logic for subsequent processing. To solve the problem of small kernel cache space and difficulty in memory space allocation for multiple applications, this application also adds an intelligent memory management module to predict subsequent request instructions, guide cache item updates, and improve the overall cache hit rate. This application provides an e-cache caching framework for applications to implement kernel-level caching, which not only effectively manages the protocol processing logic between multiple applications, but also optimizes the overall cache hit rate of the system, improving user development efficiency while also enhancing system response performance.

[0222] This invention also provides a data packet caching device that can implement the above-described data packet caching method, see reference. Figure 15 As shown, in some embodiments of this application, the data packet buffering device includes:

[0223] The data packet response module 100 is used to obtain the request data packet in response to the user's request command;

[0224] The first parsing module 200 is used to perform a first parsing on the request data packet, obtain matching parameters, and match the matching parameters with preset matching conditions to obtain matching results;

[0225] The second parsing module 300 is used to perform a second parsing on the request data packet if the matching result indicates that the request data packet matches the target application, and obtain parsed data by using the pre-configured processing logic of the target application;

[0226] The cache query module 400 is used to query the cache table to determine whether the data hash value of the request data packet is cached based on the parsed data, and obtain the cache identifier.

[0227] The packet construction module 500 is used to construct a response packet for the request packet based on the cache table and the construction logic of the pre-configured target application, if the cache identifier represents the data hash value of the request packet already cached in the cache table.

[0228] The cache update module 600 is used to initialize the cache table based on the parsed data if the cache identifier represents the data hash value of the request data packet not cached in the cache table, send the request data packet to the target application for response, obtain the response data packet, and update the cache table based on the response data packet.

[0229] Reference Figure 16 As shown, in some embodiments of this application, the data packet buffering device further includes:

[0230] The cache prediction module 700 is used to predict the probability of obtaining subsequent request instructions based on parsed data and update the cache table based on the request probability.

[0231] The pre-configuration module 800 is used to configure the matching conditions, processing logic, and construction logic according to the preset interface and application identifier.

[0232] The specific implementation of the data packet caching device in this embodiment is basically the same as the specific implementation of the data packet caching method described above, and will not be repeated here.

[0233] Figure 17An electronic device 1000 according to an embodiment of this application is shown. The electronic device 1000 includes: a processor 1001, a memory 1002, and a computer program stored on the memory 1002 and executable on the processor 1001. When the computer program is executed, it is used to perform the above-described data packet caching method.

[0234] The processor 1001 and the memory 1002 can be connected via a bus or other means.

[0235] The memory 1002, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs, such as the data packet caching method described in the embodiments of this application. The processor 1001 implements the above-described data packet caching method by running the non-transitory software program and instructions stored in the memory 1002.

[0236] The memory 1002 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store the data packet caching method described above. Furthermore, the memory 1002 may include high-speed random access memory (RAM) and non-transitory memory, such as at least one storage device, flash memory, or other non-transitory solid-state storage device. In some embodiments, the memory 1002 may optionally include remotely located memories 1002 relative to the processor 1001, which can be connected to the electronic device 1000 via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks (LANs), mobile communication networks, and combinations thereof.

[0237] The non-transitory software program and instructions required to implement the above-described packet caching method are stored in memory 1002. When executed by one or more processors 1001, the above-described packet caching method is executed, for example, executing... Figure 1 Method steps S101 to S106 in the above method Figure 2 Method steps S201 to S203, Figure 4 Method steps S301 to S303, Figure 5 Method steps S401 to S402, Figure 6 Method steps S501 to S503, Figure 7 Method steps S601 to S605, Figure 8 Method steps S701 to S709, Figure 9 Method steps S801 to S802, Figure 10 The method steps S901 to S904.

[0238] This application also provides a storage medium, which is a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned data packet caching method. The memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, the memory may include high-speed random access memory and non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0239] The packet caching method, apparatus, electronic device, and storage medium provided in this application can flexibly and efficiently implement kernel caching, allowing network simulation verification platforms to flexibly, efficiently, and seamlessly improve response performance for applications. Request packets can be processed according to pre-configured processing logic, quickly responding in the cache and constructing response packets according to preset construction logic. The processing and construction logics for different applications can be configured, improving the scalability and response speed of the caching mechanism. Furthermore, timely updating the cache when there is no corresponding response data in the cache table effectively improves the cache hit rate.

[0240] This application also has the following advantages:

[0241] 1. For kernel caching scenarios, this application proposes a general caching framework, e-cache. By providing configuration interfaces for matching conditions, protocol parsing processing logic, and response packet construction logic, it flexibly adapts to the response optimization needs of various applications.

[0242] 2. This application proposes an intelligent memory management mechanism that uses the LSTM algorithm to predict subsequent user request commands and determine the allocation and update strategy of the kernel cache, thereby solving the problem of low cache hit rate caused by insufficient kernel cache space.

[0243] 3. This application proposes a scheme to manage the processing logic of different applications using a tree structure, which can not only quickly and accurately find the most matching processing logic, but also greatly reduce the resources consumed by condition matching.

[0244] 4. This application not only provides the first parsing of the basic protocol, but also proposes a general processing logic for kernel caching. Users only need to provide application-level processing logic to use kernel caching, which solves the problems of high development difficulty and a lot of duplicate code in existing solutions in multi-application scenarios.

[0245] The embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0246] It will be understood by those skilled in the art that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, storage device storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, as is known to those skilled in the art, communication media typically include computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0247] It should also be understood that the various implementation methods provided in this application can be combined arbitrarily to achieve different technical effects. The above is a detailed description of the preferred embodiments of this application, but this application is not limited to the above-described embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of this application.

Claims

1. A data packet caching method, characterized in that, include: Responding to the user's request command, retrieve the request data packet; The header information of the request data packet is parsed using network protocol to obtain matching parameters; The matching parameters include at least one of the following: source port, source address, destination port, destination address, and protocol information; The source address, destination address, source port, destination port, and protocol information are sequentially matched with the matching conditions, and the application identifier is obtained according to the longest matching principle. Determine whether the application identifier matches the target application, and obtain the matching result; If the matching result indicates that the request data packet matches the target application, the request data packet is parsed a second time using the pre-configured processing logic of the target application to obtain parsed data; Based on the parsed data, query the cache table to see if the data hash value of the request data packet is cached, and obtain the cache identifier; If the cache identifier indicates that the cache table has cached the data hash value of the request data packet, construct the response data packet of the request data packet according to the cache table and the pre-configured construction logic of the target application; If the cache identifier indicates that the cache table does not cache the data hash value of the request data packet, the cache table is initialized based on the parsed data, the request data packet is sent to the target application to receive a response data packet, and the cache table is updated based on the response data packet; The application includes multiple applications, each with a unique application identifier. Before obtaining the request data packet in response to a user's request instruction, the method further includes: configuring the matching conditions, processing logic, and construction logic based on a preset interface and the application identifier, including: configuring the matching conditions for the corresponding application based on a first interface and the application identifier, and storing the matching conditions for different applications in a tree structure; the matching conditions include the application identifier and protocol information; configuring the processing logic for the corresponding application based on a second interface and the application identifier, and naming the processing logic to obtain a processing logic name; the application identifier and the processing logic name satisfy a first mapping relationship; configuring the construction logic for the corresponding application based on a third interface and the application identifier, and naming the construction logic to obtain a construction logic name; the application identifier and the construction logic name satisfy a second mapping relationship.

2. The data packet caching method according to claim 1, characterized in that, If the matching result indicates that the request data packet matches the target application, the request data packet is parsed a second time using the pre-configured processing logic of the target application to obtain parsed data, including: If the matching result is that the application identifier matches the target application, the processing logic name is obtained based on the application identifier; the application identifier and the processing logic name satisfy a first mapping relationship. Based on the processing logic name, the pre-configured processing logic of the target application is invoked to perform a second parsing on the request data packet to obtain the parsed data; the parsed data includes at least one of the following: request information, protocol information, source port, source address, destination port, and destination address, wherein the request information includes URL information.

3. The data packet caching method according to claim 2, characterized in that, The cache table includes a first hash table, the key attributes of which include at least one of the following: request source port, request source address, request destination port, request protocol information, and request URL information; the value attributes of the first hash table include: request data hash value; the step of querying the cache table to determine whether the data hash value of the request data packet is cached based on the parsed data to obtain a cache identifier includes: The source port in the parsed data is used as the request source port, the source address is used as the request source address, the destination port is used as the request destination port, the protocol information is used as the request protocol information, and the URL information is used as the request URL information. By combining the request source port, the request source address, the request destination port, the request protocol information, and the request URL information, a matching key is obtained; Based on the key to be matched, query whether the first hash table caches the corresponding request data hash value to obtain a cache identifier; the request data hash value corresponds to the data hash value of the request data packet.

4. The data packet caching method according to claim 3, characterized in that, The value attribute of the first hash table further includes: response cache; the step of constructing a response data packet for the request data packet based on the cache table and the pre-configured construction logic of the target application, if the cache identifier indicates that the cache table has cached the data hash value of the request data packet, includes: If the cache identifier indicates that the first hash table has cached the data hash value of the request data packet, the response cache corresponding to the request data packet in the first hash table is obtained based on the key to be matched; The construction logic name is obtained based on the application identifier; the application identifier and the construction logic name satisfy a second mapping relationship; Based on the construction logic name, the pre-configured construction logic of the target application is invoked to construct the response cache, thereby obtaining the initial response data packet; The source port and destination port, source address and destination address in the parsed data are swapped, and the verification information is calculated to obtain the redirection information; The response data packet is obtained based on the initial response data packet and the redirection information.

5. The data packet caching method according to claim 3, characterized in that, The first hash table's value attributes further include: cache status and response cache; the cache table further includes a second hash table, the key attribute of which is the request data hash value, and the value attributes of which include at least one of the following: request source port, request source address, request destination port, request protocol information, and request URL information; the step of, if the cache identifier indicates that the cache table does not cache the data hash value of the request data packet, initializing the cache table based on the parsed data, sending the request data packet to the target application for a response, obtaining a response data packet, and updating the cache table based on the response data packet, includes: If the cache identifier indicates that the first hash table does not cache the data hash value of the request data packet, calculate the data hash value of the request data packet; The source port in the parsed data is used as the request source port, the source address is used as the request source address, the destination port is used as the request destination port, the protocol information is used as the request protocol information, and the URL information is used as the request URL information. The initial key is obtained by combining the request source port, the request source address, the request destination port, the request protocol information, and the request URL information; Based on the initial key, the data hash value is cached in the first hash table as the request data hash value, and the cache state is initialized to an unavailable state, while the response cache is empty; The request data packet is sent to the target application to receive a response, and the response data packet is obtained. The response data packet is acquired and parsed to obtain response data; the response data includes at least one of the following: response information, the source port, the source address, the destination port, and the destination address; Obtain the corresponding request data packet based on the source port, the source address, the destination port, and the destination address, and calculate the corresponding data hash value based on the request data packet; The data hash value is used as the request data hash value, and the request data hash value is used as the matching key of the second hash table to retrieve the corresponding parsed data. The parsed data is used as the key to be matched in the first hash table, the response information is used as the response cache and cached in the first hash table, and the cache status is updated to an available status.

6. The data packet caching method according to claim 5, characterized in that, Before sending the request data packet to the target application for a response and obtaining the response data packet, the method further includes: The data hash value is used as the request data hash value, and the request data hash value is used as the key attribute of the second hash table, while the initial key is used as the value attribute of the second hash table; The key attribute and the value attribute are stored in the second hash table.

7. The data packet caching method according to claim 1, characterized in that, The method further includes: predicting the probability of obtaining subsequent request instructions from different request data based on the parsed data, and updating the cache table based on the request probability, including: The parsed data is preprocessed to obtain the request data to be predicted; the request data includes at least one of the following: application identifier, source port, source address, request information, request time, and hit status. The first hit status indicates that the request data packet has a response cache in the cache table, the second hit status indicates that the request data packet has no response cache in the cache table, and the third hit status indicates that the request data packet is not in the cache table. The request data to be predicted and historical request data are input into the prediction model for prediction, and the request probability of the request instruction corresponding to each request data is obtained; the prediction model is a pre-trained LSTM prediction model. Based on the request probability, the weight of each cached item in the cache table is calculated to obtain weight information; the cache table stores multiple cached items, and each cached item includes a key attribute and a value attribute; Based on the weight information, the cache item with the smallest weight is replaced to update the cache table.

8. A data packet buffering device, characterized in that, The packet caching method as described in any one of claims 1 to 7 includes: The data packet response module is used to respond to user request commands and obtain request data packets; The first parsing module is used to perform network protocol parsing on the header information of the request data packet to obtain the matching parameters; the matching parameters include at least one of the following: source port, source address, destination port, destination address, and protocol information; the source address, destination address, source port, destination port, and protocol information are sequentially matched with the matching conditions, and the application identifier is obtained according to the longest matching principle; it is then determined whether the application identifier matches the target application to obtain the matching result; The second parsing module is used to perform a second parsing on the request data packet using the pre-configured processing logic of the target application if the matching result indicates that the request data packet matches the target application, so as to obtain parsed data. The cache query module is used to query the cache table based on the parsed data to determine whether the data hash value of the request data packet is cached, and to obtain the cache identifier. A data packet construction module is used to construct a response data packet for the request data packet based on the cache table and the pre-configured construction logic of the target application if the cache identifier indicates that the cache table has cached the data hash value of the request data packet; The cache update module is used to initialize the cache table based on the parsed data if the cache identifier represents the data hash value of the request data packet not cached in the cache table, send the request data packet to the target application for response, obtain the response data packet, and update the cache table based on the response data packet; The application includes multiple applications, each with a unique application identifier. Before obtaining the request data packet in response to a user's request instruction, the method further includes: configuring the matching conditions, processing logic, and construction logic based on a preset interface and the application identifier, including: configuring the matching conditions for the corresponding application based on a first interface and the application identifier, and storing the matching conditions for different applications in a tree structure; the matching conditions include the application identifier and protocol information; configuring the processing logic for the corresponding application based on a second interface and the application identifier, and naming the processing logic to obtain a processing logic name; the application identifier and the processing logic name satisfy a first mapping relationship; configuring the construction logic for the corresponding application based on a third interface and the application identifier, and naming the construction logic to obtain a construction logic name; the application identifier and the construction logic name satisfy a second mapping relationship.

9. The data packet buffering device according to claim 8, characterized in that, The device further includes: The cache prediction module is used to predict the probability of obtaining subsequent request instructions based on the parsed data, and update the cache table based on the request probability.

10. The data packet buffering device according to claim 8, characterized in that, The device further includes: The pre-configuration module is used to configure the matching conditions, the processing logic, and the construction logic according to the preset interface and application identifier.

11. An electronic device, characterized in that, The device includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the data packet caching method as described in any one of claims 1 to 7.

12. A computer-readable storage medium, characterized in that, The storage medium stores a program that is executed by a processor to implement the data packet caching method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Cache optimization method aiming at mobile equipment and based on predication

    CN103294912A

  • Data packet scheduling method, device and equipment and readable storage medium

    CN115567590A