Data transmission method, computer equipment and storage medium
By using a shared memory mechanism on the same computer device, virtual instances can directly write and read data in shared memory, solving the problem of low data transfer efficiency between virtual instances and achieving more efficient data transfer.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-22
- Publication Date
- 2026-03-10
AI Technical Summary
In fields such as cloud computing and autonomous driving, data transmission efficiency between different virtual instances on the same computer device is low, and existing methods for transmitting notification messages via network connections suffer from high latency and overhead.
Using a shared memory mechanism, virtual instances directly write data and notification messages through shared memory, while second virtual instances actively read notification messages from shared memory to obtain the data to be read, thus utilizing shared memory for data transmission.
It reduces data transmission latency and communication costs between virtual instances, and improves data transmission efficiency.
Smart Images

Figure CN121636038A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of network, and particularly relates to a data transmission method, a computer device and a storage medium. BACKGROUND
[0002] In the fields of cloud computing and intelligent driving, a plurality of virtual instances can be deployed on a computer device to provide services for users. The plurality of virtual instances are isolated from each other, which improves resource utilization while ensuring security.
[0003] At present, communication between different virtual instances on the same computer device has become a common practice. In particular, data transmission between virtual instances is very common, and the amount of data transmitted is increasingly large. In this case, how to realize efficient data transmission between virtual instances is a problem to be solved. SUMMARY
[0004] The present application provides a data transmission method, a computer device and a storage medium, which are used to realize efficient data transmission between different virtual instances on the same computer device.
[0005] To achieve the above object, the present application adopts the following technical solutions:
[0006] In a first aspect, a data transmission method is provided, which is applied to a computer device, the computer device comprising a first virtual instance, a second virtual instance and a shared memory accessible by the first virtual instance and the second virtual instance, and the method comprises: the first virtual instance writing first data to be transmitted and a notification message into the shared memory, the notification message being used to notify the second virtual instance that there is data to be read; and the second virtual instance reading the notification message from the shared memory and reading the first data based on the notification message.
[0007] In the present application, the first virtual instance not only writes the first data to be transmitted into the shared memory accessible by the second virtual instance, but also writes the notification message used to notify the second virtual instance that there is data to be read into the shared memory. On this basis, the second virtual instance can actively read the notification message from the shared memory, determine that there is data to be read after reading the notification message, and then read the first data based on the notification message. As can be seen, in the present application, the virtual instance as a sending end can use the shared memory to deliver the notification message to the virtual instance as a receiving end, so as to timely notify the receiving end to read the transmitted data from the shared memory, and efficient data transmission between different virtual instances on the same computer device is realized.
[0008] Optionally, after writing the first data into the shared memory, the first virtual instance can also write first metadata into the shared memory, the first metadata being used to indicate a storage address of the first data. By writing the first metadata into the shared memory, the second virtual instance can quickly read the first data through the first metadata after perceiving the notification message.
[0009] Optionally, the second virtual instance reads the notification message from the shared memory, and the implementation process of reading the first data based on the notification message can include: the second virtual instance reads the notification message from the shared memory based on a preset reading period; the second virtual instance reads N metadata from the shared memory, the N being the number of the read notification messages, and the N metadata including the first metadata; and the second virtual instance reads the first data from the shared memory based on the storage address of the first data indicated by the first metadata.
[0010] In the present application, the second virtual instance can poll the shared memory according to a preset reading period to read the notification message, and batch process the read notification message, so that on the one hand, the second virtual instance can perceive in time whether there is a notification message to be processed, and on the other hand, through batch processing, the processing overhead of the notification message can be reduced.
[0011] Optionally, the shared memory includes a first queue, and the implementation process of the first virtual instance writing the notification message into the shared memory can include: the first virtual instance writes the notification message into a tail of the first queue.
[0012] Optionally, the first queue is a ring queue, the first queue includes a plurality of queue positions, and the first queue corresponds to a write start pointer, and the implementation process of the first virtual instance writing the notification message into the tail of the first queue can include: the first virtual instance writes the notification message into a first queue position pointed to by the write start pointer in the plurality of queue positions, and updates the write start pointer, the updated write start pointer pointing to a next queue position of the first queue position.
[0013] In the present application, the first virtual instance can locate the writing position of the notification message through the write start pointer of the first queue, so as to quickly write the notification message in the first queue.
[0014] Optionally, the first queue further corresponds to a read start pointer, and the process that the second virtual instance reads the notification message from the shared memory can include: the second virtual instance reads the notification message between the queue position pointed to by the read start pointer and the queue position pointed to by the write start pointer; and the second virtual instance deletes the notification message at each read queue position and updates the read start pointer, and the updated read start pointer and the write start pointer point to the same queue position.
[0015] In the present application, the first queue not only has the write start pointer, but also has the read start pointer, which is used to indicate the next queue position of the last notification message read by the second virtual instance last time, and the notification message between the read start pointer and the write start pointer is the notification message not processed by the second virtual instance. Based on this, the second virtual instance can use the read start pointer and the write start pointer to read the unprocessed notification message in batches, and then respond to these notification messages in batches to read the corresponding data.
[0016] Optionally, the shared memory includes a second queue, and the second queue is used to store metadata of data to be transmitted, and the process that the first virtual instance writes the first metadata to the shared memory can include: the first virtual instance writes the first metadata to the tail of the second queue.
[0017] Optionally, the process that the second virtual instance reads N metadata from the shared memory can include: the second virtual instance reads the N metadata from the tail of the second queue to the head of the second queue in sequence.
[0018] In the present application, the position pointed to by the read start pointer is the next queue position of the last notification message read by the second virtual instance last time. That is, for the second virtual instance, the N notification messages from the read start pointer to the write start pointer are newly added and not read. On this basis, since the newly added metadata in the second queue is written from the tail, the N metadata obtained in sequence from the tail to the head is the metadata corresponding to the N notification messages read by the second virtual instance.
[0019] In a second aspect, a computer device is provided, comprising a first virtual instance, a second virtual instance, and a shared memory accessible by the first virtual instance and the second virtual instance; wherein the first virtual instance is configured to write, into the shared memory, first data to be transmitted and a notification message, the notification message being configured to notify the second virtual instance that there is data to be read; and the second virtual instance is configured to read the notification message from the shared memory, and read the first data based on the notification message.
[0020] Optionally, the first virtual instance is further configured to write, into the shared memory, first metadata, the first metadata being configured to indicate a storage address of the first data.
[0021] Optionally, the second virtual instance is specifically configured to read the notification message from the shared memory based on a preset reading period; read N metadata from the shared memory, the N being a number of read notification messages, the N metadata comprising the first metadata; and read the first data from the shared memory based on the storage address of the first data indicated by the first metadata.
[0022] Optionally, the shared memory comprises a first queue, and the first virtual instance is specifically configured to write the notification message into a tail of the first queue.
[0023] Optionally, the first queue is a ring queue, the first queue comprises a plurality of queue positions, and the first queue corresponds to a write start pointer, and the first virtual instance is specifically configured to write the notification message into a first queue position pointed to by the write start pointer among the plurality of queue positions, and update the write start pointer, the updated write start pointer pointing to a next queue position of the first queue position.
[0024] Optionally, the first queue further corresponds to a read start pointer, and the second virtual instance is specifically configured to read the notification messages between a queue position pointed to by the read start pointer and a queue position pointed to by the write start pointer; delete the notification messages at each read queue position, and update the read start pointer, the updated read start pointer and the write start pointer pointing to a same queue position.
[0025] Optionally, the shared memory comprises a second queue, the second queue being configured to store metadata of data to be transmitted, and the first virtual instance is specifically configured to write the first metadata into a tail of the second queue.
[0026] Optionally, the second virtual instance is specifically configured to read the N metadata in an order from a tail of the second queue to a head of the second queue.
[0027] Thirdly, a data transmission apparatus is provided, comprising a first virtual instance and a second virtual instance, the data transmission apparatus operating on the same computer device, and the computer device including shared memory accessible to both the first and second virtual instances. Each of the first and second virtual instances includes at least one module for executing the data transmission method described in the first aspect.
[0028] Optionally, the data transmission device may further include a virtual machine manager that can allocate shared memory for the first virtual instance and the second virtual instance.
[0029] Fourthly, a computer-readable storage medium is provided, wherein instructions are stored therein, which, when executed on a computer device, cause the computer device to perform the data transmission method described in the first aspect.
[0030] Fifthly, a computer program product containing instructions is provided, which, when run on a computer device, causes the computer device to perform the data transmission method described in the first aspect.
[0031] The technical effects achieved by the second to fifth aspects mentioned above are similar to those achieved by the corresponding technical means in the first aspect, and will not be repeated here. Attached Figure Description
[0032] Figure 1 A schematic diagram of the structure of a computer device to which the data transmission method provided in the embodiments of this application is applicable;
[0033] Figure 2 A flowchart illustrating a data transmission method provided in an embodiment of this application;
[0034] Figure 3 A schematic diagram of a first queue provided for an embodiment of this application;
[0035] Figure 4 This is a schematic diagram illustrating reading notification messages from a first queue and deleting notification messages, provided as an embodiment of this application.
[0036] Figure 5 A schematic diagram illustrating the relationship between data in a first memory space, notification messages in a first queue, and metadata in a second queue, provided for embodiments of this application;
[0037] Figure 6 This is a schematic diagram illustrating data transfer between virtual instances on the same computer device using shared memory, provided as an embodiment of this application.
[0038] Figure 7 This is a schematic diagram of a data transmission device provided in an embodiment of this application. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0040] Before providing a detailed explanation of the embodiments of this application, let's first introduce the application scenarios involved in the embodiments of this application.
[0041] Currently, in technologies such as cloud computing, autonomous driving, and virtualized networks, multiple virtual instances can be deployed on a single computer device to provide services to users, thereby improving the utilization of hardware resources. In some scenarios, there may be data transfer requirements between multiple virtual instances deployed on the same computer device.
[0042] For example, in the cloud computing field, multiple virtual instances can be deployed on the same physical machine, and some of these virtual instances may belong to the same tenant. In this case, these different virtual instances belonging to the same tenant may need to transfer business data to each other.
[0043] For example, in the field of intelligent driving, as automotive electronic and electrical architecture evolves from a distributed architecture to a centralized architecture, various services previously provided by multiple electronic control units can now be implemented by integrating multiple functional modules providing these services into a single onboard computer device. However, because different functional modules provide services with different priorities, the requirements for their underlying operating systems also differ. For instance, automotive instrument clusters require high real-time performance, high reliability, and strong security, while in-vehicle entertainment systems primarily pursue diverse applications and services. Therefore, automotive instrument clusters and in-vehicle entertainment systems typically use different operating systems. Based on this, to enable different types of operating systems to run on the same onboard computer device, multiple virtual instances can be deployed on that device. Each virtual instance can then run a different operating system and corresponding applications to provide different services.
[0044] When multiple virtual instances are deployed in an in-vehicle computer device, there may be data transmission requirements between different virtual instances. For example, taking a first virtual instance for implementing advanced driver assistance system (ADAS) functions and a second virtual instance for implementing in-vehicle entertainment system functions as an example, after receiving real-time sensor data collected by the vehicle's sensors, the first virtual instance may need to transmit the sensor data or the processing results obtained after processing the sensor data to the second virtual instance so that the application running on the second virtual instance can display the sensor data or the corresponding processing results to the user.
[0045] Currently, when two virtual instances on the same computer device have data to be transferred, the host operating system of that computer device can allocate shared memory for these two virtual instances. Based on this, the source virtual instance, acting as the sender, can write the data to be transferred into the shared memory and send a notification message to the destination virtual instance through a network connection (such as a Transmission Control Protocol, TCP) established between the source and destination virtual instances, notifying the destination virtual instance to read the data from the shared memory. However, sending notification messages through the network connection between virtual instances has high latency and significant overhead, resulting in inefficient data transfer between virtual instances. Therefore, this application provides a method for data transfer between different virtual instances deployed on the same computer device. In this method, the first virtual instance not only writes the first data to be transferred into shared memory accessible to the second virtual instance, but also writes a notification message to notify the second virtual instance that data is to be read into the shared memory. Based on this, the second virtual instance can actively read the notification message from the shared memory, determine the data to be read, and then read the first data based on the notification message. Therefore, in this embodiment of the application, the source virtual instance as the sender can use shared memory to transmit notification messages to the destination virtual instance as the receiver, thereby notifying the destination virtual instance to read the transmitted data from the shared memory. Compared with transmitting notification messages through network connections between virtual instances, the latency and communication cost are both lower, which improves the data transmission efficiency between different virtual instances on the same computer device.
[0046] The data transmission method provided in this application is mainly applied to computer devices with multiple virtual instances deployed. Figure 1 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Figure 1 As shown, the computer device 10 may include a hardware layer and a software layer.
[0047] The hardware layer of the computer device 10 may include at least one processor 110, a communication bus 111, memory 112, a disk 113, and at least one communication interface 114. It should be noted that... Figure 1 The hardware layer structure shown does not constitute a limitation on the computer device. A computer device may include more or fewer components than shown, or combine certain components, or have different component arrangements. This application's embodiments do not limit this. The following, in conjunction with... Figure 1 A detailed description of each component of the hardware layer of computer device 10 is provided below:
[0048] Processor 110 is the control center of the computer device 10. It can be a single processor or a collective term for multiple processing elements. For example, processor 110 can be a general-purpose central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits used to control the execution of programs according to the present application, such as one or more digital signal processors (DSPs), or one or more field-programmable gate arrays (FPGAs). Processor 110 can perform various functions of the computer device by running or executing software programs stored in memory 112 and by calling data stored in memory 112. For example, in the various embodiments described below, the actions of the computer device can be executed by the processor of the computer device calling data in memory.
[0049] As one embodiment, processor 110 may include one or more CPUs.
[0050] As one embodiment, a computer device may include multiple processors, each of which may be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. Here, a processor may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).
[0051] The communication bus 111 may include a path for transmitting information between the aforementioned components. This communication bus 111 may be an industry standard architecture (ISA) bus, a peripheral component interconnect (PCI) bus, or an extended industry standard architecture (EISA) bus, etc. This bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 1 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0052] Memory 112 refers to the internal memory that directly exchanges data with processor 110. It can read and write data at any time at high speed, serving as temporary data storage for the operating system or other running programs. Memory 112 can include at least two types of memory, such as read-only memory (ROM) or other types of static storage devices that can store static information and instructions, random access memory (RAM) or other types of dynamic storage devices that can store information and instructions. Memory 112 can exist independently and be connected to processor 110 via communication bus 111. Memory 112 can also be integrated with processor 110. Memory 112 is used to store software programs that execute the schemes provided in the embodiments of this application, and its execution is controlled by processor 110.
[0053] Disk 113 is used to provide storage resources, such as storing data. It can be a hard disk or other types of storage media, such as a solid-state drive or a shingled magnetic recording hard disk.
[0054] Communication interface 114 is used for communicating with other devices or communication networks. Communication interface 114 may include a receiving unit to implement receiving functions and a sending unit to implement sending functions. For example, the communication interface 114 may be a network interface card (NIC).
[0055] As one embodiment, the computer device 10 may further include output devices and input devices. The output device communicates with the processor 110 and can display information in various ways. For example, the output device may be a liquid crystal display (LCD), a light-emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector, etc. The input device communicates with the processor 110 and can receive input in various ways. For example, the input device may be a mouse, keyboard, touchscreen device, or sensing device, etc.
[0056] The software layer of computer device 10 may include a host operating system (host OS) 115 installed and running on computer device 10, and multiple virtual instances 116. Figure 1 The image shows two virtual instances deployed on computer device 10.
[0057] The host operating system 115 may include a virtual machine monitor (VMM), also known as a hypervisor. The VMM, acting as the management layer, manages and allocates the hardware resources of the computer device 10. It utilizes virtualization technologies such as compute virtualization, network virtualization, and storage virtualization to present a virtual hardware platform for multiple virtual instances, and to schedule and isolate these virtual instances.
[0058] Virtual instance 116 can be a virtual machine, an Elastic Compute Service (ECS) instance, a cloud server, a container, a bare metal server, etc.
[0059] For example, taking virtual instance 116 as a virtual machine, virtual instance 116 may include a guest operating system (guest OS) 1161 and one or more applications 1162 deployed on guest operating system 1161. The types of guest OS running in different virtual instances may be the same or different, and the applications running on different virtual instances may be different or the same.
[0060] In this embodiment, when there is a data transfer requirement between two virtual instances 116, the VMM can allocate shared memory for these two virtual instances from the memory 112 of the computer device 10. Based on this, the two virtual instances can utilize the data transfer method provided in this embodiment to achieve efficient data transfer through this shared memory.
[0061] The data transmission method provided in the embodiments of this application will be described in detail below.
[0062] Figure 2 This is a flowchart illustrating a data transmission method provided in an embodiment of this application. This method can be applied to the computer devices described above; see [link to relevant documentation]. Figure 2 The method includes the following steps:
[0063] S201: The first virtual instance writes the first data to be transmitted and a notification message to the shared memory. The notification message is used to notify the second virtual instance that there is data to be read.
[0064] In this embodiment of the application, before the first virtual instance and the second virtual instance transmit data, the VMM in the host operating system of the computer device can first allocate shared memory for the first virtual instance and the second virtual instance.
[0065] For example, when the first or second virtual instance first obtains data to be transmitted to the other end, it may send a memory allocation request to the VMM. The memory allocation request may carry the identifiers of the first and second virtual instances. After receiving the memory allocation request, the VMM allocates shared memory for the first and second virtual instances.
[0066] Optionally, after creating the first and second virtual instances, the VMM can also actively obtain the communication requirement information of the first and second virtual instances. If the communication requirement information indicates that there is a communication requirement between the first and second virtual instances, the VMM can allocate shared memory for the first and second virtual instances. This communication requirement information can be communication requirement information generated by the virtual instance based on its own application, or it can be communication requirement information configured by the user.
[0067] In one possible implementation, the VMM can virtualize a peripheral component interconnect (PCI) device, use the memory of the virtual PCI device as shared memory, and provide the address information of the shared memory to the first virtual instance and the second virtual instance to achieve the allocation of shared memory.
[0068] In another possible implementation, the VMM can also use a free memory space in the host operating system's memory as shared memory and provide the address information of this shared memory to the first virtual instance and the second virtual instance to achieve shared memory allocation.
[0069] After the VMM allocates shared memory for the first virtual instance and the second virtual instance, for the first data obtained by the first virtual instance and to be transferred to the second virtual instance, the first virtual instance can write the first data into the first memory space of the shared memory. Then, the first virtual instance can write a notification message into the second memory space of the shared memory to notify the second virtual instance of the existence of data to be read. Here, the first memory space is used to store the data to be transferred, and the second memory space is used to store the notification message.
[0070] It should be noted that the second memory space is a contiguous memory space. This second memory space stores a first queue, which can be a circular queue including multiple queue positions, and the first queue has a write start pointer. The queue position indicated by the write start pointer is the position following the queue position of the last notification message in the first queue; in other words, the queue position indicated by the write start pointer is the position where a notification message is about to be written. Based on this, after the first virtual instance writes the first data to the first memory space, it can write a notification message at the first queue position indicated by the write start pointer of the first queue. Afterwards, the first virtual instance can update the write start pointer, and the updated write start pointer will point to the next queue position.
[0071] In some embodiments, the first queue can be a queue specifically used to store notification messages sent to the second virtual instance. These notification messages are those used to notify the second virtual instance to read data. In this case, the first queue can be created by the first virtual instance, and each queue position in the first queue can refer to a single bit, with each bit initially set to a first value. Therefore, when the write start pointer points to the first bit, the first virtual instance can modify the first value of the first bit to a second value. At this time, the second value of the first bit is the notification message written by the first virtual instance to the first queue. Specifically, the first value can be 0 and the second value can be 1; or the first value can be 1 and the second value can be 0.
[0072] In other embodiments, the first queue may include notification messages destined for either the second virtual instance or the first virtual instance. In this case, the first queue may be created by either the first or the second virtual instance, and each queue position in the first queue is used to store a notification message, which includes the identifier of the destination virtual instance. Based on this, after the first virtual instance writes first data to the first memory space, it can write a notification message at the first queue position pointed to by the write start pointer. Since this notification message is destined for the second virtual instance, that is, the destination virtual instance of the notification message is the second virtual instance, the notification message may include the identifier of the second virtual instance.
[0073] Figure 3 This is a schematic diagram illustrating a first queue according to an embodiment of this application. Figure 3 As shown, the first queue includes n queue positions, where queue position A, pointed to by the write start pointer Ws, is the next queue position after the last notification message m0. Based on this, after the first virtual instance writes the first data to the first memory space, it can write the notification message m1 at queue position A indicated by the write start pointer Ws. Afterwards, the first virtual instance can update the write start pointer Ws, so that the updated write start pointer Ws points to the next queue position after queue position A, i.e., queue position B.
[0074] It should be noted that since the write start pointer of the first queue points to the position after the last notification message in the first queue, which is the position where the notification message is about to be written, in other words, the write start pointer actually points to the tail position of the first queue. Therefore, in this embodiment, the write start pointer can also be called the tail pointer.
[0075] Optionally, in some possible implementations, the shared memory also includes a third memory space for storing metadata of the data. After writing the first data to the free space in the first memory space, the first virtual instance can also generate metadata of the first data, i.e., first metadata. Then, the first virtual instance can write this first metadata to the third memory space. This first metadata can be used to indicate the storage address of the first data in the shared memory. For example, the first metadata may include the starting storage address of the first data in the first memory space and the length of the first data. In this way, a subsequent second virtual instance can obtain the storage address of the data it wants to read by reading the metadata in the third memory space, and then read the data based on that storage address.
[0076] For example, the third memory space is also a contiguous memory space, and this third memory space may store a second queue created by the first virtual instance. This second queue is used to store metadata of the data that the first virtual instance wants to transfer to the second virtual instance. After generating the first metadata, the first virtual instance can write the first metadata to the tail of the second queue.
[0077] S202: The second virtual instance reads the notification message from the shared memory and reads the first data based on the read notification message.
[0078] In the first implementation, the second virtual instance can monitor in real time whether there are any newly added notification messages in the second memory space of the shared memory. Whenever a newly added notification message is detected in the second memory space, the second virtual instance can read the newly added notification message and read the first data based on the read newly added notification message.
[0079] As described above, the second memory space can store the first queue, and the first queue has a write start pointer. Based on this, the second virtual instance can monitor in real time whether the write start pointer of the first queue is updated. Whenever an update of the write start pointer is detected, the second virtual instance can determine that there are newly added notification messages in the first queue. At this time, the second virtual instance can read the notification messages between the write start pointers before and after the update.
[0080] After reading the notification message, the second virtual instance can use different methods to obtain the first data based on the notification message, depending on the type of notification message contained in the first queue.
[0081] Scenario 1: If the first queue is a queue specifically used to store notification messages sent to the second virtual instance, after reading the notification messages between the write start pointer before and after the update, the second virtual instance can calculate the number N of notification messages read. Then, based on the number N of notification messages read, it can obtain N metadata, and then read the first data based on the obtained N metadata.
[0082] For example, as described above, the third memory space of the shared memory can store a second queue, which is used to store metadata of data to be transferred to the second virtual instance. Furthermore, when the first virtual instance writes data to the first memory space, it can write the metadata of the data to the tail of the second queue. Based on this, in this embodiment, after determining the number N of notification messages read, the second virtual instance can obtain N metadata entries starting from the tail of the second queue, in order from the tail to the head. Here, N is an integer greater than or equal to 1.
[0083] It should be noted that since the first queue is specifically used to store notification messages sent to the second virtual instance, and the first virtual instance writes a notification message to the tail of the first queue whenever it writes data to the first memory space, the number of newly added notification messages in the first queue is the same as the number of newly added metadata in the second queue. Furthermore, since all newly added metadata in the second queue is written from the tail, the N metadata items retrieved sequentially from tail to head are the metadata corresponding to the newly added notification messages in the first queue. In summary, when the newly added notification messages in the first queue include the notification message corresponding to the first data, the N metadata items retrieved will include the metadata of the first data, i.e., the first metadata.
[0084] Optionally, in some possible implementations, the second queue may also have a read start pointer and a write start pointer. The read start pointer of the second queue can be used to indicate the queue position of the next metadata after the last metadata most recently read by the second virtual instance before the current time; that is, the read start pointer can be used to indicate the metadata about to be read in the second queue. The write start pointer of the second queue is used to indicate the queue position following the queue position of the last metadata in the second queue. Based on this, after the second virtual instance reads the notification message from the first queue, it can directly read the metadata at each queue position between the read start pointer and the write start pointer of the second queue. After reading the metadata, the second virtual instance can update the read start pointer of the second queue, and the updated read start pointer and the write start pointer of the second queue will point to the same queue position. Furthermore, the method for updating the write start pointer of the second queue can refer to the method for updating the write start pointer of the first queue, and will not be repeated here.
[0085] Optionally, after the second virtual instance reads the metadata at each queue position between the read start pointer and the write start pointer of the second queue, it can also delete the metadata at these queue positions and then update the read start pointer of the second queue.
[0086] After reading N metadata, the second virtual instance can read the data stored at the N storage addresses indicated by the N metadata.
[0087] For example, taking the first metadata among N metadata as an example, the first metadata may include the starting storage address and length of the first data. Based on this, the second virtual instance can start from the starting storage address in the shared memory and read data of the corresponding length. The data read is the first data.
[0088] Furthermore, after reading the notification message, the second virtual instance can also delete the notification message at each queue position between the write start pointer before and after the update. For example, if each queue position is one bit, after reading the second value at each of the aforementioned bits, the second virtual instance can update the second value at each of the aforementioned bits to the first value, thereby completing the deletion of the notification message.
[0089] Scenario 2: If the first queue can store notification messages destined for both the second and first virtual instances, and each notification message in the first queue includes the identifier of the destination virtual instance, then after reading the notification messages at each queue position between the write start pointer before and after the update, the second virtual instance can determine whether each read notification message includes the identifier of the second virtual instance, that is, whether the read notification messages contain notification messages destined for the second virtual instance. If the read notification messages contain notification messages destined for the second virtual instance, the second virtual instance can determine the number N of notification messages destined for the second virtual instance. Then, the second virtual instance can read N metadata and read the first data based on these N metadata. The implementation method of the second virtual instance reading N metadata and reading the first data based on the N metadata can be referred to the relevant description in Scenario 1 above, and will not be repeated here.
[0090] In addition, in this case, after the second virtual instance determines that the notification message it reads is destined for itself, it can also delete the notification message from the first queue.
[0091] In the second implementation, the second virtual instance can use a user-mode polling mechanism to read notification messages in batches. That is, the second virtual instance can read notification messages in the second memory space of shared memory in batches based on a preset reading period, and read the first data based on the batch-read notification messages.
[0092] For example, the first queue in the second memory space can have not only a write start pointer but also a read start pointer corresponding to the second virtual instance. The read start pointer corresponding to the second virtual instance can point to the queue position following the queue position of the last notification message most recently read by the second virtual instance. It is worth noting that if the first queue is specifically used to store notification messages sent to the second virtual instance, then the first queue has one read start pointer, which is the read start pointer corresponding to the second virtual instance. If the first queue can store notification messages sent to both the second and first virtual instances, then the first queue can have two read start pointers, one for the first virtual instance and the other for the second virtual instance.
[0093] Based on this, when the second virtual instance determines the time to read the notification message based on the length of the preset reading period and the time of the most recent reading notification message, it can read the notification message between the queue position pointed to by the read start pointer and the queue position pointed to by the write start pointer of the second virtual instance in the first queue, and update the read start pointer of the second virtual instance. The updated read start pointer and the write start pointer point to the same queue position, and the queue position pointed to by the updated read start pointer is the starting queue position for the next batch reading of notification messages by the second virtual instance.
[0094] After receiving notification messages in batches, the second virtual instance reads the first data in different ways based on the notification messages received, depending on the specific notification messages included in the first queue.
[0095] Scenario 1: If the first queue is a queue specifically used to store notification messages sent to the second virtual instance, then after the second virtual instance reads the notification messages between the read start pointer and the write start pointer of the second virtual instance in the first queue in batches, it can determine the number N of notification messages read. Then, it reads N metadata and reads the first data based on the N metadata.
[0096] The third memory space within the shared memory can store a second queue, which is used to store metadata of data to be transferred to the second virtual instance. Furthermore, when the first virtual instance writes data to the first memory space, it can write the data's metadata to the tail of the second queue. Based on this, in this embodiment, after determining the number N of notification messages read, the second virtual instance can retrieve N metadata entries starting from the tail of the second queue, proceeding from the tail to the head. Here, N is an integer greater than or equal to 1.
[0097] It should be noted that the read start pointer of the second virtual instance points to the next queue position after the queue position of the last notification message most recently read by the second virtual instance. In other words, for the second virtual instance, the N notification messages from this read start pointer to the write start pointer are newly added notification messages that have not yet been read. Since the first virtual instance writes a notification message to the tail of the first queue and the metadata of the data to the tail of the second queue whenever it writes data to the first memory space, it is evident that the number of unread metadata items in the second queue is also N. Furthermore, since the newly added metadata in the second queue is also written from the tail, the N metadata items obtained sequentially from the tail to the head are the metadata corresponding to the N notification messages read by the second virtual instance. In summary, when the N notification messages read include the notification message corresponding to the first data, the N metadata items obtained will include the metadata of the first data, i.e., the first metadata.
[0098] After obtaining N metadata, the second virtual instance can refer to the method described above to read the first data based on the N metadata.
[0099] Furthermore, if the first queue is specifically used to store notification messages sent to the second virtual instance, after the second virtual instance reads a batch of notification messages between its read start pointer and write start pointer in the first queue, it can delete these notification messages and then update its read start pointer. For example, if the notification messages between the second virtual instance's read start pointer and write start pointer are the second values at each queue position between the read start pointer and write start pointer, the second virtual instance can modify the second values at each queue position to the first value, thereby completing the deletion of each notification message.
[0100] For example, Figure 4 This is a schematic diagram illustrating the reading and deleting of notification messages from a first queue, as shown in an embodiment of this application. The first queue is specifically used to store notification messages sent to the second virtual instance, and each queue position is represented by a bit. A value of 1 indicates a notification message, and a value of 0 indicates no notification message at that queue position. Based on this, as... Figure 4As shown in the left figure, the read start pointer of the first queue is Rs, and the write start pointer is Ws. Rs points to bit C, and Ws points to bit B. When the time to read the notification message arrives, the second virtual instance can sequentially read the notification message from bit C pointed to by Rs, until it reads the bit preceding bit B indicated by Ws, i.e., bit A. After reading the notification message from bit C to bit B, as... Figure 4 As shown in the right figure, the second virtual instance can modify the second value of each bit between bit C and bit B to the first value and update Rs. The updated Rs points to bit C. That is, the bit pointed to by the updated Rs is the same bit pointed to by Ws.
[0101] exist Figure 4 In the first queue shown, the read start pointer points to the position of the first notification message to be read. Furthermore, all notification messages in the queue before the read start pointer have been deleted. Therefore, the queue position pointed to by the read start pointer is actually the head position of the first queue. Thus, in this case, the read start pointer can also be called the head pointer of the first queue. Additionally, when the read start pointer and write start pointer point to the same queue position, it indicates that the current first queue does not contain any notification messages; that is, the first queue is empty.
[0102] Figure 5 This is a schematic diagram illustrating the relationship between data in a first memory space, notification messages in a first queue, and metadata in a second queue, as provided in an embodiment of this application. Initially, both the first and second queues are empty, and the write start pointer and read start pointer of the first queue both point to the same queue position. Based on this, see... Figure 5 In Figure (a), after the first virtual instance writes the first data D1 into the first memory space, it will write the corresponding metadata Meta1 to the second queue and write the notification message m1 to the first queue. The read start pointer Rs of the first queue remains unchanged, while the write start pointer Ws of the first queue is updated. See then... Figure 5 In diagram (b), the first virtual instance writes data D2 into the first memory space, writes the corresponding metadata Meta2 into the second queue, writes notification message m2 into the first queue, keeps the Rs of the first queue unchanged, and updates the Ws of the first queue. See then... Figure 5In diagram (c), the first virtual instance writes data D3 into the first memory space and writes the corresponding metadata Meta3 into the second queue. It also writes notification message m3 into the first queue, keeping Rs in the first queue unchanged and updating Ws in the first queue. After the first virtual instance writes m3, the second virtual instance reaches the time to read notification messages. At this time, the second virtual instance reads three notification messages m1, m2, and m3 from Rs to Ws in the first queue. After reading, it deletes these three notification messages from the first queue and updates Rs. The updated Rs and Ws point to the same location, as shown below. Figure 5 As shown in Figure (d), the second virtual instance learns from the three notification messages it receives that it needs to read three metadata items. In this case, the second virtual instance starts from the tail of the second queue and reads the three metadata items Meta1, Meta2, and Meta3 in sequence from the tail to the head. Based on these three metadata items, the second virtual instance can read D1, D2, and D3.
[0103] Scenario 2: If the first queue can store notification messages destined for both the second and first virtual instances, and each notification message in the first queue includes the identifier of the destination virtual instance, then after batch reading the notification messages between the read start pointer and write start pointer of the second virtual instance in the first queue, the second virtual instance can search for a notification message containing the identifier of the second virtual instance from at least one of the read notification messages. That is, it can search for a notification message destined for the second virtual instance. If a notification message destined for the second virtual instance is found, the second virtual instance can determine the number N of notification messages destined for the second virtual instance. Then, the second virtual instance can read N metadata using the method described above and read the first data based on these N metadata.
[0104] It should be noted that, in this case, after determining the notification message to be sent to the second virtual instance, the second virtual instance can also delete the notification message to be sent to the second virtual instance that is located between the read start pointer and the write start pointer of the second virtual instance in the first queue.
[0105] Based on the data transmission method described in the above embodiments, this application also illustrates a schematic diagram of data transmission between virtual instances on the same computer device using shared memory. See also Figure 6The host operating system 60 in the computer device allocates shared memory 63 for virtual machines 61 and 62. Within shared memory 63, a first memory space 631 stores data to be transmitted, a second memory space 632 includes a first queue PQ for storing notification messages sent to virtual machine 62, and a third memory space 633 includes a second queue MQ for storing metadata of the data to be sent to virtual machine 62. After virtual machine 61 receives data to be sent to virtual machine 62, it can sequentially execute the following steps: 1. Virtual machine 61 writes the data to be transmitted to virtual machine 62 into the first memory space 631; 2. Virtual machine 61 writes the metadata of the data into MQ; 3. Virtual machine 61 writes notification messages into PQ; 4. Virtual machine 62 reads N notification messages from PQ; 5. Virtual machine 62 reads N metadata from MQ; 6. Virtual machine 62 reads data from the first memory space 631 based on the N metadata.
[0106] In this embodiment, the first virtual instance not only writes the first data to be transmitted to the shared memory accessible to the second virtual instance, but also writes a notification message to the second virtual instance to notify it that data is to be read. Based on this, the second virtual instance can actively read the notification message from the shared memory. After reading the notification message, it determines the data to be read and then reads the first data based on the notification message. Therefore, in this embodiment, the source virtual instance, as the sending end, can use shared memory to transmit a notification message to the destination virtual instance, as the receiving end, thereby notifying the destination virtual instance to read the transmitted data from the shared memory. Compared to transmitting notification messages through network connections between virtual instances, this method has lower latency and network overhead, improving data transmission efficiency between different virtual instances on the same computer device.
[0107] Furthermore, in this embodiment, the second virtual instance can employ a user-mode polling mechanism to detect whether there are notification messages in the shared memory, thereby promptly determining whether there is data to be read and improving data reading efficiency. Based on the polling mechanism, the second virtual instance can use batch processing to process one or more notification messages at a time, thus minimizing the processing overhead while ensuring data reading efficiency.
[0108] The data transmission apparatus provided in the embodiments of this application will now be described.
[0109] Figure 7 This is a schematic diagram of the structure of a data transmission device provided in an embodiment of this application. Figure 7As shown, the data transmission device 71 can be deployed in a computer device 70. The data transmission device 71 includes a first virtual instance 711 and a second virtual instance 712. The computer device 70 includes shared memory 72 allocated for the first virtual instance 711 and the second virtual instance 712.
[0110] The first virtual instance 711 is used to execute S201 in the aforementioned embodiment, and the second virtual instance 712 is used to execute S202 in the aforementioned embodiment.
[0111] Optionally, the first virtual instance 711 may include a data writing module 7111, a metadata writing module 7112, and a notification message writing module 7113. Specifically, the data writing module 7111 is used to write first data to be transferred to the second virtual instance 712 into the shared memory 72; the metadata writing module 7112 is used to write first metadata into the shared memory 72, which is metadata of the first data and indicates the storage address of the first data in the shared memory 72; and the notification message writing module 7113 is used to write notification messages into the shared memory 72.
[0112] Optionally, the shared memory 72 includes a second queue for storing metadata of data to be transferred to the second virtual instance 712. Based on this, the metadata writing module 7112 is specifically used to write first metadata to the tail of the second queue.
[0113] Optionally, the shared memory 72 includes a first queue, and the notification message writing module 7113 is specifically used to write notification messages to the tail of the first queue.
[0114] Optionally, the first queue is a circular queue, which includes multiple queue positions and has a corresponding write start pointer. The notification message writing module 7113 is specifically used to: write a notification message to the first queue position pointed to by the write start pointer among the multiple queue positions, and update the write start pointer, which points to the next queue position after the first queue position.
[0115] Optionally, the second virtual instance 712 may include a notification message reading module 7121, a metadata reading module 7122, and a data reading module 7123. The notification message reading module 7121 is used to read notification messages from the shared memory 72; the metadata reading module 7122 is used to read metadata based on the notification messages read by the notification message reading module 7121; and the data reading module 7123 is used to read data from the shared memory 72 based on the metadata read by the metadata reading module 7122.
[0116] Optionally, the notification message reading module 7121 is specifically used to read notification messages from the shared memory 72 according to a preset reading cycle; the metadata reading module 7122 is specifically used to read N metadata from the shared memory 72, where N is the number of notification messages read; and the data reading module 7123 is used to read first data from the shared memory based on the storage address indicated by the N metadata.
[0117] Optionally, if the shared memory 72 includes a first queue, the first queue also corresponds to a read start pointer. The notification message reading module 7121 is specifically used to: read the notification message between the queue position pointed to by the read start pointer and the queue position pointed to by the write start pointer; delete the notification message at each queue position read, and update the read start pointer, wherein the updated read start pointer and the write start pointer point to the same queue position.
[0118] Optionally, if the shared memory 72 includes a second queue, the metadata reading module 7122 is specifically used to read N metadata items starting from the tail of the second queue and in order from the tail to the head of the second queue.
[0119] In this embodiment, the first virtual instance not only writes the first data to be transmitted to the shared memory accessible to the second virtual instance, but also writes a notification message to the second virtual instance to notify it that data is to be read. Based on this, the second virtual instance can actively read the notification message from the shared memory. After reading the notification message, it determines the data to be read and then reads the first data based on the notification message. Therefore, in this embodiment, the source virtual instance, as the sending end, can use shared memory to transmit a notification message to the destination virtual instance, as the receiving end, thereby notifying the destination virtual instance to read the transmitted data from the shared memory. Compared to transmitting notification messages through network connections between virtual instances, this method has lower latency and network overhead, improving data transmission efficiency between different virtual instances on the same computer device.
[0120] It should be noted that the module division in the data transmission device provided in the above embodiments is illustrative and only represents one logical functional division. In actual implementation, other division methods may also be used. Furthermore, the functional modules in the various embodiments of this application can be integrated into a single processor, exist as separate physical entities, or be integrated into a single module. The integrated modules described above can be implemented in hardware or as software functional modules.
[0121] If the integrated module is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of this application, in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a router, switch, or other network device) or processor to execute all or part of the steps of the methods in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0122] Furthermore, the data transmission device and data transmission method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.
[0123] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., digital versatile discs (DVDs)), or semiconductor media (e.g., solid-state disks (SSDs)).
[0124] In the various embodiments of this application, unless otherwise specified or logically conflicting, the terminology and / or descriptions between different embodiments are consistent and can be referenced mutually. Technical features in different embodiments can be combined to form new embodiments based on their inherent logical relationships. In the embodiments of this application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the association relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone, where A and B can be singular or plural. In the textual description of the embodiments of this application, the character " / " generally indicates that the preceding and following related objects have an "or" relationship. In this application, "first," "second," and various numerical designations are only for ease of description and are not used to limit the scope of the embodiments of this application. For example, they are used to distinguish different messages, rather than to describe a specific order or sequence.
[0125] It is understood that the various numerical designations used in the embodiments of this application are merely for descriptive convenience and are not intended to limit the scope of the embodiments of this application. The order of the process numbers does not imply the order of execution; the execution order of each process should be determined by its function and internal logic.
[0126] Finally, it should be noted that the above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data transmission method, characterized by, Applied to a computer device comprising a first virtual instance, a second virtual instance and a shared memory accessible by the first virtual instance and the second virtual instance, the method comprises: The first virtual instance writes first data to be transmitted and a notification message into the shared memory, the notification message being used to notify the second virtual instance of data to be read; The second virtual instance reads the notification message from the shared memory, and reads the first data based on the notification message.
2. The method of claim 1, wherein, The method further comprises: The first virtual instance writes first metadata into the shared memory, the first metadata being used to indicate a storage address of the first data.
3. The method of claim 2, wherein, The second virtual instance reads the notification message from the shared memory based on a preset reading period, reads N metadata from the shared memory, the N being a number of the read notification messages, and the N metadata comprising the first metadata, and reads the first data from the shared memory based on the storage address of the first data indicated by the first metadata. The shared memory comprises a first queue, and the first virtual instance writes a notification message into the shared memory, comprising: The first virtual instance writes the notification message into a tail of the first queue. The first queue is a ring queue, the first queue comprises a plurality of queue positions, and the first queue corresponds to a write start pointer, and the first virtual instance writes the notification message into a first queue position pointed to by the write start pointer among the plurality of queue positions, and updates the write start pointer, the updated write start pointer pointing to a next queue position of the first queue position.
4. The method according to any one of claims 1 to 3, characterized in that, The first queue further corresponds to a read start pointer, and the second virtual instance reads the notification message from the shared memory, comprising: The second virtual instance reads the notification message between a queue position pointed to by the read start pointer and a queue position pointed to by the write start pointer; 5. The method of claim 4, wherein, The second virtual instance deletes the notification message at each read queue position, and updates the read start pointer, the updated read start pointer and the write start pointer pointing to a same queue position. The shared memory comprises a second queue, the second queue being used to store metadata of data to be transmitted, and the first virtual instance writes first metadata into the shared memory, comprising:
6. The method of claim 5, wherein, The first virtual instance writes the first metadata into a tail of the second queue. The second virtual instance reads N metadata from the shared memory, comprising: The second virtual instance reads the N metadata in an order from a tail of the second queue to a head of the second queue.
7. The method of claim 3, wherein, 8. The method of claim 7, wherein, 9. A computer device, comprising: The computer device comprises a first virtual instance, a second virtual instance, and a shared memory accessible by the first virtual instance and the second virtual instance; The first virtual instance is configured to write, into the shared memory, first data to be transmitted and a notification message, the notification message being configured to notify the second virtual instance of the data to be read; The second virtual instance is configured to read the notification message from the shared memory, and read the first data based on the notification message.
10. The computer device of claim 9, wherein, The first virtual instance is further configured to write, into the shared memory, first metadata, the first metadata being configured to indicate a storage address of the first data.
11. The computer device of claim 10, wherein, The second virtual instance is specifically configured to read the notification message from the shared memory based on a preset reading period, and read N metadata from the shared memory, the N being a number of read notification messages, the N metadata comprising the first metadata. The first data is read from the shared memory based on the storage address of the first data indicated by the first metadata.
12. The computer device of any of claims 9 to 11, wherein, The shared memory comprises a first queue, and the first virtual instance is specifically configured to write the notification message into a tail of the first queue.
13. The computer device of claim 12, wherein, The first queue is a ring queue, the first queue comprises a plurality of queue positions, and the first queue corresponds to a write start pointer, and the first virtual instance is specifically configured to write the notification message into a first queue position pointed to by the write start pointer among the plurality of queue positions, and update the write start pointer, the updated write start pointer pointing to a next queue position of the first queue position.
14. The computer device of claim 13, wherein, The first queue further corresponds to a read start pointer, and the second virtual instance is specifically configured to read the notification messages between a queue position pointed to by the read start pointer and a queue position pointed to by the write start pointer, delete the notification messages at each read queue position, and update the read start pointer, the updated read start pointer and the write start pointer pointing to a same queue position.
15. The computer device of claim 11, wherein, The shared memory comprises a second queue, the second queue being configured to store metadata of data to be transmitted, and the first virtual instance is specifically configured to write the first metadata into a tail of the second queue.
16. The computer device of claim 15, wherein, The second virtual instance is specifically configured to read the N metadata in an order from a tail of the second queue to a head of the second queue.
17. A computer-readable storage medium, characterized in that, The computer readable storage medium stores instructions, when the instructions are run on the computer device, causing the computer device to perform the data transmission method in any one of claims 1 to 8.
18. A computer program product comprising instructions, characterized in that, The instructions, when run on the computer device, cause the computer device to perform the data transmission method in any one of claims 1 to 8.