Multi-threaded data processing method, device, equipment and medium
By controlling the thread in the user-mode protocol stack to obtain the preset key value and calling the standard network interface, combined with the conditional mutex lock, blocking IO operations are implemented, which solves the problem of single-thread limitation in the existing technology and improves the efficiency of multi-threaded data processing. and security.
Patent Information
- Application Number
- CN202311368059.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-20
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2043-10-20
AI Technical Summary
The existing user-mode protocol stack only supports single-threaded processing of network data and cannot be applied to multi-threaded applications. A large number of business code modifications are required when loading the user-mode protocol stack, resulting in high code modification costs and inability to achieve seamless switching, making it impossible to support Blocking IO operations.
By controlling the user-mode protocol stack thread and application thread to obtain the preset key value, calling the standard network interface to create a socket and listening for IO events, using a conditional mutex to implement blocking IO operations, and waking up the application thread to process IO events, it is achieved Multi-threaded data processing.
Application logic can be embedded into the user-mode protocol stack programming framework without modifying the business code, supports multi-threaded concurrency safety, and improves multi-threaded data processing efficiency and performance.
Smart Images

Figure CN117608818B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a multi-threaded data processing method, device, equipment and medium. Background Art
[0002] The user-mode protocol stack generally adopts the "glue bonding" idea to "glue" the interface of the network protocol stack in the operating system to the application program, reducing the number of system calls in the process of copying network data from the network card to the application program, thereby improving data processing performance.
[0003] In the prior art, the idea of the traditional user-mode protocol stack is adopted to process network data, and only a single thread is supported to process the sending and receiving of messages in RTC mode. When loading the user-mode protocol stack, the application business code needs to be modified in large quantities to embed the business logic into the programming framework of the user-mode protocol stack, so as to adapt to the programming model of the user-mode protocol stack. This method makes the application program not only have high code modification costs when using the user-mode protocol stack SDK, but also the single-threaded programming framework of the user-mode protocol stack does not support blocking IO operations, and cannot be applied to application business that needs to support multi-threading. Summary of the invention
[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a multi-threaded data processing method, device, equipment and medium to improve the efficiency of multi-threaded data processing.
[0005] In a first aspect, an embodiment of the present disclosure provides a multi-threaded data processing method, including:
[0006] Control the user state protocol stack thread to obtain a first value of a preset key, and control the application program thread to obtain at least one second value of the preset key;
[0007] The application thread calls a standard network interface to create a socket according to the second value, and binds and monitors IO events of the socket;
[0008] Rewrite the preset function, in response to the application thread blocking and waiting, call the conditional mutex to block the IO operation;
[0009] The user mode protocol stack thread calls the network interface to receive a data packet according to the first value, and calls the conditional mutex corresponding to the data packet to wake up the application thread, so that the application thread traverses and processes the IO event.
[0010] In a second aspect, an embodiment of the present disclosure provides a multi-threaded data processing device, comprising:
[0011] A control module, used to control a user-mode protocol stack thread to obtain a first value of a preset key, and control an application program thread to obtain at least one second value of the preset key;
[0012] A monitoring module, used for the application thread to call a standard network interface according to the second value to create a socket, bind and monitor IO events of the socket;
[0013] A calling module, used for rewriting a preset function, in response to the application thread blocking and waiting, calling a conditional mutex to block the IO operation;
[0014] A processing module is used for the user mode protocol stack thread to call the network interface according to the first value to receive a data packet, and call the conditional mutex corresponding to the data packet to wake up the application thread, so that the application thread traverses and processes the IO event.
[0015] In a third aspect, an embodiment of the present disclosure provides an electronic device, including:
[0016] Memory;
[0017] Processor; and
[0018] Computer programs;
[0019] The computer program is stored in the memory and is configured to be executed by the processor to implement the method as described in the first aspect.
[0020] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the method described in the first aspect.
[0021] In a fifth aspect, an embodiment of the present disclosure further provides a computer program product, which includes a computer program or instructions, and when the computer program or instructions are executed by a processor, the method described in the first aspect is implemented.
[0022] The multi-threaded data processing method, apparatus, device and medium provided by the embodiments of the present disclosure control the user-mode protocol stack thread to obtain the first value of a preset key, and control the application program thread to obtain at least one second value of the preset key, thereby protecting the thread security through one-key-multiple-values; the application program thread calls the standard network interface to create a socket according to the second value, binds and listens to the IO events of the socket, and embeds the business logic into the programming framework of the user-mode protocol stack through the standard network interface, so that the application program loads the user-mode protocol stack without modifying the business code; calls the conditional mutex corresponding to the data packet to wake up the application program thread, so that the multi-threads are scheduled in an orderly and efficient manner, thereby protecting the concurrent security of the multi-threads; the user-mode protocol stack thread calls the network interface to receive the data packet according to the first value, and calls the conditional mutex corresponding to the data packet to wake up the application program thread, so that the application program thread traverses and processes the IO events, thereby realizing the blocking packet receiving logic and improving the efficiency of multi-threaded data processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0024] In order to more clearly illustrate the embodiments of the present invention 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.
[0025] Figure 1 A flow chart of a multi-threaded data processing method provided by an embodiment of the present disclosure;
[0026] Figure 2 A schematic diagram of a standard network interface package provided by an embodiment of the present disclosure;
[0027] Figure 3 A schematic diagram of the structure of a multi-threaded data processing device provided in an embodiment of the present disclosure;
[0028] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0029] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0030] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0031] The user-mode protocol stack generally adopts the "glue bonding" idea to "glue" the interface of the network protocol stack in the operating system to the application program, reducing the number of system calls in the process of copying network data from the network card to the application program, thereby improving data processing performance.
[0032] In the prior art, the idea of the traditional user-mode protocol stack is adopted to process network data, and only a single thread is supported to process the sending and receiving of messages in RTC mode. When loading the user-mode protocol stack, the application business code needs to be modified in large quantities to embed the business logic into the programming framework of the user-mode protocol stack, so as to adapt to the programming model of the user-mode protocol stack. This method makes the application program not only have high code modification costs and cannot achieve seamless switching when using the user-mode protocol stack SDK, but also the single-threaded programming framework of the user-mode protocol stack does not support blocking IO operations and cannot be applied to application business that needs to support multi-threading.
[0033] The defects of the prior art are as follows: Under the single-threaded programming framework of the user-mode protocol stack, the application data processing and the data plane development kit (DPDK) receiving and sending packets are "glued" to the context of a thread. There is no thread lock and a suitable thread scheduling wake-up mechanism, and it can only rely on single-threaded polling to continuously promote the receiving and sending of data packets and data processing. The existing programming model cannot directly connect to the standard socket network interface, cannot implement the blocking IO operation of the select interface, and cannot use multi-threaded application services. In response to this problem, the embodiment of the present disclosure provides a multi-threaded data processing method, which is introduced below in conjunction with a specific embodiment.
[0034] Figure 1 A flowchart of a multi-threaded data processing method provided in an embodiment of the present disclosure. The method can be executed by a multi-threaded data processing device, which can be implemented in software and / or hardware, and can be configured in an electronic device, such as a server or a terminal, wherein the terminal specifically includes a mobile phone, a computer or a tablet computer, etc. In addition, the method can be applied to application scenarios of multi-threaded data processing, and it can be understood that the multi-threaded data processing method provided in an embodiment of the present disclosure can also be applied in other scenarios.
[0035] Below Figure 1 The multi-threaded data processing method shown in the figure is introduced, and the specific steps of the method are as follows:
[0036] S101. Control a user-mode protocol stack thread to obtain a first value of a preset key, and control an application program thread to obtain at least one second value of the preset key.
[0037] Control the user-state protocol stack thread to obtain the first value of the preset key key. The user-state protocol stack thread can be represented by thread0. Control the application thread to obtain at least one second value of the preset key key. The number of application threads is at least one, corresponding to obtaining at least one second value of the preset key key. For the convenience of expression, it will be explained in terms of one application thread in the following, and the application thread can be thread1.
[0038] Optionally, controlling the application thread to obtain at least one second value of the preset key includes: controlling the application thread to call a network interface function of a standard network interface, and obtaining at least one second value of the preset key through a global variable.
[0039] Specifically, the application thread (thread1) calls the network interface function vfus_pthread_create() of the standard network interface, sets proc0+thread1 to the second value of the preset key key, and obtains at least one second value of the preset key key from the global variable curthread in the application thread (thread1).
[0040] S102: The application thread calls a standard network interface to create a socket according to the second value, and binds and monitors IO events of the socket.
[0041] Socket is an abstraction of the endpoint for two-way communication between application processes on different hosts in the network. A socket is one end of the process communication on the network, providing a mechanism for application layer processes to exchange data using network protocols. In terms of its position, the socket is connected to the application process at the top and the network protocol stack at the bottom. It is the interface for the application to communicate through the network protocol and the interface for the application to interact with the network protocol stack.
[0042] The application thread (thread1) calls the standard network interface to create a socket according to the second value of the preset key key, and binds and monitors the IO events of the socket.
[0043] Exemplarily, the application thread (thread1) calls the standard network interface according to the second value of the preset key key, the standard network interface can be socket(), connect(), bind(), creates a socket socket of the TCP server, obtains socketfd, binds socketfd, monitors socket-related IO events through epoll technology, and blocks the application thread (thread1) waiting for the connect operation.
[0044] S103, rewriting a preset function, in response to the application thread blocking and waiting, calling a conditional mutex to block the IO operation.
[0045] Mutex lock: In multitasking, multiple tasks running at the same time may need to access the same resource, so there is such a lock in the thread to restrict access to shared resources. Mutex locks have only two states, locked and unlocked. Emphasize atomicity and uniqueness.
[0046] Condition lock: The condition lock emphasizes conditional waiting. The condition lock will block the current thread until a certain condition is met before continuing to execute.
[0047] The conditional mutex lock is a combination of the above-mentioned mutex lock and the conditional lock. Multiple tasks running at the same time may need to access the same resource. In this case, there is such a lock in the thread to restrict access to shared resources. When a certain condition is met, execution will continue.
[0048] Rewrite the preset function, which may be the epoll_wait() function, and in response to the blocked wait of the application thread (thread1), call the conditional mutex to block the IO operation.
[0049] Exemplarily, the epoll_wait() function is rewritten, thereby rewriting the implementation of the epoll_wait() function, so that the application thread (thread1) calls the conditional mutex to block the IO operation when blocking and waiting.
[0050] S104: The user-mode protocol stack thread calls a network interface according to the first value to receive a data packet, and calls a conditional mutex corresponding to the data packet to wake up the application thread, so that the application thread traverses and processes the IO event.
[0051] The user state protocol stack thread (thread0) calls the network interface to receive a data packet according to the first value, and calls the conditional mutex corresponding to the data packet to wake up the application thread (thread1), so that the application thread (thread1) traverses and processes IO events.
[0052] The disclosed embodiment controls the user-mode protocol stack thread to obtain the first value of a preset key, controls the application program thread to obtain at least one second value of the preset key, and protects the thread security through one-key-multiple-values; the application program thread calls the standard network interface to create a socket according to the second value, binds and listens to the IO events of the socket, and embeds the business logic into the programming framework of the user-mode protocol stack through the standard network interface, and the application program loads the user-mode protocol stack without modifying the business code; calls the conditional mutex corresponding to the data packet to wake up the application program thread, so that multiple threads are scheduled in an orderly and efficient manner, thereby protecting the concurrent security of multiple threads; the user-mode protocol stack thread calls the network interface to receive the data packet according to the first value, and calls the conditional mutex corresponding to the data packet to wake up the application program thread, so that the application program thread traverses and processes the IO events, thereby realizing the blocking packet receiving logic and improving the efficiency of multi-threaded data processing.
[0053] In some embodiments, before controlling the user-state protocol stack thread to obtain a first value of a preset key and controlling the application thread to obtain at least one second value of the preset key, the method further includes: initializing the user-state protocol stack, creating a preset key according to the thread-local storage feature pthread_key_create, the access thread and value of the preset key are one-to-one corresponding, and the access thread includes at least the user-state protocol stack thread and the application thread.
[0054] Initialize the user-mode protocol stack. During the initialization of the user-mode protocol stack of the vfus SDK, create a preset key key according to the feature pthread_key_create of the thread local storage (Thread Local Storage). The data pointed to by the preset key key is called thread private data. The access thread and value of the preset key key are one-to-one corresponding, that is, the values (that is, thread private data) obtained by different threads accessing the preset key key are different, and the access threads include at least the user-mode protocol stack thread and the application thread. Among them, the thread local storage (Thread Local Storage) feature adopts one-key multiple-value (that is, one preset key key corresponds to multiple values) technology, that is, when different threads access the same variable, they are actually accessing different data.
[0055] Exemplarily, when the user-mode protocol stack is initialized, the user-mode protocol stack thread is started, the user-mode protocol stack thread thread0 is initialized, the preset key key is set, the file system interface data (proc0) + the user-mode protocol stack thread data (thread0) are used as parameters, and are set as the first value of the preset key key, and the first value of the preset key key is obtained by the global variable curthread in the user-mode protocol stack thread (thread0). When the application thread (thread1) is created, the network interface function vfus_pthread_create() of the standard network interface created by the application thread is called, the second value of the preset key key is set, and the second value of the preset key key is obtained by the global variable curthread in the application thread (thread1).
[0056] The disclosed embodiment creates a preset key through the thread local storage feature pthread_key_create, solves the impact of curthread global variables on multi-threading, reduces costs, and improves the security of multi-threaded data processing.
[0057] In some embodiments, before the application thread calls the standard network interface to create a socket according to the second value, the method further includes: encapsulating the network interface according to a preset standard to obtain a standard network interface.
[0058] Encapsulate the network interface according to the preset standard to obtain a standard network interface. Figure 2 As shown in the figure, the user-mode protocol stack uses the network interface on the left, such as vfus_socket(), vfus_connect(), vfus_bind(), vfus_accept(), and vfus_recv(); the application uses the standard network interface on the right, such as socket(), connect(), bind(), accept(), and recv(). The network interface on the left is encapsulated and adapted according to the preset standard to obtain the standard network interface on the right, which supports the model of the interface (Application Programming Interface, API) between standard programs.
[0059] The disclosed embodiment encapsulates the network interface according to preset standards to obtain a standard network interface, supports seamless switching through a preload method, and realizes dynamic loading of a software development kit (Software Development Kit, SDK), so that when an application loads a user-mode protocol stack, it can be dynamically plugged in and unloaded without modifying the business code.
[0060] In some embodiments, the user-state protocol stack thread calls the network interface according to the first value to receive a data packet, and calls the conditional mutex corresponding to the data packet to wake up the application thread, so that the application thread traverses and processes the IO event, including: the user-state protocol stack thread calls the network interface according to the first value to receive a connect data packet, verifies the data packet, and stores the data packet to a preset location, and calls the conditional mutex corresponding to the data packet to wake up the application thread; when the application thread is awakened, the application thread traverses and processes the IO event.
[0061] The user-mode protocol stack thread (thread0) calls the network interface according to the first value to receive the connect data packet, verifies the data packet, and stores the data packet in a preset location, which may be the buf of the socket, and calls the conditional mutex corresponding to the data packet to wake up the application thread (thread1); when the application thread (thread1) is awakened, the application thread (thread1) traverses and processes IO events.
[0062] Exemplarily, when the client sends a connect data packet, the user-mode protocol stack thread (thread0) detects the connect data packet, calls the network interface according to the first value to receive the connect data packet, verifies the data packet, stores the data packet in the buf of the socket, and calls the conditional mutex corresponding to the data packet to wake up the waiting application thread (thread1). When the application thread (thread1) is awakened, the application thread (thread1) traverses and processes IO events. The user-mode protocol stack thread (thread0) continues to detect whether there is a data packet.
[0063] Optionally, when the application thread is awakened, after the application thread traverses and processes the IO event, the method further includes: adding the target connection data packet to a listening queue based on the connect data packet being a target connection data packet.
[0064] Specifically, when the application thread (thread1) determines that the connect data packet is a new connection data packet, it determines that the connect data packet is a target connection data packet, adds the target connection data corresponding to the connect data packet to the listening queue, and the application thread (thread1) continues to wait for the corresponding IO event of the receiving socket.
[0065] Optionally, the method also includes: the user-mode protocol stack thread calls the network interface to receive data according to the first value, stores the data in a preset location, and calls the conditional mutex corresponding to the data to wake up the application thread; when the application thread is awakened, the application thread traverses and processes the IO events, and reads the data and processes the data according to the type of the IO event.
[0066] Specifically, the client continues to send data, the user-mode protocol stack thread (thread0) calls the network interface to receive data according to the first value, and stores the data in a preset location, which can be the buf of the socket, and calls the conditional mutex corresponding to the data to wake up the application thread (thread1); when the application thread (thread1) is awakened, the application thread (thread1) traverses and processes IO events, and reads the data in the preset location according to the type of IO event, processes the data and calls the standard network interface to send a response data packet to the client. The application thread (thread1) continues to wait for the corresponding IO event of the socket.
[0067] The disclosed embodiment clarifies the process of the multi-threaded data processing method by specifically describing the communication process between the client and the server, thereby improving the efficiency of the multi-threaded data processing.
[0068] Figure 3 The structure diagram of the multi-threaded data processing device provided in the embodiment of the present disclosure is shown in FIG. The multi-threaded data processing device may be the terminal described in the above embodiment, or the multi-threaded data processing device may be a component or assembly in the terminal. The multi-threaded data processing device provided in the embodiment of the present disclosure may execute the processing flow provided in the embodiment of the multi-threaded data processing method, such as Figure 3 As shown, the multi-threaded data processing device 30 includes: a control module 31, a monitoring module 32, a calling module 33, and a processing module 34; wherein the control module 31 is used to control the user-mode protocol stack thread to obtain a first value of a preset key, and control the application program thread to obtain at least one second value of the preset key; the monitoring module 32 is used for the application program thread to call a standard network interface according to the second value to create a socket, bind and monitor the IO events of the socket; the calling module 33 is used to rewrite the preset function, and in response to the application program thread blocking and waiting, call a conditional mutex to block the IO operation; the processing module 34 is used for the user-mode protocol stack thread to call a network interface according to the first value to receive a data packet, and call a conditional mutex corresponding to the data packet to wake up the application program thread, so that the application program thread traverses and processes the IO events.
[0069] Optionally, the multi-threaded data processing device 30 also includes: an initialization module 35, which is used to initialize the user-state protocol stack, create a preset key according to the thread local storage characteristic pthread_key_create, and the access thread and value of the preset key are one-to-one corresponding, and the access thread includes at least the user-state protocol stack thread and the application thread.
[0070] Optionally, the control module 31 is further used to control the application thread to call the network interface function of the standard network interface, and obtain at least one second value of the preset key through a global variable.
[0071] Optionally, the multi-threaded data processing device 30 further includes: a packaging module 36, which is used to package the network interface according to a preset standard to obtain a standard network interface.
[0072] Optionally, the processing module 34 is also used for the user-mode protocol stack thread to call the network interface according to the first value to receive a connect data packet, verify the data packet, store the data packet to a preset location, and call the conditional mutex corresponding to the data packet to wake up the application thread; when the application thread is awakened, the application thread traverses and processes the IO events.
[0073] Optionally, the multi-threaded data processing device 30 further includes: an adding module 37, configured to add the target connection data to the listening queue based on the connect data packet being a target connection data packet.
[0074] Optionally, the processing module 34 is also used for the user-mode protocol stack thread to call the network interface to receive data according to the first value, store the data in a preset location, and call the conditional mutex corresponding to the data to wake up the application thread; when the application thread is awakened, the application thread traverses and processes the IO events, and reads the data according to the type of the IO event, and processes the data.
[0075] Figure 3 The multi-threaded data processing device of the illustrated embodiment can be used to execute the technical solution of the above-mentioned multi-threaded data processing method embodiment. Its implementation principle and technical effect are similar and will not be repeated here.
[0076] Figure 4 Schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. The electronic device may be a terminal as described in the above embodiment. The electronic device provided in an embodiment of the present disclosure may execute the processing flow provided in an embodiment of the multi-threaded data processing method, such as Figure 4As shown, the electronic device 40 includes: a memory 41, a processor 42, a computer program and a communication interface 43; wherein the computer program is stored in the memory 41 and is configured so that the processor 42 executes the multi-threaded data processing method as described above.
[0077] In addition, an embodiment of the present disclosure further provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor to implement the multi-threaded data processing method described in the above embodiment.
[0078] In addition, an embodiment of the present disclosure further provides a computer program product, which includes a computer program or instructions, and when the computer program or instructions are executed by a processor, the multi-threaded data processing method as described above is implemented.
[0079] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0080] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0081] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0082] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device:
[0083] Control the user state protocol stack thread to obtain a first value of a preset key, and control the application program thread to obtain at least one second value of the preset key;
[0084] The application thread calls a standard network interface to create a socket according to the second value, and binds and monitors IO events of the socket;
[0085] Rewrite the preset function, in response to the application thread blocking and waiting, call the conditional mutex to block the IO operation;
[0086] The user mode protocol stack thread calls the network interface to receive a data packet according to the first value, and calls the conditional mutex corresponding to the data packet to wake up the application thread, so that the application thread traverses and processes the IO event.
[0087] In addition, the electronic device can also execute other steps in the multi-threaded data processing method as described above.
[0088] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0089] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0090] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit does not, in some cases, limit the unit itself.
[0091] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0092] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0093] 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.
[0094] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A multi-threaded data processing method, characterized in that: The method comprises: Control the user state protocol stack thread to obtain a first value of a preset key, and control the application program thread to obtain at least one second value of the preset key; Encapsulate the network interface according to the preset standard to obtain a standard network interface; The application thread calls the standard network interface to create a socket according to the second value, and binds and monitors IO events of the socket; Rewrite the preset function, in response to the application thread blocking and waiting, call the conditional mutex to block the IO operation; The user mode protocol stack thread calls the network interface to receive a data packet according to the first value, and calls a conditional mutex corresponding to the data packet to wake up the application thread, so that the application thread traverses and processes the IO event.
2. The method according to claim 1, characterized in that Before controlling the user mode protocol stack thread to obtain the first value of the preset key and controlling the application program thread to obtain at least one second value of the preset key, the method further includes: Initialize the user state protocol stack, create a preset key according to the characteristic pthread_key_create of thread local storage, the access thread and value of the preset key are one-to-one corresponding, and the access thread includes at least the user state protocol stack thread and the application thread.
3. The method according to claim 1, characterized in that Controlling the application thread to obtain at least one second value of the preset key includes: The application program thread is controlled to call a network interface function of a standard network interface, and obtain at least one second value of the preset key through a global variable.
4. The method according to claim 1, characterized in that The user state protocol stack thread calls the network interface to receive a data packet according to the first value, and calls a conditional mutex corresponding to the data packet to wake up the application thread, so that the application thread traverses and processes the IO event, including: The user mode protocol stack thread calls the network interface according to the first value to receive a connect data packet, verifies the data packet, stores the data packet in a preset location, and calls a conditional mutex corresponding to the data packet to wake up the application thread; When the application thread is awakened, the application thread traverses and processes the IO events.
5. The method according to claim 4, characterized in that When the application thread is awakened, after the application thread traverses and processes the IO event, the method further includes: Based on the connect data packet being a target connection data packet, the target connection data packet is added to the listening queue.
6. The method according to claim 5, characterized in that The method further comprises: The user mode protocol stack thread calls the network interface to receive data according to the first value, stores the data in a preset location, and calls a conditional mutex corresponding to the data to wake up the application thread; When the application thread is awakened, the application thread traverses and processes the IO events, and reads and processes the data according to the type of the IO event.
7. A multi-threaded data processing device, characterized in that: The device comprises: A control module, used to control a user-mode protocol stack thread to obtain a first value of a preset key, and control an application program thread to obtain at least one second value of the preset key; The encapsulation module is used to encapsulate the network interface according to the preset standard to obtain a standard network interface; A monitoring module, used for the application thread to call the standard network interface to create a socket according to the second value, and bind and monitor IO events of the socket; A calling module, used for rewriting a preset function, in response to the application thread blocking and waiting, calling a conditional mutex to block the IO operation; A processing module is used for the user mode protocol stack thread to call the network interface to receive a data packet according to the first value, and call the conditional mutex corresponding to the data packet to wake up the application thread, so that the application thread traverses and processes the IO event.
8. An electronic device, characterized in that: include: Memory; processor; as well as Computer programs; The computer program is stored in the memory and is configured to be executed by the processor to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
