TECHNICAL FIELD

The present technology relates to the field of network communications, and in particular, to a communication method and apparatus in a cloud environment.

BACKGROUND

With rapid development of network virtualization technologies, increasingly more applications (APP) run on a virtual machine. To improve network communication efficiency, applications on hosts usually perform communication in a remote direct memory access (RDMA) manner. RDMA means that data is directly transferred to a memory of a computer using a network, and the data is quickly moved from one system to a memory of a remote system without imposing any impact on an operating system such that a delay problem of data processing at a host end during network transmission is resolved. When an application running on a virtual machine on a local host communicates with an application running on a virtual machine on a remote host, a virtual network segment needs to be configured on the local virtual machine and the remote virtual machine, and then is bridged to physical network interface cards for communication.

Currently, when applications running on virtual machines on hosts perform communication through RDMA, virtualization and data forwarding need to be performed for a plurality of times. As a result, steps required for performing data transmission are increased, high network overheads and a long delay are caused, and system efficiency is decreased.

SUMMARY

Embodiments of this application provide a communication method, to improve efficiency of data transmission between applications running on virtual machines.

According to a first aspect, this application provides a communication method. The method includes monitoring, by a first shared agent, first shared memory, where the first shared memory is used by a first application, the first application runs on a first virtual device, the first virtual device is located on a first host, the first shared memory belongs to a part of memory of the first host and does not belong to memory specified by the first host for the first virtual device, and the first shared agent independent of the first virtual device is disposed on the first host, and after determining that data of the first application is written to the first shared memory, reading, by the first shared agent, the data from the first shared memory, and sending the data to a second application, where the second application is a data sharing party specified by the first application. In this way, steps required for performing data transmission between applications on virtual devices are reduced, network overheads are reduced, a delay is shortened, and system efficiency is improved.

For the first aspect, in a possible implementation, the first application applies for the first shared memory, and obtains the allocated first shared memory, and the first application registers shared information of the first application with a sharing management center, where the shared information of the first application includes an identifier of the first application, an identifier of the data sharing party specified by the first application, and information about the first shared memory. In this way, when data is transmitted between applications, whether a related application has permission to share data can be checked in order to enhance system stability.

For the first aspect, in another possible implementation, before the reading, by the first shared agent, the data from the first shared memory, the first shared agent sends a query message to the sharing management center based on the identifier of the first application, and receives a query response message sent by the sharing management center, where the query response message indicates information about the data sharing party of the first application, and the information about the data sharing party includes an identifier of the second application, and the first shared agent performs, based on the identifier of the second application, the step of sending the data to the second application. In this method, system operating efficiency can be improved.

For the first aspect, in another possible implementation, the first shared agent sends the data to the second application in a RDMA manner. In this method, a data transmission speed can be increased, and system operating efficiency can be improved.

For the first aspect, in another possible implementation, the first application obtains a virtual address of the first shared memory, the first application translates a physical address of the first shared memory into an address of virtual memory of the first shared agent, and the first shared agent obtains the address of the virtual memory of the first shared agent. Correspondingly, the first application writes the data to the first shared memory according to the virtual address of the first shared memory, and the first shared agent monitors the first shared memory according to the address of the virtual memory of the first shared agent. In this method, the first shared agent may monitor the first shared memory, and may extract data when the data is written to the first shared memory, thereby improving system operating efficiency.

For the first aspect, in another possible implementation, the first application creates a ring buffer based on the first shared memory, the virtual address of the first shared memory is a virtual address of the ring buffer, and the physical address of the first shared memory is a physical address of the ring buffer. In this method, a shared memory may be used by a plurality of applications at the same time, thereby improving system operating efficiency.

For the first aspect, in another possible implementation, the first shared memory that the first application applies for may be in a form of a memory page, and may be huge page memory. In this method, system operating efficiency can be further improved.

For the first aspect, in another possible implementation, the first shared memory is divided with an equal size such that sizes of all areas obtained through division are the same. In this method, utilization of a shared memory can be improved, and system operating efficiency is improved.

According to a second aspect, this application provides a communication method. The method includes receiving, by a second shared agent, data from a first application, where second shared memory is used by a second application, the second application runs on a second virtual device, the second virtual device is located on a second host, the second shared memory belongs to a part of memory of the second host and does not belong to memory specified by the second host for the second virtual device, and the second shared agent independent of the second virtual device is disposed on the second host, and writing, by the second shared agent, the data to the second shared memory such that the second application obtains the data, where the first application and the second application are data sharing parties of each other. In this way, steps required for performing data transmission between applications on virtual devices are reduced, network overheads are reduced, a delay is shortened, and system efficiency is improved.

For the second aspect, in a possible implementation, the second application applies for the second shared memory, and obtains the allocated second shared memory, and the second application registers shared information of the second application with a sharing management center, where the shared information of the second application includes an identifier of the second application, an identifier of the data sharing party specified by the second application, and information about the second shared memory. In this way, when data is transmitted between applications, whether a related application has permission to share data can be checked in order to enhance system stability.

For the second aspect, in another possible implementation, before the writing, by the second shared agent, the data to the second shared memory, the second shared agent sends a query message to the sharing management center, to determine the identifier of the second application or the information about the second shared memory, and performs, based on the identifier of the second application or the information about the second shared memory, the step of writing the data to the second shared memory. In this method, system operating efficiency can be improved.

For the second aspect, in another possible implementation, the data received from the first application is sent by the first application in a RDMA manner. In this method, a data transmission speed can be increased, and system operating efficiency can be improved.

For the second aspect, in another possible implementation, the second application obtains a virtual address of the second shared memory, and the second application translates a physical address of the second shared memory into an address of virtual memory of the second shared agent, and provides the second shared agent with the virtual address of the second shared agent. Correspondingly, the second shared agent writes the received data to the second shared memory according to the address of the virtual memory of the shared agent. In this method, the second shared agent may write the received data to the second shared memory such that the second application obtains the data, thereby improving system efficiency.

For the second aspect, in another possible implementation, the second application creates a ring buffer based on the second shared memory, where the virtual address of the second shared memory is a virtual address of the ring buffer, and the physical address of the second shared memory is a physical address of the ring buffer. In this method, a shared memory may be used by a plurality of applications at the same time, thereby improving system operating efficiency.

According to a third aspect, this application provides a computer system. The computer system includes a first host and a first virtual device running on the first host, a first application runs on the first virtual device, first shared memory is allocated to the first application, and the first shared memory belongs to a part of memory of the first host and does not belong to memory specified by the first host for the first virtual device, and the computer system further includes a monitoring module, and the monitoring module is independent of the first virtual device, and is configured to monitor the first shared memory, and after determining that data of the first application is written to the first shared memory, read the data from the first shared memory, and send the data to a second application, where the second application is a data sharing party specified by the first application.

For the third aspect, in a possible implementation, the first application is configured to apply for the first shared memory, obtain the allocated first shared memory, and register shared information of the first application, where the shared information of the first application includes an identifier of the first application, an identifier of the data sharing party specified by the first application, and information about the first shared memory.

For the third aspect, in another possible implementation, before reading the data from the first shared memory, the monitoring module sends a query message to a sharing management center, and receives a query response message sent by the sharing management center, where the query response message indicates information about the data sharing party of the first application, and the information about the data sharing party includes an identifier of the second application, and the monitoring module performs, based on the identifier of the second application, the step of sending the data to the second application.

For the third aspect, in another possible implementation, the monitoring module sends the data to the second application in a RDMA manner.

For the third aspect, in another possible implementation, the first application is further configured to obtain a virtual address of the first shared memory, and translate a physical address of the first shared memory into an address of virtual memory of the monitoring module, where the monitoring module obtains the address of the virtual memory of the monitoring module. Correspondingly, the first application writes the data to the first shared memory according to the virtual address of the first shared memory, and the monitoring module monitors the first shared memory according to the address of the virtual memory of the monitoring module.

For the third aspect, in another possible implementation, the first application creates a ring buffer based on the first shared memory, the virtual address of the first shared memory is a virtual address of the ring buffer, and the physical address of the first shared memory is a physical address of the ring buffer.

According to a fourth aspect, this application provides a computer system. The computer system includes a second host and a second virtual device running on the second host, a second application runs on the second virtual device, second shared memory is allocated to the second application, and the second shared memory belongs to a part of memory of the second host and does not belong to memory specified by the second host for the second virtual device, and the computer system further includes a transmission module, and the transmission module is independent of the second virtual device, and is configured to receive data from a first application, and write the data to the second shared memory such that the second application obtains the data, where the first application is a data sharing party specified by the second application.

For the fourth aspect, in a possible implementation, the second application is configured to apply for the second shared memory, obtain the allocated second shared memory, and register shared information of the second application, where the shared information of the second application includes an identifier of the second application, an identifier of the data sharing party specified by the second application, and information about the second shared memory.

For the fourth aspect, in another possible implementation, the transmission module is further configured to send a query message to a sharing management center before writing the data to the second shared memory, to determine the identifier of the second application or the information about the second shared memory, and the transmission module performs, based on the identifier of the second application or the information about the second shared memory, the step of writing the data to the second shared memory.

For the fourth aspect, in another possible implementation, the data received from the first application is sent by the first application in a RDMA manner.

For the fourth aspect, in another possible implementation, the second application is further configured to obtain a virtual address of the second shared memory, and the second application translates a physical address of the second shared memory into an address of virtual memory of the transmission module, and provides the transmission module with the address of the virtual memory of the transmission module. Correspondingly, the transmission module is further configured to write the received data to the second shared memory according to the address of the virtual memory of the transmission module.

For the fourth aspect, in another possible implementation, the second application creates a ring buffer based on the second shared memory, the virtual address of the second shared memory is a virtual address of the ring buffer, and the physical address of the second shared memory is a physical address of the ring buffer.

According to a fifth aspect, a computer system is provided. The computer system includes a processor and a memory, where the memory stores program code, and the processor is configured to invoke the program code in the memory to perform the data transmission method according to the first aspect.

According to a sixth aspect, a computer system is provided. The computer system includes a processor and a memory, where the memory stores program code, and the processor is configured to invoke the program code in the memory to perform the data transmission method according to the second aspect.

According to a seventh aspect, a data transmission system is provided. The data transmission system includes at least two hosts. A first virtual device runs on a first host, a first application runs on the first virtual device, first shared memory is allocated to the first application, the first shared memory belongs to a part of memory of the first host and does not belong to memory specified by the first host for the first virtual device, and the first host further includes a first shared agent. A second virtual device runs on a second host, a second application runs on the second virtual device, second shared memory is allocated to the second application, the second shared memory belongs to a part of memory of the second host and does not belong to memory specified by the second host for the second virtual device, and the second host further includes a second shared agent. The second application is a data sharing party of the first application. The first shared agent is configured to monitor the first shared memory, and after monitoring and detecting that data of the first application is written to the first shared memory, read the data from the first application, and send the data to the second host. The second shared agent is configured to receive the data from the first application, and write the data to the second shared memory.

For the seventh aspect, in a possible implementation, the data transmission system further includes a sharing management center configured to receive a registration message from the first host, and obtain shared information that is of the first application and that is in the registration message, where the shared information of the first application includes an identifier of the first application, an identifier of a data sharing party specified by the first application, and information about the first shared memory. The sharing management center is configured to receive a query message from the first shared agent, query information about the data sharing party of the first application based on the identifier that is of the first application and that is carried in the query message of the first shared agent, and send a query response message to the first shared agent, where the query response message includes an identifier of the second application.

For the seventh aspect, in another possible implementation, the sharing management center in the data transmission system is further configured to receive a query message from the second shared agent, query the identifier of the second application or information about the second shared memory, and send a query response message to the second shared agent, where the query response message includes the identifier of the second application or the information about the second shared memory.

In the data transmission system, the first host is further configured to further perform the method according to the first aspect, and the second host is further configured to further perform the method according to the second aspect.

