Data transmission method, device, electronic device and storage medium
By extracting data from the kernel cache and storing it in the user cache, it solves the problem of excessive kernel cache occupancy in high concurrency scenarios, improves data transmission efficiency, and ensures the stability of data reception and sending.
Patent Information
- Application Number
- CN202011132819.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-21
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2040-10-21
Smart Images

Figure CN114390098B
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a data transmission method, device, electronic device and storage medium. Background Art
[0002] When data is transmitted, threads can be established in both the data sender and the data receiver, and data transmission can be realized through threads. Specifically, when data is sent, the user thread of the data sender can store the data to be sent in the kernel cache of the data sender, and then the data sender can send the data to the data receiver. When data is received, the data receiver can store the received data in the kernel cache of the data receiver, and then the user thread waiting to obtain the data reads the data from the kernel cache.
[0003] In a high-concurrency scenario, the data sender and the data receiver will transmit a large amount of data in a short period of time. If the above data transmission method is used for data transmission, a large amount of data will occupy the kernel cache in a short period of time, causing the data receiver to be unable to receive data, or the data sender to be unable to send data, thereby reducing data transmission efficiency. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a data transmission method, device, electronic device and storage medium to solve the problem of low data transmission efficiency in high concurrency scenarios. The specific technical solution is as follows:
[0005] In a first aspect, a data transmission method is provided, the method further comprising:
[0006] Extracting first data from the kernel cache, wherein the first data is data to be sent to the first user thread;
[0007] storing the first data in a user cache;
[0008] Instruct the first user thread to extract the first data from the user cache.
[0009] Optionally, storing the first data in a user cache includes:
[0010] Obtaining a user cache corresponding to the first user thread from one or more of the user caches;
[0011] The first data is stored in a user cache corresponding to the first user thread.
[0012] Optionally, storing the first data in a user cache includes:
[0013] storing a thread identifier and the first data in the user cache correspondingly, wherein the thread identifier is an identifier of the first user thread;
[0014] The instructing the first user thread to extract the first data from the user cache includes:
[0015] Instruct the first user thread to extract the first data from the user cache according to the thread identifier.
[0016] Optionally, before storing the first data in the user cache, the method further includes:
[0017] Sending a user cache request to a device running the first user thread, wherein the user cache request is used to request allocation of cache space;
[0018] receiving a response message from the device, wherein the response message indicates a storage location of a cache space allocated for the first user thread;
[0019] The cache space indicated by the storage location is determined as the user cache.
[0020] In a second aspect, a data transmission method is provided, the method further comprising:
[0021] Extracting data transmission information from the user cache, wherein the data transmission information is used to represent the data instructed to be sent by the second user thread, and the data transmission information is stored in the user cache by the second user thread;
[0022] Acquire the second data identified by the data transmission information from the data storage space;
[0023] The second data is stored in a kernel cache, wherein the kernel cache is used to send the second data.
[0024] Optionally, extract data transmission information from the user cache, including:
[0025] detecting the amount of storage occupied by the data transmission information in the user cache;
[0026] When the storage amount reaches a preset threshold, the data transmission information is extracted from the user cache.
[0027] Optionally, storing the second data in a kernel cache includes:
[0028] In a case where the data transmission information indicates a data recipient of the second data, searching for a sub-buffer area corresponding to the data recipient of the second data from data recipients and sub-buffer areas having a corresponding relationship to obtain a target sub-buffer area, wherein the kernel cache includes a plurality of sub-buffer areas;
[0029] The second data is stored in the target sub-cache area, wherein the kernel cache is used to send the data stored in the target sub-cache area to the data receiver.
[0030] Optionally, storing the second data in a kernel cache includes:
[0031] A data recipient identifier and the second data are correspondingly stored in the kernel cache, the data recipient identifier is an identifier of a data recipient receiving the second data, the data transmission information includes the data recipient identifier, and the kernel cache is used to send the second data according to the data recipient identifier.
[0032] According to a third aspect, a data transmission device is provided, the device further comprising:
[0033] An extraction module, configured to extract first data from the kernel cache, wherein the first data is data to be sent to the first user thread;
[0034] A storage module, used for storing the first data in a user cache;
[0035] An instruction module is used to instruct the first user thread to extract the first data from the user cache.
[0036] Optionally, the storage module includes:
[0037] An acquisition submodule, configured to acquire a user cache corresponding to the first user thread from one or more of the user caches;
[0038] A first storage submodule is configured to store the first data in a user cache corresponding to the first user thread.
[0039] Optionally, the storage module is used to store a thread identifier and the first data in the user cache correspondingly, and the thread identifier is an identifier of the first user thread;
[0040] The instructing module is used to instruct the first user thread to extract the first data from the user cache according to the thread identifier.
[0041] Optionally, the device further comprises:
[0042] A sending module, configured to send a user cache request to a device running the first user thread, wherein the user cache request is used to request allocation of cache space;
[0043] a receiving module, configured to receive response information from the device, wherein the response information indicates a storage location of a cache space allocated for the first user thread;
[0044] A determination module is used to determine the cache space indicated by the storage location as the user cache.
[0045] In a fourth aspect, a data transmission device is provided, the device comprising:
[0046] An extraction module, used to extract data transmission information from the user cache, wherein the data transmission information is used to represent the data instructed to be sent by the second user thread, and the data transmission information is stored in the user cache by the second user thread;
[0047] An acquisition module, configured to acquire the second data identified by the data transmission information from the data storage space;
[0048] A storage module is used to store the second data in a kernel cache, wherein the kernel cache is used to send the second data.
[0049] Optionally, the extraction module includes:
[0050] A detection submodule, used to detect the storage amount occupied by the data transmission information in the user cache;
[0051] The extraction submodule is used to extract the data transmission information from the user cache when the storage amount reaches a preset threshold.
[0052] Optionally, the storage module includes:
[0053] A search submodule is used for searching, when the data transmission information indicates a data recipient of the second data, a sub-buffer area corresponding to the data recipient of the second data from the data recipients and sub-buffer areas having a corresponding relationship, to obtain a target sub-buffer area. The kernel cache includes a plurality of sub-buffer areas.
[0054] A storage submodule is used to store the second data in the target sub-cache area, wherein the kernel cache is used to send the data stored in the target sub-cache area to the data recipient.
[0055] Optionally, the storage module is used to store a data recipient identifier and the second data correspondingly in a kernel cache, the data recipient identifier is an identifier of a data recipient that receives the second data, the data transmission information includes the data recipient identifier, and the kernel cache is used to send the second data according to the data recipient identifier.
[0056] In a fifth aspect, an electronic device is provided, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0057] Memory, used to store computer programs;
[0058] The processor is used to implement the method steps described in any first aspect or any second aspect when executing the program stored in the memory.
[0059] In a sixth aspect, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the method steps described in any one of the first aspects or any one of the second aspects are implemented.
[0060] In a seventh aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned data transmission methods.
[0061] Beneficial effects of the embodiments of the present application:
[0062] The embodiment of the present application provides a data transmission method, device, electronic device and storage medium. In the present application, first data can be extracted from the kernel cache, wherein the first data is data to be sent to the first user thread; the first data is stored in the user cache; and the first user thread is instructed to extract the first data from the user cache.
[0063] Since the first data is extracted from the kernel cache when transmitting data and then stored in the user cache, the storage space of the kernel cache can be released in real time, alleviating the storage pressure of the kernel cache, thereby avoiding the problem of being unable to receive or send data when processing a large amount of data in a short time, and improving data transmission efficiency.
[0064] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0066] Figure 1 A flowchart of a data transmission method provided in an embodiment of the present application;
[0067] Figure 2 A flowchart of another data transmission method provided in an embodiment of the present application;
[0068] Figure 3 A flowchart of another data transmission method provided in an embodiment of the present application;
[0069] Figure 4 An example diagram of a data transmission method provided in an embodiment of the present application;
[0070] Figure 5 A schematic diagram of the structure of a data transmission device provided in an embodiment of the present application;
[0071] Figure 6 A schematic diagram of the structure of another data transmission device provided in an embodiment of the present application;
[0072] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0073] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0074] The embodiment of the present application provides a data transmission method, which can be applied to a data transmission party. The data transmission party may include a data sender and a data receiver.
[0075] Taking the case of data transmission between a client with an application installed and a server of the application, the data transmission parties may include the client and the server. In the case where the client sends data to the server, the data sender may be the client and the data receiver may be the server. In the case where the server sends data to the client, the data sender may be the server and the data receiver may be the client. It is understandable that a device that acts as a data sender in one case may act as a data receiver in another case.
[0076] In the embodiment of the present application, in order to perform data transmission, the data transmission party may create multiple threads. The multiple threads may include user threads and target threads, wherein the user thread is used to process the data required to run the application, the user thread may generate data to be sent to the data receiving party, and the user thread may perform data processing on the data sent by the data sending party according to the set business logic. The target thread may be used to extract data from the kernel cache, or store data in the kernel cache. The number of target threads is less than the number of user threads. In the embodiment of the present application, the number of target threads may be 1.
[0077] The kernel cache is used to store data to be sent to the data receiver, and to send the data to the data receiver, and to store the data sent by the data sender, when the data is received.
[0078] The present application embodiment takes the method applied to the data receiving party as an example to illustrate the processing process of the data transmission method. Figure 1 As shown, including:
[0079] Step 101: extract first data from the kernel cache.
[0080] The first data is data to be sent to the first user thread.
[0081] In implementation, when receiving the first data sent by the data sender, the data receiver may store the first data in a kernel cache, and then the target thread in the data receiver may extract the first data from the kernel cache.
[0082] Step 102: Store the first data in the user cache.
[0083] In implementation, the target thread may determine a user cache in the data receiver, and then store the first data in the determined user cache.
[0084] Optionally, one or more user caches may be set in the data receiver. According to different settings of the user cache in the data receiver, the target thread may have different processing procedures for determining the user cache in the data receiver. The specific processing procedures will be described in detail later.
[0085] The target thread may only store the first data in the determined user cache, and the target thread may also obtain the thread identifier of the first user thread. The first data is stored in the determined user cache based on the thread identifier, and the specific processing process will be described in detail later.
[0086] Step 103: Instruct the first user thread to extract first data from the user cache.
[0087] In implementation, the first data may carry a thread identifier, the target thread may obtain the thread identifier carried by the first data, and use the thread corresponding to the thread identifier as the first user thread. Then, the target thread may send indication information to the first user thread, and then the first user thread may extract the first data from the user cache according to the indication information.
[0088] There may be various ways for the first user thread to extract the first data from the user cache according to the indication information. In a first feasible implementation, when multiple user caches are set in the data receiving party, the indication information may indicate the user cache storing the first data, thereby, the first user thread may extract the first data from the user cache indicated by the indication information.
[0089] In a second feasible implementation manner, the indication information may indicate a storage location of the first data in the user cache, and thus the first user thread may extract the first data from the user cache according to the storage location indicated by the indication information.
[0090] In a third feasible implementation manner, the indication information may indicate a thread identifier of the first user thread, and the first user thread may extract the first data from the user cache according to the thread identifier. The specific processing process will be described in detail later.
[0091] In the embodiment of the present application, since the first data is extracted from the kernel cache after receiving the first data and then stored in the user cache, the storage space of the memory cache can be released in real time, alleviating the storage pressure of the memory cache, thereby avoiding the problem of being unable to receive or send data when processing a large amount of data in a short time, thereby improving data transmission efficiency.
[0092] In high-concurrency scenarios, the data sender and the data receiver will establish a large number of user threads, which will extract the received data from the kernel cache or store the data to be sent to achieve the transmission of a large amount of data in a short time. As a result, the kernel cache needs to interact with a large number of user threads in a short period of time and frequently switch the access threads, resulting in high processing pressure on the kernel cache.
[0093] In the embodiment of the present application, the target thread extracts the first data from the kernel cache. Therefore, it is possible to avoid the kernel cache from interacting with a large number of user threads in a short period of time, reduce thread switching, and thus reduce the processing pressure of the kernel cache and improve data transmission efficiency.
[0094] Before transmitting data, you can apply for user cache from the device where the user thread is located. The specific steps are as follows:
[0095] Step 1: Send a user cache request to a device running a first user thread.
[0096] The user cache request is used to request allocation of cache space.
[0097] In implementation, after the data transmission party starts running, a user buffer request may be sent to a device running the first user thread.
[0098] In the embodiment of the present application, when the data transmission party is a client with an application installed, the device running the first user thread may be the client. When the data transmission party is a server of the application, the device running the first user thread may be the server. When the server is a service cluster composed of multiple servers, the device running the first user thread may be some or all of the servers in the service cluster.
[0099] Step 2: Receive the response information from the device.
[0100] The response information indicates a storage location of a cache space allocated to the first user thread.
[0101] In implementation, after receiving the user cache request, the device running the first user thread may determine a portion of cache space in the local cache as the cache space allocated to the first user thread, and then generate response information indicating the storage location of the cache space and send the response information.
[0102] Optionally, a user thread belonging to the same application as the first user thread can use the cache space allocated for the first user thread, that is, multiple user threads of the application can use the cache space together. Therefore, the response information can indicate the storage location of the cache space allocated for the application to which the first user thread belongs.
[0103] Optionally, when multiple applications are running in the device running the first user thread, the device may allocate the same cache space to the multiple applications, and the user threads of the multiple applications may use the cache space together. Alternatively, the device running the first user thread may allocate a cache space to each application separately, and the user thread of each application may use the cache space corresponding to the application.
[0104] Step 3: Determine the cache space indicated by the storage location as the user cache.
[0105] In an embodiment of the present application, a user cache request may be sent to a device running a first user thread, and then a response message indicating a storage location of an allocated cache space may be received. Afterwards, the cache space indicated by the storage location may be determined as the user cache. Thus, the cache mechanism of the user cache is expanded on the basis of the kernel cache, so that when the first data is subsequently sent, the data transmission information of the first data is stored and extracted in the user cache, and when the second data is received, the second data is stored and extracted in the user cache.
[0106] The above-mentioned processing process of applying for user cache can be implemented by the target thread in the data transmission party, and can also be implemented by the user thread in the data transmission party, which is not specifically limited in the embodiment of the present application.
[0107] Optionally, a user cache may be set in the data receiving party, and user threads of all applications in the data receiving party may share and use the user cache. Alternatively, multiple user caches may be set in the data receiving party, and the multiple user caches are respectively set for multiple applications in the data receiving party. When user caches are respectively set for multiple applications, a separate user cache may be set for each application, so that user threads belonging to the same application can use the same user cache. Alternatively, the same user cache may be set for some applications, and user threads belonging to some applications can share and use the user cache.
[0108] According to different settings of the user cache in the data receiving party, the embodiment of the present application provides an implementation method for storing the first data in the user cache, including:
[0109] Step 1: Obtain a user cache corresponding to a first user thread from one or more user caches.
[0110] In implementation, in the case where a user cache is provided in the data receiving party, after extracting the first data from the kernel cache, the target thread may directly use the user cache as the user cache corresponding to the first user thread.
[0111] In the case where multiple user caches are set in the data receiving party, after extracting the first data from the kernel cache, the target thread can obtain the thread identifier carried by the first data, and use the user thread corresponding to the thread identifier as the first user thread. Then, the target thread can determine the application to which the first user thread belongs, and obtain the target application. After that, the target thread can search for the user cache corresponding to the target application in the application and user cache having a corresponding relationship, and use the found user cache as the user cache corresponding to the first user thread.
[0112] Step 2: Store the first data in a user cache corresponding to the first user thread.
[0113] In the embodiment of the present application, in the case where a user cache is set in the data receiving party, the target thread can directly store the first data in the user cache, thereby improving the data storage efficiency of the data receiving party.
[0114] In the case where multiple user caches are set in the data receiving party, the target thread can store the first data in the user cache corresponding to the target application. In this way, the first data can be stored in the user cache of the corresponding application, which makes it easier for the first user thread to search for the first data in the user cache, thereby improving the data extraction efficiency of the data receiving party.
[0115] Optionally, a thread identifier of the first user thread may be obtained, and the first data may be stored and retrieved in the user cache based on the thread identifier. The processing includes:
[0116] Step 1: extract first data from the kernel cache.
[0117] In implementation, the processing procedure of this step may refer to the processing procedure of step 101, and will not be repeated here.
[0118] Step 2: Store the thread identifier and the first data correspondingly in the user cache.
[0119] In implementation, the first data may carry a thread identifier, and the target thread may obtain the thread identifier carried by the first data to obtain the thread identifier of the first user thread. Then, the target thread may store the thread identifier of the first user thread and the first data in the user cache accordingly.
[0120] Step three: instruct the first user thread to extract the first data from the user cache according to the thread identifier.
[0121] In implementation, the target thread may send indication information indicating the thread identifier of the first user thread, and then the first user thread may extract data corresponding to the thread identifier of the first user thread from the user cache to obtain the first data.
[0122] In the embodiment of the present application, since the thread identifier and the first data are stored in the user cache in correspondence, it is convenient for the first user thread to extract the first data in the user cache according to the thread identifier, thereby improving the data extraction efficiency. Furthermore, it is ensured that the first user thread extracts the first data from the user cache in a timely manner, freeing up the storage space of the user cache, so that the user cache can store more data extracted from the kernel cache, further improving the data transmission efficiency.
[0123] The present application also provides a data transmission method, which can be applied to a data sender, such as Figure 2As shown, the specific steps are as follows:
[0124] Step 201: extract data transmission information from the user cache.
[0125] The data transmission information is used to represent the data instructed to be sent by the second user thread. For the sake of distinction, the data instructed to be sent by the second user thread is referred to as second data.
[0126] In implementation, when the second user thread in the data sender has the second data to be sent to the data receiver, the second user thread can generate data transmission information of the second data. Then, the second user thread can store the data transmission information in the user buffer corresponding to the second user thread. Afterwards, the target thread can extract the data transmission information from the user buffer.
[0127] In the embodiment of the present application, the data transmission information may include the storage location of the second data in the data storage space, and / or the data identifier of the second data. The data transmission information may also include one or more information such as information capable of identifying the second user thread, information capable of identifying the data recipient receiving the second data, and the like.
[0128] For example, the data transmission information may include the thread number of the second user thread, the data cache pointer of the second data, the data length of the second data, and a connection handle indicating the data receiver. The thread number is used to identify the second user thread, the data cache pointer and the data length are used to indicate the storage location of the second data in the data storage space, and the connection handle is used to indicate the data receiver of the second data.
[0129] Step 202: Acquire second data identified by the data transmission information from the data storage space.
[0130] In implementation, when the data transmission information includes the storage position of the second data in the data storage space, the target thread may read the second data from the data storage space according to the storage position included in the data transmission information.
[0131] When the data transmission information includes the data identifier of the second data, the target thread may read the second data from the data storage space according to the data identifier.
[0132] Step 203: Store the second data in the kernel cache.
[0133] The kernel cache is used to send the second data.
[0134] Since the kernel has a kernel characteristic of sending the data to be sent to the data recipient when the data to be sent is stored in the kernel cache, this kernel characteristic can be utilized to store the second data to be sent in the kernel cache to send the second data to the data recipient.
[0135] In the embodiment of the present application, when sending the second data, the second user thread first stores the data transmission information of the second data in the user cache, and the target thread obtains the second data according to the data transmission information extracted from the user cache, and then stores the second data in the kernel cache. Thus, in a high concurrency scenario, it is possible to avoid directly storing a large amount of second data to be sent in the kernel cache, thereby reducing the storage pressure of the kernel cache and improving the data transmission efficiency.
[0136] Furthermore, compared with a large number of user threads directly storing the second data in the kernel cache, storing the second data in the kernel cache by the target thread can avoid the kernel cache from interacting with a large number of user threads in a short period of time, reduce the number of thread switching, thereby alleviating the processing pressure of the kernel cache and improving data transmission efficiency.
[0137] In addition, since the data transmission information indicating the second data is stored in the user cache, the target thread obtains the second data according to the data transmission information and then stores the second data in the kernel cache, the second data is only stored once in the kernel cache during the second data transmission process. Compared with storing the second data in the user cache, subsequently extracting the second data from the user cache and then storing the second data in the kernel cache, repeated storage of the second data is avoided. On the one hand, the storage space of the user cache can be saved, and on the other hand, the storage and extraction of the second data with a larger capacity in the user cache can be avoided, saving the processing resources consumed by the data transmission party for data reading and writing.
[0138] Optionally, the target thread may extract the data transmission information from the user cache in a variety of ways. In a first feasible implementation, the target thread may detect whether the data transmission information is stored in the user cache. If the data transmission information is detected to be stored in the user cache, the target thread may extract the data transmission information from the user cache. If the data transmission information is not detected to be stored in the user cache, the target thread may not perform subsequent processing.
[0139] In a second feasible implementation, the second user thread may send indication information to the target thread after storing the data transmission information in the user buffer. The target thread may extract the data transmission information from the user buffer after receiving the indication information.
[0140] In a third feasible implementation, the target thread may extract the data transmission information according to the amount of storage occupied by the data transmission information in the user cache, such as Figure 3 As shown, including:
[0141] Step 301: Detect the storage volume occupied by data transmission information in the user cache.
[0142] In implementation, the target thread may detect the amount of storage occupied by the data transmission information in the user cache. Then, the target thread may compare the detected amount of storage with a preset threshold. If the amount of storage does not reach the preset threshold, the target thread may not perform subsequent processing.
[0143] Optionally, the preset threshold value may be set according to the amount of data transmitted during the actual data transmission process. For example, the preset threshold value may be 1 Kb.
[0144] Step 302: When the storage amount reaches a preset threshold, extract data transmission information from the user cache.
[0145] In the embodiment of the present application, when the storage amount of the data transmission information reaches a preset threshold, the target thread can extract multiple data transmission information from the user cache, and then obtain multiple second data according to the multiple data transmission information. Thus, the target thread can batch store multiple second data in the kernel storage, thereby enabling batch transmission of the second data and preventing the phenomenon of sending small packets of data.
[0146] Optionally, the data transmission information can also be used to indicate a data recipient of the second data. The target thread can indicate the data recipient of the second data to the kernel cache based on the data transmission information while storing the second data in the kernel cache, so that the kernel cache sends the second data to the indicated data recipient. The present application embodiment provides two implementations of indicating the data recipient of the second data to the kernel cache, including:
[0147] Method 1: The kernel cache may include multiple sub-buffers, each sub-buffer corresponds to a data receiver, and the kernel cache may be used to send the data stored in each sub-buffer to the data receiver corresponding to the sub-buffer. In this case, the process of indicating the data receiver of the kernel cache second data may include:
[0148] Step 1: From the data receivers and sub-buffers having a corresponding relationship, search for the sub-buffer corresponding to the data receiver of the second data to obtain a target sub-buffer.
[0149] In implementation, after extracting the data transmission information, the target thread can determine the data recipient indicated by the data transmission information. Then, the target thread can search for the sub-buffer corresponding to the determined data recipient from the data recipients and sub-buffers having a corresponding relationship to obtain the target sub-buffer.
[0150] Step 2: storing the second data in the target sub-buffer area.
[0151] In the embodiment of the present application, the target thread can search for the target sub-buffer area corresponding to the data recipient of the second data from the data recipients and sub-buffer areas with a corresponding relationship, and then store the second data in the target sub-buffer area. Thus, when sending the second data, the data sender can quickly determine the data recipient of the second data, thereby improving data transmission efficiency.
[0152] Mode 2: The data transmission information may include a data recipient identifier, and the kernel cache may be used to send the second data according to the data recipient identifier. The data recipient identifier is an identifier of a data recipient of the second data. In this case, the processing of indicating the data recipient of the second data to the kernel cache may include: storing the data recipient identifier and the second data in the kernel cache accordingly. Thus, when sending the second data, the second data may be sent to the data recipient indicated by the data recipient identifier, so that the data sender can quickly determine the data recipient of the second data, thereby improving the data transmission efficiency.
[0153] like Figure 4 As shown, it is an example diagram of a data transmission method provided by an embodiment of the present application, wherein both device 100 and device 200 are data transmission parties, device 100 may be a client with an application installed, and device 200 may be a server of the application. After the data transmission party starts running, a user cache may be applied for the application so that the data transmission party realizes data transmission based on the user cache and the kernel cache.
[0154] When the client sends data to the server, as shown by the solid arrow in the device 100, when the user thread in the client has the second data to be sent, the user thread can generate data transmission information of the second data, and then write the data transmission information into the user cache. Then, by calling the time waiting model, the user thread can enter the waiting state and wait for the response data sent by the server. The data transmission information may include the thread number of the user thread, the data cache pointer of the second data, the data length of the second data, and the connection handle indicating the data receiver.
[0155] The target thread can detect the storage amount occupied by the data transmission information in the user cache, and when the storage amount reaches a preset threshold of 1Kb, extract the data transmission information from the user cache, obtain the second data from the data storage space according to the data transmission information, and then store the obtained second data in the kernel cache. Then, the kernel characteristics can be used to send the second data stored in the kernel cache to the server, thereby realizing data transmission.
[0156] As shown by the dotted arrow in device 200, after receiving the second data sent by the client, the server can store the second data as the received first data in the kernel cache. The target thread in the server can extract the first data from the kernel cache and write the first data into the user cache. Therefore, by extracting the first data from the kernel cache in a timely manner and storing the first data in the user cache, the probability of the kernel cache becoming full can be reduced, and the data receiving efficiency can be improved.
[0157] Then, the user thread in the server can extract the first data from the user cache and generate response data of the first data. After that, the server can send the response data to the client, and the sending process is shown by the solid arrow in the device 200. The specific sending process is similar to the sending process of the client sending the second data to the server, and will not be repeated here.
[0158] After receiving the response data sent by the server, the client can store the response data in the kernel cache, and then the target thread can extract the response data from the kernel cache and store the response data in the user cache. After that, the target thread can activate the first user thread that enters the waiting state in an event-driven manner, and the first user thread extracts the response data from the user cache and processes the response data according to the business logic of the first user thread.
[0159] In this way, TCP (Transmission Control Protocol) communication between the client and the server can be achieved.
[0160] Based on the same technical concept, the embodiment of the present application also provides a data transmission device, such as Figure 5 As shown, the device comprises:
[0161] An extraction module 510, configured to extract first data from a kernel cache, wherein the first data is data to be sent to a first user thread;
[0162] A storage module 520, configured to store the first data in a user cache;
[0163] The instructing module 530 is configured to instruct the first user thread to extract the first data from the user cache.
[0164] Optionally, the storage module includes:
[0165] An acquisition submodule, configured to acquire a user cache corresponding to the first user thread from one or more of the user caches;
[0166] A first storage submodule is configured to store the first data in a user cache corresponding to the first user thread.
[0167] Optionally, the storage module is used to store a thread identifier and the first data in the user cache correspondingly, and the thread identifier is an identifier of the first user thread;
[0168] The instructing module is used to instruct the first user thread to extract the first data from the user cache according to the thread identifier.
[0169] Optionally, the device further comprises:
[0170] A sending module, configured to send a user cache request to a device running the first user thread, wherein the user cache request is used to request allocation of cache space;
[0171] a receiving module, configured to receive response information from the device, wherein the response information indicates a storage location of a cache space allocated for the first user thread;
[0172] A determination module is used to determine the cache space indicated by the storage location as the user cache.
[0173] In the embodiment of the present application, since the first data is extracted from the kernel cache after receiving the first data and then stored in the user cache, the storage space of the memory cache can be released in real time, alleviating the storage pressure of the memory cache, thereby avoiding the problem of being unable to receive or send data when processing a large amount of data in a short time, thereby improving data transmission efficiency.
[0174] Based on the same technical concept, the embodiment of the present application also provides a data transmission device, such as Figure 6 As shown, the device comprises:
[0175] An extraction module 610 is used to extract data transmission information from the user cache, wherein the data transmission information is used to represent the data instructed to be sent by the second user thread, and the data transmission information is stored in the user cache by the second user thread;
[0176] An acquisition module 620, configured to acquire the second data identified by the data transmission information from the data storage space;
[0177] The storage module 630 is used to store the second data in a kernel cache, wherein the kernel cache is used to send the second data.
[0178] Optionally, the extraction module includes:
[0179] A detection submodule, used to detect the storage amount occupied by the data transmission information in the user cache;
[0180] The extraction submodule is used to extract the data transmission information from the user cache when the storage amount reaches a preset threshold.
[0181] Optionally, the storage module includes:
[0182] a search submodule, configured to search for a sub-buffer area corresponding to the data recipient of the second data from the data recipients and sub-buffer areas having a corresponding relationship, and obtain a target sub-buffer area, when the data transmission information indicates that there is a data recipient of the second data, wherein the kernel cache includes a plurality of sub-buffer areas;
[0183] A storage submodule is used to store the second data in the target sub-cache area, wherein the kernel cache is used to send the data stored in the target sub-cache area to the data recipient.
[0184] Optionally, the storage module is used to store a data recipient identifier and the second data correspondingly in a kernel cache, the data recipient identifier is an identifier of a data recipient that receives the second data, the data transmission information includes the data recipient identifier, and the kernel cache is used to send the second data according to the data recipient identifier.
[0185] In the embodiment of the present application, when sending the second data, the second user thread first stores the data transmission information of the second data in the user cache, and the target thread obtains the second data according to the data transmission information extracted from the user cache, and then stores the second data in the kernel cache. Thus, in a high concurrency scenario, it is possible to avoid directly storing a large amount of second data to be sent in the kernel cache, thereby reducing the storage pressure of the kernel cache and improving the data transmission efficiency.
[0186] Based on the same technical concept, the embodiment of the present application also provides an electronic device, such as Figure 7 As shown, it includes a processor 701, a communication interface 702, a memory 703 and a communication bus 704, wherein the processor 701, the communication interface 702, and the memory 703 communicate with each other through the communication bus 704.
[0187] Memory 703, used for storing computer programs;
[0188] The processor 701 is used to implement the steps of any of the above data transmission methods when executing the program stored in the memory 703.
[0189] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0190] The communication interface is used for communication between the above electronic device and other devices.
[0191] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0192] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0193] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned data transmission methods are implemented.
[0194] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any of the data transmission methods in the above embodiments.
[0195] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.
[0196] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0197] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. A data transmission method, characterized in that: Applied to a target thread in a data transmission party, the method further comprises: Extracting first data from the kernel cache, wherein the first data is data to be sent to the first user thread; In the case where multiple user caches are set in the data receiving party, a thread identifier carried by the first data is obtained, and a user thread corresponding to the thread identifier is used as a first user thread; an application to which the first user thread belongs is determined to obtain a target application; a user cache corresponding to the target application is searched among applications and user caches having a corresponding relationship, and the user cache found is used as a user cache corresponding to the first user thread; storing the first data in a user cache; instructing the first user thread to extract the first data from the user cache; Before storing the first data in the user cache, the method further includes: Sending a user cache request to a device running the first user thread, wherein the user cache request is used to request allocation of cache space; receiving a response message from the device, wherein the response message indicates a storage location of a cache space allocated for the first user thread; The cache space indicated by the storage location is determined as the user cache.
2. The method according to claim 1, characterized in that Storing the first data in a user cache includes: Obtaining a user cache corresponding to the first user thread from one or more of the user caches; The first data is stored in a user cache corresponding to the first user thread.
3. The method according to claim 1, characterized in that Storing the first data in a user cache includes: storing a thread identifier and the first data in the user cache correspondingly, wherein the thread identifier is an identifier of the first user thread; The instructing the first user thread to extract the first data from the user cache includes: Instruct the first user thread to extract the first data from the user cache according to the thread identifier.
4. A data transmission method, characterized in that: Applied to a target thread in a data sender, the method comprises: Extracting data transmission information from the user cache, wherein the data transmission information is used to represent the data instructed to be sent by the second user thread, the data transmission information is stored by the second user thread in the user cache corresponding to the second user thread, and the data transmission information includes a storage location of the second data in the data storage space, a data identifier of the second data, information identifying the second user thread, and information identifying a data recipient receiving the second data; Acquire the second data identified by the data transmission information from the data storage space according to the storage location or data identifier in the data transmission information; The second data is stored in a kernel cache, wherein the kernel cache is used to send the second data to a data receiver of the second data.
5. The method according to claim 4, characterized in that Extract data transfer information from the user cache, including: detecting the amount of storage occupied by the data transmission information in the user cache; When the storage amount reaches a preset threshold, the data transmission information is extracted from the user cache.
6. The method according to claim 4, characterized in that Storing the second data in the kernel cache includes: In a case where the data transmission information indicates a data recipient of the second data, searching for a sub-buffer area corresponding to the data recipient of the second data from data recipients and sub-buffer areas having a corresponding relationship to obtain a target sub-buffer area, wherein the kernel cache includes a plurality of sub-buffer areas; The second data is stored in the target sub-cache area, wherein the kernel cache is used to send the data stored in the target sub-cache area to the data receiver.
7. The method according to claim 4, characterized in that Storing the second data in the kernel cache includes: A data recipient identifier and the second data are stored correspondingly in the kernel cache, the data recipient identifier is an identifier of a data recipient receiving the second data, the data transmission information includes the data recipient identifier, and the kernel cache is used to send the second data according to the data recipient identifier.
8. A data transmission device, characterized in that: Applied to a target thread in a data transmission party, the device further comprises: An extraction module, configured to extract first data from the kernel cache, wherein the first data is data to be sent to the first user thread; The device is also used for obtaining a thread identifier carried by the first data and using a user thread corresponding to the thread identifier as a first user thread when multiple user caches are set in the data receiving party; determining an application to which the first user thread belongs to obtain a target application; searching for a user cache corresponding to the target application among applications and user caches having a corresponding relationship, and using the found user cache as a user cache corresponding to the first user thread; A storage module, used for storing the first data in a user cache; an instruction module, configured to instruct the first user thread to extract the first data from the user cache; Before storing the first data in the user cache, the device further includes: A sending module, configured to send a user cache request to a device running the first user thread, wherein the user cache request is used to request allocation of cache space; a receiving module, configured to receive response information from the device, wherein the response information indicates a storage location of a cache space allocated for the first user thread; A determination module is used to determine the cache space indicated by the storage location as the user cache.
9. A data transmission device, characterized in that: Applied to a target thread in a data sender, the device comprises: an extraction module, configured to extract data transmission information from the user cache, wherein the data transmission information is used to represent the data instructed to be sent by the second user thread, the data transmission information is stored by the second user thread in the user cache corresponding to the second user thread, and the data transmission information includes a storage location of the second data in the data storage space, a data identifier of the second data, information identifying the second user thread, and information identifying a data recipient receiving the second data; An acquisition module, configured to acquire, from the data storage space, the second data identified by the data transmission information according to the storage location or data identifier in the data transmission information; A storage module is used to store the second data in a kernel cache, wherein the kernel cache is used to send the second data to a data recipient of the second data.
10. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; The processor is used to implement the method steps described in any one of claims 1 to 3 or claims 4 to 7 when executing the program stored in the memory.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 3 or claims 4 to 7 are implemented.
