Data communication method and device based on shared memory

By using memory mapping in the vehicle timing database to pre-allocate memory blocks and transmit only file name and size information, the problem of data ingestion delay and high computing power consumption in the vehicle environment is solved, efficient data communication and processing is achieved, and vehicle safety is improved. performance.

CN118626291APending Publication Date: 2024-09-10NEUSOFT RUICHI AUTOMOTIVE TECH (DALIAN) CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410783414.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

In the vehicle environment, during the data ingestion process of the vehicle time series database, the CPU needs to perform multiple data copies and network protocol stack processing, resulting in high computing power consumption, increased latency, and impact on real-time performance.

Method used

Pre-allocate physical memory blocks as data buffers through memory mapping, and only transmit data identification and serialized data size information, reducing CPU and network transmission burdens and achieving efficient data communication and processing.

Benefits of technology

It significantly reduces CPU computing power consumption, improves vehicle performance, reduces data transmission and processing delays, and improves data processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626291A
    Figure CN118626291A
Patent Text Reader

Abstract

The invention provides a data communication method based on a shared memory. The data communication method is applied to a vehicle-mounted time sequence database client. When the method is executed, a client pre-allocates at least one physical memory block as a data buffer area through memory mapping, and establishes a corresponding relationship between each memory block and a data identifier; when the client needs to write service data, serializing the service data into a pre-allocated physical memory block, and determining a data identifier corresponding to the memory block and size information of the serialized data; and the client sends the data identifier and the size information of the serialized data to the vehicle-mounted time sequence database server so as to instruct the vehicle-mounted time sequence database server to read the data from the corresponding physical memory block and process the data. Therefore, the memory blocks are pre-allocated by using memory mapping, and only the file name and size information are transmitted, so that the burden of CPU and network transmission is remarkably reduced, efficient data communication and data processing are realized, the computing power consumption of the CPU is reduced, and the performance of the vehicle is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a data communication method and device based on shared memory. Background Art

[0002] With the continuous advancement of smart car technology, the significant increase in vehicle-side computing power has made edge computing a feasible data processing method. Direct data analysis on the vehicle side can not only save the traffic of uploading data, release cloud computing power, but also greatly improve the real-time performance of data analysis. Since the signals generated by the vehicle have natural time series, the on-board time series database has become a key technology for vehicle-side data analysis.

[0003] The on-board time series database usually adopts an architecture tailored from the cloud time series database to adapt to the characteristics of the in-vehicle environment. During the data processing process, the on-board time series database ingests and analyzes data through the CS (Client-Server) communication mode. Specifically, the on-board time series database client needs to serialize the business data in the memory into a byte array for transmission over the network. Then, the data is sent out by calling the send method. At this time, the CPU needs to copy the data from the user space to the socket buffer in the kernel space. Next, the network protocol stack processes the data and then sends the data to the server through the network. On the server, the CPU copies the data from the socket buffer to the process's memory again and performs a deserialization operation.

[0004] The serialization, memory copy, network protocol stack processing, and deserialization of these data all require the CPU to process the complete submitted data set, occupying valuable computing resources. In a vehicle environment, due to the limitation of computing resources, this processing method may increase the delay of data intake and even affect the real-time performance of the vehicle. Summary of the invention

[0005] In view of this, the present application provides a data communication method and device based on shared memory, aiming to reduce CPU computing power consumption and improve vehicle performance.

[0006] In a first aspect, the present application provides a data communication method based on shared memory, which is applied to a vehicle-mounted time series database client, and the communication method includes:

[0007] The vehicle-mounted time series database client pre-allocates at least one physical memory block as a data buffer through memory mapping, and establishes a corresponding relationship between each memory block and a data identifier;

[0008] When the vehicle-mounted time series database client needs to write business data, the business data is serialized into the pre-allocated physical memory block, and the data identifier corresponding to the memory block and the size information of the serialized data are determined;

[0009] The vehicle-mounted time series database client sends the data identifier and the size information of the serialized data to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read the data from the corresponding physical memory block and process it.

[0010] Optionally, the vehicle-mounted time series database client includes a user space and a kernel space, and the vehicle-mounted time series database client sends the data identifier and size information of the serialized data to the vehicle-mounted time series database server, including:

[0011] The vehicle-mounted time series database client encapsulates the data identifier and the size information of the serialized data into a message to be sent in the user space and calls the kernel space;

[0012] The kernel space copies the data identifier and size information of the serialized data from the user space to the socket buffer of the kernel space in response to the call request from the user space;

[0013] In the kernel space, the data identifier and the size information of the serialized data are encapsulated and processed using the network protocol stack, and then sent to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read the data from the corresponding physical memory block and process it.

[0014] Optionally, the encapsulating the data identifier and the size information of the serialized data by using a network protocol stack in the kernel space and then sending the encapsulated data to the vehicle-mounted time series database server includes:

[0015] Adding network protocol header information to the data identifier and data size using a network protocol stack in the kernel space;

[0016] Calculating the checksum of the data identifier and the data size using a network protocol stack in the kernel space;

[0017] Encapsulating the data identifier, size information of the serialized data, network protocol header information and checksum into a data packet;

[0018] The data packet is sent to the vehicle-mounted time series database server.

[0019] Optionally, the vehicle-mounted time series database client includes an SDK, and when the vehicle-mounted time series database client needs to write service data, serializing the service data into the pre-allocated physical memory block includes:

[0020] The vehicle-mounted time series database client maps the at least one physical memory block to a virtual address space corresponding to the vehicle-mounted time series database client;

[0021] When the vehicle-mounted time series database client needs to write business data, the data to be written cached in the SDK is serialized into the physical memory block corresponding to the virtual address space.

[0022] Optionally, the vehicle-mounted time series database client pre-allocates at least one physical memory block as a data buffer through memory mapping, and establishes a corresponding relationship between each memory block and a data identifier, including:

[0023] The vehicle-mounted time series database client uses a memory mapping function to pre-allocate a physical memory block of a specified size;

[0024] The vehicle-mounted time series database client allocates a unique data identifier for each allocated physical memory block; the data identifier is used to identify the memory block address corresponding to each allocated physical memory block;

[0025] The vehicle-mounted time series database client establishes and stores a mapping table between the data identifier and the memory block address.

[0026] In a second aspect, the present application provides a data communication method based on shared memory, which is applied to a vehicle-mounted time series database server, and the communication method includes:

[0027] The vehicle-mounted time series database server receives the data identifier and the size information of the serialized data sent from the vehicle-mounted time series database client; the serialized data is serialized by the vehicle-mounted time series database client according to the business data and written into the physical memory block corresponding to the data identifier; the physical memory block is pre-allocated by the vehicle-mounted time series database client using memory mapping;

[0028] The vehicle-mounted time series database server reads and processes the data from the corresponding physical memory block according to the data identifier and the size information of the serialized data.

[0029] Optionally, the vehicle-mounted time series database server includes a user space and a kernel space, and the vehicle-mounted time series database server receives the data identifier and size information of the serialized data sent from the vehicle-mounted time series database client, including:

[0030] In response to receiving the data identifier and the size information of the serialized data sent by the on-board time series database client, the on-board time series database server kernel space copies the data identifier and the size information of the serialized data to the socket buffer of the on-board time series database server kernel space, and transmits the data identifier and the size information of the serialized data to the on-board time series database server user space.

[0031] Optionally, the user space includes a vehicle-mounted time series database server virtual address space and a vehicle-mounted time series database server memory buffer, and the vehicle-mounted time series database server reads data from a corresponding physical memory block and processes the data according to the data identifier and the size information of the serialized data, including:

[0032] The vehicle-mounted time series database server uses memory mapping to map the physical memory pre-allocated by the vehicle-mounted time series database client to its own virtual address space according to the data identifier to obtain serialized data;

[0033] The vehicle-mounted time series database server deserializes the serialized data according to the size information of the serialized data to obtain business data.

[0034] In a third aspect, the present application provides a data communication device based on shared memory, which is applied to a vehicle-mounted time series database client, and the communication device includes:

[0035] A memory mapping module, used for the vehicle-mounted time series database client to pre-allocate at least one physical memory block as a data buffer through memory mapping, and establish a corresponding relationship between each memory block and a data identifier;

[0036] A writing module, used for serializing the business data into the pre-allocated physical memory block when the vehicle-mounted time series database client needs to write business data, and determining the data identifier corresponding to the memory block and the size information of the serialized data;

[0037] The sending module is used for the vehicle-mounted time series database client to send the data identifier and the size information of the serialized data to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read the data from the corresponding physical memory block and process it.

[0038] In a fourth aspect, the present application provides a data communication device based on shared memory, which is applied to a vehicle-mounted time series database server, and the communication device includes:

[0039] A receiving module is used for the vehicle-mounted time series database server to receive the data identifier and the size information of the serialized data sent from the vehicle-mounted time series database client; the serialized data is written into the physical memory block corresponding to the data identifier by the vehicle-mounted time series database client according to the business data serialization; the physical memory block is pre-allocated by the vehicle-mounted time series database client using memory mapping;

[0040] The reading module is used for the vehicle-mounted time series database server to read and process data from the corresponding physical memory block according to the data identifier and the size information of the serialized data.

[0041] The present application provides a data communication method based on shared memory, which is applied to a vehicle-mounted time series database client. When executing the method, the vehicle-mounted time series database client pre-allocates at least one physical memory block as a data buffer through memory mapping, and establishes a corresponding relationship between each memory block and a data identifier; when the vehicle-mounted time series database client needs to write business data, the business data is serialized into the pre-allocated physical memory block, and the data identifier corresponding to the memory block and the size information of the serialized data are determined; the vehicle-mounted time series database client sends the data identifier and the size information of the serialized data to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read and process the data from the corresponding physical memory block. In this way, by using memory mapping to pre-allocate memory blocks and only transmitting file names and size information, the burden on the CPU and network transmission is significantly reduced, efficient data communication and data processing are achieved, CPU computing power consumption is reduced, and vehicle performance is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in this embodiment or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0043] Figure 1 A schematic diagram of a related technology for implementing data ingestion provided in an embodiment of the present application;

[0044] Figure 2 A method flow chart of a shared memory-based data communication method provided in an embodiment of the present application;

[0045] Figure 3 A flowchart of a possible implementation method of step S1 provided in an embodiment of the present application;

[0046] Figure 4A data communication process based on shared memory is provided in the embodiment of the present application;

[0047] Figure 5 A flowchart of a possible implementation method of step S3 provided in an embodiment of the present application;

[0048] Figure 6 is a flow chart of a data communication method based on shared memory provided by an embodiment of the present disclosure;

[0049] Figure 7 is a schematic diagram of a data communication device based on a shared memory provided by an embodiment of the present disclosure, which is applied to a vehicle-mounted time series database client;

[0050] Figure 8 It is a schematic diagram of another shared memory-based data communication device provided in an embodiment of the present disclosure, which is applied to a vehicle-mounted time series database server. DETAILED DESCRIPTION

[0051] With the rapid development of automotive electronics and intelligence, modern vehicles are gradually evolving into complex systems that integrate a large number of sensors and advanced control systems. These systems generate a large amount of real-time data every second, including signals from multiple fields such as engines, chassis, body control, safety systems, and advanced driver assistance systems (ADAS). In order to effectively utilize this data, the on-board time series database has become a key technical component.

[0052] In-vehicle time series databases usually use an architecture tailored from cloud-based time series databases to adapt to the characteristics of the in-vehicle environment. In the process of data ingestion, network-based CS (Client-Server) communication is a common method. Specifically, the data ingestion process of an in-vehicle time series database involves multiple key steps. Figure 1 A schematic diagram of a related technology for implementing data ingestion provided in an embodiment of the present application. Figure 1As shown in the figure, the client needs to serialize the business data in the SDK memory into a byte array for transmission over the network. Then, the data is sent out by calling the send method. At this time, the CPU needs to copy the data from the user space to the socket buffer in the kernel space. Next, the network protocol stack processes the data copied to the kernel space, such as calculating the checksum, and then sends the data to the socket buffer on the server through the network. On the server side, the CPU again copies the data from the server's socket buffer to the byte array in the memory of the server process, and performs a deserialization operation to restore it to the runtime data structure and store it in the server's memory buffer. These steps require the CPU to process the complete submitted data set, occupying valuable computing resources. In a vehicle environment, due to the limitation of computing resources, this processing method may increase the delay of data ingestion and even affect the real-time performance of the vehicle.

[0053] In view of this, the present application provides a data communication method based on shared memory, which is applied to a vehicle-mounted time series database client. When executing the method, the vehicle-mounted time series database client pre-allocates at least one physical memory block as a data buffer through memory mapping, and establishes a corresponding relationship between each memory block and a data identifier; when the vehicle-mounted time series database client needs to write business data, the business data is serialized into the pre-allocated physical memory block, and the data identifier corresponding to the memory block and the size information of the serialized data are determined; the vehicle-mounted time series database client sends the data identifier and the size information of the serialized data to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read and process the data from the corresponding physical memory block.

[0054] In this way, by using memory mapping to pre-allocate memory blocks and only transmit file name and size information, the burden on the CPU and network transmission is significantly reduced, efficient data communication and data processing are achieved, CPU computing power consumption is reduced, and vehicle performance is improved.

[0055] In order to be able to understand the characteristics and technical contents of the embodiments of the present disclosure in more detail, the implementation of the embodiments of the present disclosure is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present disclosure. In the following technical description, for the convenience of explanation, a full understanding of the disclosed embodiments is provided through multiple details. However, one or more embodiments can still be implemented without these details. In other cases, in order to simplify the drawings, well-known structures and devices can be simplified for display. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0056] Figure 2 A method flow chart of a shared memory-based data communication method provided in an embodiment of the present application is applied to a vehicle-mounted time series database client. Figure 2 As shown, the shared memory-based data communication method provided in the embodiment of the present application may include:

[0057] S1, the vehicle-mounted time series database client pre-allocates at least one physical memory block as a data buffer through memory mapping, and establishes a corresponding relationship between each memory block and a data identifier.

[0058] Memory Mapping (mmap) is a way to allow a process to access the contents of a file or other object as if the contents were loaded into the process's address space. In this way, the process can directly operate on the data in memory without having to read or write files through traditional I / O operations (such as read and write).

[0059] It should be noted that mmap is a memory mapping method in Unix and Unix-like systems, but there are other memory mapping methods in other operating systems or specific application scenarios, such as Named Shared Memory: POSIX APIs (such as shm_open and ftruncate) provide a way to share memory between multiple processes. In some operating systems, device drivers can create memory-mapped devices that map the device's memory or registers to user space, allowing user space programs to directly access hardware resources. Similar functions can also be achieved using databases or in-memory databases (such as Redis, Memcached, etc.). These systems store data in memory and provide a set of APIs to access this data.

[0060] In this step, in order to achieve efficient data transmission, the vehicle-mounted time series database client will use mmap to pre-allocate one or more blocks of physical memory as data buffers before starting. These memory blocks are mapped in the virtual address space of the client process and associated with files or other objects through memory mapping. In order to ensure that both the client and the server can accurately find the data that needs to be transmitted or processed, the client will assign a unique data identifier (which may be an ID, label, file name, etc.) to each pre-allocated memory block. In this way, when data needs to be transmitted, the client only needs to send this data identifier and related metadata (such as data size), and the server can accurately read the data from the corresponding memory block.

[0061] In an optional embodiment, since there are many possible implementations of memory mapping, the embodiment of the present application uses mmap to implement memory mapping, so, Figure 3 A possible implementation flow chart of step S1 provided in the embodiment of the present application, combined with Figure 3 As shown, the vehicle-mounted time series database client pre-allocates at least one physical memory block as a data buffer through memory mapping, and establishes a corresponding relationship between each memory block and a data identifier, including:

[0062] S11, the vehicle-mounted time series database client uses the memory mapping function to pre-allocate a physical memory block of a specified size.

[0063] In this step, the vehicle-mounted time series database client uses the memory mapping function provided by the operating system (such as mmap in Linux system) to request a certain amount of physical memory space. These memory spaces are allocated in the virtual address space of the process, but are actually mapped to a certain area of ​​physical memory. For example: suppose the vehicle-mounted time series database client needs to pre-allocate a 10MB physical memory block to cache time series data. It calls the mmap function and specifies the required size (10MB) and other parameters (such as file descriptor, offset, protection flag, etc.). The operating system allocates the corresponding physical memory space and creates a mapping in the virtual address space of the process.

[0064] S12, the vehicle-mounted time series database client assigns a unique data identifier to each allocated physical memory block.

[0065] In the step, once the physical memory block is allocated, the vehicle-mounted time series database client needs to assign a unique data identifier to each memory block. This identifier can be an integer, string, or other type of unique identifier, which is used to reference and identify this memory block in subsequent operations. For example: Assume that the vehicle-mounted time series database client has allocated 5 10MB memory blocks. It can assign a unique data identifier to each memory block, such as integers 1, 2, 3, 4, 5. These identifiers will be used to reference and operate these memory blocks in subsequent codes.

[0066] In memory, each physical memory block has a corresponding address. A data identifier is associated with this address so that the client and server can quickly find and access the corresponding memory block. Continuing with the above example, assume that the starting address of memory block 1 in the virtual address space is 0x10000000. Then, when the client needs to access memory block 1, it can find this address through data identifier 1 and the mapping table, and directly perform read and write operations. In other words, the data identifier is used to identify the memory block address corresponding to each allocated physical memory block.

[0067] S13, the vehicle-mounted time series database client establishes and saves a mapping table between data identifiers and memory block addresses.

[0068] In order to efficiently manage these memory blocks, the vehicle-mounted time series database client needs to establish a mapping table to save the correspondence between data identifiers and memory block addresses. This mapping table can be a hash table, array, or other data structure, depending on the implementation and performance requirements. Specifically, the client can create a hash table to save the mapping relationship. The key of the hash table is the data identifier (such as integers 1, 2, 3, 4, 5), and the value is the corresponding memory block address (such as 0x10000000, 0x10A00000, etc.). When a memory block needs to be accessed, the client can simply find the corresponding address in the hash table through the data identifier.

[0069] In this way, the vehicle-mounted time series database client and the vehicle-mounted time series database server can effectively improve the efficiency of data transmission, reduce I / O operations, and reduce the use of system resources, and quickly access and operate these memory blocks through unique data identifiers.

[0070] S2: When the vehicle-mounted time series database client needs to write business data, the business data is serialized into a pre-allocated physical memory block, and the data identifier corresponding to the physical memory block and the size information of the serialized data are determined.

[0071] In this step, serialization is the process of converting data structures or object states into a format that can be stored or transmitted. In the vehicle-mounted time series database client, when business data needs to be written, these data (such as complex structures, objects or other data types) need to be converted into a continuous byte stream (usually called "serialized data" or "serialized data") so that they can be stored in physical memory blocks or sent to the server over the network.

[0072] After serializing the business data, the client writes this byte stream to the physical memory block that was previously pre-allocated through memory mapping. After writing the business data to the physical memory block, the client needs to determine two key pieces of information: Data ID: This is a unique identifier used to identify a specific physical memory block. In the previous step, the client has assigned a unique data ID to each allocated physical memory block so that the server can locate and access the data in the memory block based on this ID. Size information of serialized data: This is the byte size of the serialized business data. Since the serialized data is a byte stream, knowing its size is critical for the server to correctly allocate buffers or perform other operations when reading.

[0073] In an alternative embodiment, Figure 4The present invention provides a data communication process based on shared memory. Figure 4 As shown, the vehicle-mounted time series database client includes an SDK.

[0074] In an optional embodiment, the vehicle-mounted time series database client includes an SDK. When the vehicle-mounted time series database client needs to write business data, the business data is serialized into a pre-allocated physical memory block, including: the vehicle-mounted time series database client maps at least one physical memory block to the virtual address space corresponding to the vehicle-mounted time series database client; when the vehicle-mounted time series database client needs to write business data, the data to be written cached in the SDK is serialized into the physical memory block corresponding to the virtual address space.

[0075] SDK is a component of the client that is responsible for handling the logic related to interacting with the database, including data caching, serialization, and writing.

[0076] In this embodiment, the client pre-allocates one or more physical memory blocks ( Figure 4 The corresponding physical memory 0 (disk file 0), physical memory 1 (disk file 1), and physical memory N (disk file N) are used as data buffers. Then, through the memory management function of the operating system, these physical memory blocks are mapped to the virtual address space of the client process. This process establishes a mapping relationship between virtual addresses and physical addresses, allowing the client to directly access data in physical memory through virtual addresses.

[0077] When business data needs to be written to the database, the data will first be cached by the SDK. The SDK provides a variety of interfaces and functions to manage this data, such as data verification, compression, encryption, etc. Before writing, the SDK will serialize the data to be written in the cache. Serialization is the process of converting a data structure or object state into a format that can be stored or transmitted. The serialized data is usually a byte stream, which can be stored and transmitted more efficiently.

[0078] With the mapping relationship between virtual addresses and physical addresses, the SDK can directly access and write data in physical memory blocks through virtual addresses. The SDK writes serialized data to the corresponding physical memory blocks. This process is efficient because the data is directly transmitted in physical memory, reducing data copying and transmission overhead.

[0079] For example, an in-vehicle time series database client needs to record data such as the vehicle's speed, location, and timestamp. These data will first be cached by the SDK and necessary verification and preprocessing will be performed. Then, the SDK will serialize the data in the cache to generate a byte stream containing information such as speed, location, and timestamp. Next, the SDK will write this byte stream to the corresponding physical memory block based on the mapping relationship between the virtual address and the physical address. Finally, the client will notify the server to read the data from the corresponding physical memory block and process it. The entire process is efficient, flexible, and easy to expand.

[0080] In this embodiment, by mapping the physical memory block to the virtual address space, the client can directly access the data in the physical memory, reducing the data copying and transmission overhead, and improving the speed and efficiency of data writing. In addition, the SDK provides a rich interface and functions to manage data, such as data verification, compression, encryption, etc. This makes data processing more flexible and can be customized and optimized according to specific needs. In addition, the SDK-based architecture makes the system easier to expand and maintain. When it is necessary to add new functions or optimize existing functions, it is only necessary to make corresponding modifications in the SDK without making large-scale changes to the entire system.

[0081] S3, the vehicle-mounted time series database client sends the data identifier and the size information of the serialized data to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read the data from the corresponding physical memory block and process it.

[0082] In this embodiment, once the data identifier and size information are determined, the client sends this information to the vehicle-mounted time series database server. After receiving this information, the server can find the corresponding physical memory block according to the data identifier and correctly read and process the data therein according to the size information.

[0083] Specifically, combined Figure 4 ,The vehicle time series database client includes user space and kernel space. Figure 5 A possible implementation flow chart of step S3 provided in the embodiment of the present application, combined with Figure 5 As shown, the vehicle-mounted time series database client sends the data identifier and the size information of the serialized data to the vehicle-mounted time series database server, which may include:

[0084] S31, the vehicle-mounted time series database client encapsulates the data identifier and the size information of the serialized data into a message to be sent in the user space and calls the kernel space.

[0085] The vehicle-mounted time series database client serializes the business data in the user space and stores it in a pre-allocated physical memory block. Then, the client generates a message containing a data identifier (used to identify a specific physical memory block) and the size of the serialized data. This message is to be sent to the server to inform the server where to read the data and how much data to read. The user space will encapsulate this message into a message body to be sent, and prepare to call the kernel space service to send this message. Figure 4 As shown, the user space passes the message to be sent and the sending request to the kernel space through a system call (such as send, sendto, etc.).

[0086] In this step, since the client generates a message including a data identifier and serialized data size information, the message is very small, and in some possible embodiments, it is only about a dozen bytes.

[0087] S32, the kernel space responds to the call request from the user space and copies the data identifier and the size information of the serialized data from the user space to the socket buffer of the kernel space.

[0088] The kernel space responds to the call request from the user space and prepares to send data. The kernel space will first create a socket buffer (if it has not been created yet), and copy the data identifier and serialized data size information provided by the user space from the user space to the socket buffer of the kernel space. This process ensures the integrity and security of the data because the kernel space is isolated from the user space.

[0089] In this step, since only the file name and an integer are copied, the amount of data is very small, for example, only about a dozen bytes as mentioned above. Compared with the traditional solution of copying several MB of data in the entire client memory, the amount of data is reduced to one hundred thousandth of the original.

[0090] S33, in the kernel space, the network protocol stack is used to encapsulate the data identifier and the size information of the serialized data and send them to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read the data from the corresponding physical memory block and process it.

[0091] Next, the kernel space will use the network protocol stack (such as TCP / IP) to encapsulate the message. This may include adding a protocol header, calculating a checksum, determining a route, and other steps. Once the message is encapsulated and ready to be sent, the kernel space will send the message to the network, and the destination address is the address of the vehicle time series database server.

[0092] In an optional embodiment, the data identifier and the size information of the serialized data are encapsulated and processed in the kernel space using the network protocol stack and then sent to the vehicle-mounted time series database server, which may include: adding network protocol header information to the data identifier and data size using the network protocol stack in the kernel space; calculating the data identifier and the checksum of the data size using the network protocol stack in the kernel space; encapsulating the data identifier, the size information of the serialized data, the network protocol header information and the checksum into a data packet; and sending the data packet to the vehicle-mounted time series database server.

[0093] Specifically, in kernel space, the network protocol stack adds appropriate network protocol header information to the data identifier (usually an identifier used to identify the type and source of the data) and the data size (the size of the serialized data). These headers contain metadata about the data packet, such as the source address, destination address, protocol type, etc. The header information is added to ensure that the data packet can be correctly routed and transmitted to the target server in the network.

[0094] In order to ensure the integrity and accuracy of the data, the network protocol stack calculates the checksum of the data identifier, data size, and network protocol header information. The checksum is a simple error detection mechanism used to detect whether an error has occurred in the transmission process of a data packet. The calculation of the checksum is usually based on a certain algorithm (such as CRC, Fletcher check, etc.), and is obtained by performing specific operations on each byte in the data packet. In this embodiment, since only the data identifier and data size are transmitted, the overhead and time of calculating the checksum can be greatly reduced.

[0095] Once the data identifier, data size, network protocol header information and checksum are ready, the network protocol stack will encapsulate them into a complete data packet. This data packet contains all the necessary information for transmission and routing in the network. Finally, the encapsulated data packet will be sent to the vehicle-mounted timing database server. The sending process may involve the interaction of multiple network layers, such as the IP layer, link layer, etc. Each layer will perform corresponding processing on the data packet (such as adding its own header information, performing routing selection, etc.), and the embodiments of the present application do not limit this.

[0096] In this embodiment, although the network protocol stack involves multiple steps and levels in processing data packets, the information added at each level (such as header information, checksum, etc.) is usually only a dozen bytes. This makes the size of the data packet relatively small, reducing the overhead and delay of network transmission. Since the amount of data processed by the network protocol stack is small, the processing time will also be greatly reduced, improving the efficiency of network transmission. And because the amount of data is small, the probability of errors occurring during network transmission will also be reduced, thereby improving the reliability of data transmission.

[0097] In this embodiment, by pre-allocating memory and mapping business data through mmap, the CPU load of data transmission and processing is significantly reduced. By sending only the file name and size information, the network transmission volume and kernel space copy are reduced, thereby greatly improving the overall performance, reducing computing power consumption, and making business processing more efficient.

[0098] Figure 6 1 is a flow chart of a data communication method based on shared memory provided by an embodiment of the present disclosure. Figure 6 As shown, the embodiment of the present disclosure provides a shared memory-based data communication method that can be applied to a vehicle-mounted time series database server. The shared memory-based data communication method may include:

[0099] S4, the vehicle-mounted time series database server receives the data identifier and size information of the serialized data sent from the vehicle-mounted time series database client.

[0100] The serialized data is written into the physical memory block corresponding to the data identifier by the vehicle-mounted time series database client according to the serialization of the business data. The physical memory block is pre-allocated by the vehicle-mounted time series database client using memory mapping. The specific implementation method refers to the contents recorded in S1-S3 above, and this embodiment will not be repeated here.

[0101] S5, the vehicle-mounted time series database server reads and processes the data from the corresponding physical memory block according to the data identifier and the size information of the serialized data.

[0102] In an optional embodiment, the on-board time series database server includes a user space and a kernel space, and the on-board time series database server receives a data identifier and serialized data size information sent from the on-board time series database client, including: the on-board time series database server kernel space responds to receiving the data identifier and serialized data size information sent from the on-board time series database client, copies the data identifier and serialized data size information to the socket buffer of the on-board time series database server kernel space, and transmits the data identifier and serialized data size information to the on-board time series database server user space.

[0103] Combination Figure 4 As shown in the figure, in the vehicle-mounted time series database server, the interaction between the user space and the kernel space is usually involved. When the vehicle-mounted time series database client sends the data identifier and the size information of the serialized data to the server, this process involves receiving data from the network to the kernel space, and then copying the data from the kernel space to the user space for the server program to process.

[0104] Specifically, when the network protocol stack in the server kernel space receives a data packet from the client, it parses the data packet and extracts the data identifier and the size of the serialized data. This information is then copied to the kernel space socket buffer. Next, the server kernel space notifies the user space that there is data to read and copies the data from the kernel space socket buffer to the user space buffer.

[0105] For example, suppose a vehicle-mounted time series database client collects the real-time speed data of the vehicle, serializes it and writes it to a local memory-mapped file. Then, the client sends the file name and size of the serialized data (assuming the file name is "speed_data_20231023" and the size is 14KB) to the server. The client sends the file name "speed_data_20231023" and the size of 14KB to the server through the network.

[0106] After receiving the data packet, the network protocol stack in the kernel space of the server parses the file name and size information and copies them to the socket buffer in the kernel space. The kernel space of the server then notifies the user space that there is data to read. At this point, the server program (running in the user space) calls a system call (such as recv or read) to request to read data from the socket buffer. The kernel responds to this request and copies the file name and size information from the socket buffer in the kernel space to the buffer in the user space. After receiving the file name and size information in the user space, the server program can read the actual serialized data from the client's memory-mapped file based on this information and perform subsequent processing.

[0107] In this process, the server only copies the data identifier and the size of the serialized data, which are usually very small, only a dozen bytes. This design significantly reduces the CPU copy workload and memory bandwidth usage, thereby improving performance.

[0108] In an optional embodiment, the user space includes a vehicle-mounted time series database server virtual address space and a vehicle-mounted time series database server memory buffer. The vehicle-mounted time series database server reads data from the corresponding physical memory block according to the data identifier and the size information of the serialized data and processes the data, including: the vehicle-mounted time series database server uses memory mapping to map the physical memory pre-allocated by the vehicle-mounted time series database client to its own virtual address space according to the data identifier to obtain the serialized data; the vehicle-mounted time series database server deserializes the serialized data according to the size information of the serialized data to obtain the business data.

[0109] In this embodiment, the client serializes the business data and writes it into the pre-allocated physical memory block, and notifies the server through the data identifier (such as the file name or memory block ID) and the size information of the serialized data. After receiving this information, the server uses the memory mapping (mmap) technology to map the pre-allocated physical memory block of the client to its own virtual address space, so that the data can be directly accessed without memory copying.

[0110] Specifically, the vehicle-mounted time series database server determines the location and size of the pre-allocated physical memory block on the client based on the received data identifier. The server then prepares for memory mapping in its own user space. For example, a special file descriptor is opened (possibly through shared memory, temporary files, or other mechanisms), which is associated with the client's physical memory block. The server calls the mmap system call to establish the memory mapping.

[0111] The mmap system call tells the kernel to map the client's physical memory block to the server's virtual address space. This call specifies the starting address, size, access permissions, and other parameters of the physical memory block. After receiving the mmap call, the kernel checks the validity of the parameters and adds appropriate entries to the server's page table to map the physical memory page to the server's virtual address space. During this process, the kernel may allocate some page table entries and related data structures to support this mapping. Once the memory mapping is successfully established, the server can access the data in the client's physical memory block through the virtual address just like accessing its own memory. This data is the serialized business data.

[0112] Furthermore, the server reads the size information of the serialized data received previously. This information tells the server how many bytes of data it needs to read to completely obtain the serialized business data. The server allocates enough space in its own memory buffer to store the deserialized business data. The size of this space should match the size of the serialized data. The server uses the memory mapping established previously to read the serialized business data from the client's physical memory block through the virtual address.

[0113] This process is accomplished by directly accessing the memory in the virtual address space, without the need for additional memory copies. The server decodes (or deserializes) the serialized data it reads into the original business data structure. This process depends on the serialization and deserialization format of the business data, which may be achieved by parsing binary data, JSON, XML, or other formats. Once the data is deserialized into a business data structure, the server can further process the data, such as storing it in a database, performing calculations, sending it to other systems, or performing real-time analysis.

[0114] In the above embodiment, since the server only receives the data identifier and the size information of the serialized data sent by the client, and the server can directly access the data in the client's physical memory block through memory mapping without copying the data to the server's memory. The overhead of memory copying is greatly reduced and the speed of data access is improved. In addition, since the memory copy and related system call overhead are reduced, the entire data processing process becomes more efficient. This helps to improve the throughput and response speed of the system. And since the data can be shared directly between the server and the client without going through the intermediate storage or transport layer, the delay of data processing can be significantly reduced. This is especially important for scenarios where real-time processing of vehicle data is required.

[0115] In summary, the shared memory-based data communication method provided in the embodiment of the present application can reduce the CPU computing power usage by 50% and shorten the single submission time by 30% under the condition of the same data volume.

[0116] The above are some specific implementations of the data communication method based on shared memory provided by the embodiment of the present application. Based on this, the present application also provides a corresponding device. The device provided by the embodiment of the present application will be introduced from the perspective of functional modularization.

[0117] See also Figure 7 The structure diagram of the data communication device 700 based on shared memory is shown, which is applied to the vehicle-mounted time series database client. The device 700 includes a memory mapping module 710, a writing module 720 and a sending module 730.

[0118] The memory mapping module 710 is used for the vehicle-mounted time series database client to pre-allocate at least one physical memory block as a data buffer through memory mapping, and establish a corresponding relationship between each memory block and a data identifier.

[0119] The writing module 720 is used to serialize the business data into the pre-allocated physical memory block when the vehicle-mounted time series database client needs to write business data, and determine the data identifier corresponding to the memory block and the size information of the serialized data.

[0120] The sending module 730 is used for the vehicle-mounted time series database client to send the data identifier and the size information of the serialized data to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read the data from the corresponding physical memory block and process it.

[0121] Optionally, the vehicle-mounted time series database client includes a user space and a kernel space, and the sending module 730 is specifically used to:

[0122] The vehicle-mounted time series database client encapsulates the data identifier and the size information of the serialized data into a message to be sent in the user space and calls the kernel space;

[0123] The kernel space copies the data identifier and size information of the serialized data from the user space to the socket buffer of the kernel space in response to the call request from the user space;

[0124] In the kernel space, the data identifier and the size information of the serialized data are encapsulated and processed using the network protocol stack, and then sent to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read the data from the corresponding physical memory block and process it.

[0125] Optionally, the sending module 730 is specifically configured to:

[0126] Adding network protocol header information to the data identifier and data size using a network protocol stack in the kernel space;

[0127] Calculating the checksum of the data identifier and the data size using a network protocol stack in the kernel space;

[0128] Encapsulating the data identifier, size information of the serialized data, network protocol header information and checksum into a data packet;

[0129] The data packet is sent to the vehicle-mounted time series database server.

[0130] Optionally, the vehicle-mounted time series database client includes an SDK, and the writing module 720 is specifically used for:

[0131] The vehicle-mounted time series database client maps the at least one physical memory block to a virtual address space corresponding to the vehicle-mounted time series database client;

[0132] When the vehicle-mounted time series database client needs to write business data, the data to be written cached in the SDK is serialized into the physical memory block corresponding to the virtual address space.

[0133] Optionally, the memory mapping module 710 is specifically used to:

[0134] The vehicle-mounted time series database client uses a memory mapping function to pre-allocate a physical memory block of a specified size;

[0135] The vehicle-mounted time series database client allocates a unique data identifier for each allocated physical memory block; the data identifier is used to identify the memory block address corresponding to each allocated physical memory block;

[0136] The vehicle-mounted time series database client establishes and stores a mapping table between the data identifier and the memory block address.

[0137] See also Figure 8 The structure diagram of the data communication device 800 based on shared memory is shown, which is applied to the vehicle-mounted time series database server. The device 800 includes a receiving module 810 and a reading module 820.

[0138] The receiving module 810 is used for the vehicle-mounted time series database server to receive the data identifier and the size information of the serialized data sent from the vehicle-mounted time series database client; the serialized data is serialized by the vehicle-mounted time series database client according to the business data and written into the physical memory block corresponding to the data identifier; the physical memory block is pre-allocated by the vehicle-mounted time series database client using memory mapping;

[0139] The reading module 820 is used for the vehicle-mounted time series database server to read and process data from the corresponding physical memory block according to the data identifier and the size information of the serialized data.

[0140] Optionally, the vehicle-mounted time series database server includes a user space and a kernel space, and the receiving module 810 is specifically used to:

[0141] In response to receiving the data identifier and the size information of the serialized data sent by the on-board time series database client, the on-board time series database server kernel space copies the data identifier and the size information of the serialized data to the socket buffer of the on-board time series database server kernel space, and transmits the data identifier and the size information of the serialized data to the on-board time series database server user space.

[0142] Optionally, the receiving module 810 is specifically configured to:

[0143] The vehicle-mounted time series database server uses memory mapping to map the physical memory pre-allocated by the vehicle-mounted time series database client to its own virtual address space according to the data identifier to obtain serialized data;

[0144] The vehicle-mounted time series database server deserializes the serialized data according to the size information of the serialized data to obtain business data.

[0145] The embodiments of the present application also provide corresponding devices and computer storage media for implementing the solutions provided by the embodiments of the present application.

[0146] The device includes a memory and a processor, the memory is used to store instructions or codes, and the processor is used to execute the instructions or codes, so that the device executes the shared memory-based data communication method described in any embodiment of the present application.

[0147] The computer storage medium stores codes, and when the codes are executed, the device executing the codes implements the shared memory-based data communication method described in any embodiment of the present application.

[0148] The "first" and "second" in the names such as "first" and "second" (if any) mentioned in the embodiments of the present application are only used as name identifiers and do not represent the first or second in order.

[0149] Through the description of the above implementation methods, it can be known that those skilled in the art can clearly understand that all or part of the steps in the above-mentioned embodiment method can be implemented by means of software plus a general hardware platform. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a storage medium, such as a read-only memory (ROM) / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a vehicle-mounted time series database server, or a network communication device such as a router) to execute the methods described in each embodiment of the present application or some parts of the embodiments.

[0150] Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.

[0151] The above description is merely an exemplary embodiment of the present application and is not intended to limit the protection scope of the present application.

Claims

1. A data communication method based on shared memory, characterized in that: Applied to the vehicle-mounted time series database client, the communication method includes: The vehicle-mounted time series database client pre-allocates at least one physical memory block as a data buffer through memory mapping, and establishes a corresponding relationship between each memory block and a data identifier; When the vehicle-mounted time series database client needs to write business data, the business data is serialized into the pre-allocated physical memory block, and the data identifier corresponding to the physical memory block and the size information of the serialized data are determined; The vehicle-mounted time series database client sends the data identifier and the size information of the serialized data to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read the data from the corresponding physical memory block and process it.

2. The data communication method based on shared memory according to claim 1, characterized in that: The vehicle-mounted time series database client includes a user space and a kernel space. The vehicle-mounted time series database client sends the data identifier and the size information of the serialized data to the vehicle-mounted time series database server, including: The vehicle-mounted time series database client encapsulates the data identifier and the size information of the serialized data into a message to be sent in the user space and calls the kernel space; The kernel space copies the data identifier and size information of the serialized data from the user space to the socket buffer of the kernel space in response to the call request from the user space; In the kernel space, the data identifier and the size information of the serialized data are encapsulated and processed using the network protocol stack, and then sent to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read the data from the corresponding physical memory block and process it.

3. The data communication method based on shared memory according to claim 2, characterized in that: The step of encapsulating the data identifier and the size information of the serialized data by using the network protocol stack in the kernel space and sending the encapsulated data to the vehicle-mounted time series database server includes: Adding network protocol header information to the data identifier and data size using a network protocol stack in the kernel space; Calculating the checksum of the data identifier and the data size using a network protocol stack in the kernel space; Encapsulating the data identifier, size information of the serialized data, network protocol header information and checksum into a data packet; The data packet is sent to the vehicle-mounted time series database server.

4. The data communication method based on shared memory according to claim 1, characterized in that: The vehicle-mounted time series database client includes an SDK, and when the vehicle-mounted time series database client needs to write service data, the service data is serialized into the pre-allocated physical memory block, including: The vehicle-mounted time series database client maps the at least one physical memory block to a virtual address space corresponding to the vehicle-mounted time series database client; When the vehicle-mounted time series database client needs to write business data, the data to be written cached in the SDK is serialized into the physical memory block corresponding to the virtual address space.

5. The data communication method based on shared memory according to claim 1, characterized in that: The vehicle-mounted time series database client pre-allocates at least one physical memory block as a data buffer through memory mapping, and establishes a corresponding relationship between each memory block and a data identifier, including: The vehicle-mounted time series database client uses a memory mapping function to pre-allocate a physical memory block of a specified size; The vehicle-mounted time series database client allocates a unique data identifier for each allocated physical memory block; the data identifier is used to identify the memory block address corresponding to each allocated physical memory block; The vehicle-mounted time series database client establishes and stores a mapping table between the data identifier and the memory block address.

6. A data communication method based on shared memory, characterized in that: Applied to the vehicle-mounted time series database server, the communication method includes: The vehicle-mounted time series database server receives the data identifier and the size information of the serialized data sent from the vehicle-mounted time series database client; the serialized data is serialized by the vehicle-mounted time series database client according to the business data and written into the physical memory block corresponding to the data identifier; the physical memory block is pre-allocated by the vehicle-mounted time series database client using memory mapping; The vehicle-mounted time series database server reads and processes the data from the corresponding physical memory block according to the data identifier and the size information of the serialized data.

7. The data communication method based on shared memory according to claim 6, characterized in that: The vehicle-mounted time series database server includes a user space and a kernel space. The vehicle-mounted time series database server receives the data identifier and the size information of the serialized data sent from the vehicle-mounted time series database client, including: In response to receiving the data identifier and the size information of the serialized data sent by the on-board time series database client, the on-board time series database server kernel space copies the data identifier and the size information of the serialized data to the socket buffer of the on-board time series database server kernel space, and transmits the data identifier and the size information of the serialized data to the on-board time series database server user space.

8. The shared memory-based data communication method according to claim 7, characterized in that: The user space includes a virtual address space of an on-board time series database server and a memory buffer of an on-board time series database server. The on-board time series database server reads data from a corresponding physical memory block and processes the data according to the data identifier and the size information of the serialized data, including: The vehicle-mounted time series database server uses memory mapping to map the physical memory pre-allocated by the vehicle-mounted time series database client to its own virtual address space according to the data identifier to obtain serialized data; The vehicle-mounted time series database server deserializes the serialized data according to the size information of the serialized data to obtain business data.

9. A data communication device based on shared memory, characterized in that: Applied to a vehicle-mounted time series database client, the communication device comprises: A memory mapping module, used for the vehicle-mounted time series database client to pre-allocate at least one physical memory block as a data buffer through memory mapping, and establish a corresponding relationship between each memory block and a data identifier; A writing module, used for serializing the business data into the pre-allocated physical memory block when the vehicle-mounted time series database client needs to write business data, and determining the data identifier corresponding to the memory block and the size information of the serialized data; The sending module is used for the vehicle-mounted time series database client to send the data identifier and the size information of the serialized data to the vehicle-mounted time series database server to instruct the vehicle-mounted time series database server to read the data from the corresponding physical memory block and process it.

10. A data communication device based on shared memory, characterized in that: Applied to the vehicle-mounted time series database server, the communication device includes: A receiving module is used for the vehicle-mounted time series database server to receive the data identifier and the size information of the serialized data sent from the vehicle-mounted time series database client; the serialized data is written into the physical memory block corresponding to the data identifier by the vehicle-mounted time series database client according to the business data serialization; the physical memory block is pre-allocated by the vehicle-mounted time series database client using memory mapping; The reading module is used for the vehicle-mounted time series database server to read and process data from the corresponding physical memory block according to the data identifier and the size information of the serialized data.

Citation Information

Cited By

  • Vehicle-mounted data communication method and system and vehicle

    CN118802957A