Embedded data transmission method and system

By designing an embedded high-concurrency and high-performance data transmission framework, using the separation of receiving threads and worker threads, the problem of low performance in high-concurrency network connection processing in the existing technology is solved, and efficient and stable data transmission is achieved. Resource optimization.

CN115883627BActive Publication Date: 2024-11-29SHANDONG LUNENG SOFTWARE TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211474156.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-22
Publication Date
2024-11-29
Estimated Expiration
2042-11-22

AI Technical Summary

Technical Problem

The prior art has poor performance when handling high-concurrent network connections and cannot support large-concurrent requests and long-connect requests, resulting in wasted system resources.

Method used

An embedded high-concurrency and high-performance data transmission framework is designed, adopting the separation of the receiving thread and the worker thread. By receiving thread, the worker thread receives the client data and writes it to the receiving queue. The worker thread extracts data from the receiving queue for processing. Using IO multiplexing technology and non-blocking IO technology, reduce data replication and resource utilization.

Benefits of technology

It effectively improves the real-time upload and data access reliability of online monitoring of substations and auxiliary equipment monitoring, optimizes the stability and efficiency of data transmission, reduces the use of server and computer room resources, and avoids resource waste.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115883627B_ABST
    Figure CN115883627B_ABST
Patent Text Reader

Abstract

The present invention belongs to the technical field of multi-threaded data transmission, and specifically relates to an embedded data transmission method and system, including: a receiving thread receives data information from a client, writes the received client data information into a receiving queue and stores it; after a working thread receives a receiving thread instruction, it extracts parameter information in the receiving thread instruction, determines the receiving thread to which the receiving queue of the acquired parameter information belongs, and completes data transmission between the receiving thread and the corresponding working thread; wherein, one receiving queue corresponds to one working thread, and one receiving thread corresponds to at least two receiving queues.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of multi-threaded data transmission, and in particular relates to an embedded data transmission method and system. Background Art

[0002] The statements in this section merely provide background information related to the present disclosure and do not necessarily constitute prior art.

[0003] With the rapid development of power Internet and Internet of Things, the number of various smart sensors, electronic devices and mobile terminals used in power systems has increased dramatically, which has also put forward higher performance and concurrency requirements for the background programs of embedded aggregation points in power systems.

[0004] According to the inventors' understanding, currently, the following three solutions are usually used to process concurrent networks:

[0005] (1) IO multiplexing model, which processes multiple connection requests by calling the select function through a single process (not multi-threaded). It can support processing multiple network connection requests at the same time. However, the maximum concurrency is 1024. When the concurrency number is large, the processing performance is low.

[0006] (2) Multi-process model: When a connection request comes in, the main process forks to generate a child process, which is responsible for connecting with the client for data communication. When the client actively closes the connection, the child process ends its operation. Its processing mode is simple and easy to understand. When the connection request is very small, the efficiency is high. However, when there are too many connection requests, system resources are quickly exhausted.

[0007] (3) Multi-threaded mode, start multiple work sites, the main thread is responsible for receiving client connection requests, and the working thread is responsible for communicating with the client. When a connection request comes, the ACCEPT thread puts the socket handle into an array, and the idle thread in the working thread takes a socket handle from the array. The corresponding working thread then connects with the client for data communication. When the client actively closes the connection, the working thread takes the socket handle from the specified array and repeats the operation. Although it can overcome the defect of system resource loss when there are too many connection requests, it cannot support a large number of concurrent requests and a slightly larger number of long connection requests. Summary of the invention

[0008] In order to solve the above problems, the present invention proposes an embedded data transmission method and system, designs an embedded high-concurrency, high-performance data transmission framework, which is applied to the server side to realize the rapid adaptation and access of massive power equipment, smart sensors, smart terminals and other end devices in the smart grid, reduce resource waste, and optimize the data transmission of the power grid.

[0009] According to some embodiments, a first solution of the present disclosure provides an embedded data transmission method, which adopts the following technical solution:

[0010] An embedded data transmission method, comprising:

[0011] The receiving thread receives data information from the client, writes the received client data information into the receiving queue and stores it;

[0012] After receiving the receiving thread instruction, the working thread extracts the parameter information in the receiving thread instruction, determines the receiving thread to which the receiving queue of the acquired parameter information belongs, and completes the data transmission between the receiving thread and the corresponding working thread;

[0013] Among them, one receiving queue corresponds to one working thread, and one receiving thread corresponds to at least two receiving queues.

[0014] As a further technical limitation, in the process of the receiving thread receiving data information from the client, when the client sends a connection request, the receiving thread calls the Accept service to receive the connection request from the client, and distributes it to a receiving thread through the SOCKET-FD in the Accept service. The receiving thread that receives the SOCKET-FD adds the FD to the FD_SET of select for listening, thereby realizing the communication between the receiving thread and the client and completing the receiving thread receiving the data information from the client.

[0015] As a further technical limitation, in order to reduce data duplication, the receiving thread needs to allocate a space from the receiving queue for the data to be received when it starts receiving data; when the receiving thread receives a complete client data message, it sends a message through UNINX-UDP to inform a working thread to extract the corresponding parameter information from the specified receiving queue and process it.

[0016] As a further technical limitation, in the process of writing the received client data information into the receiving queue and storing it, the receiving thread is started, and the readable set is set using epoll. IO multiplexing technology and non-blocking IO technology are applied through epoll. It is determined whether there is an event notification based on the set readable set, and the timeout of the readable set is set according to epoll. When the TCP link times out, the readable set is reset; when there is an event notification, the socket set traversal process is performed; by traversing the socket set, it is determined whether there is data reception. The socket set traversal process is to traverse all sockets managed by the receiving thread. When the traversal is completed and no event is found, the readable set is set back to the setting for the next round of judgment. When a data event is found, data is received; data from each socket is received, and it is determined whether the received data is a complete protocol message. If so, it is put into the receiving message queue of the memory pool technology, and a receiving thread instruction is sent to the working thread. If not, the readable set is set back to the setting for the next round of judgment.

[0017] Furthermore, the receiving queue is a shared resource of multiple threads, uses locking technology, uses an event triggering mechanism in epoll and data receiving queue processing, and uses load balancing technology in the writing process between the receiving thread and the receiving queue of the message.

[0018] Furthermore, a readable set is set, and an agreed timeout period is set. The process is blocked until no message is processed. When a timeout is detected, the timeout processing is performed: the socket link handle is deleted from the epoll queue, and a readable set is set. When a processing notification is received from the receiving thread, the message content is received, the message is analyzed, and then data is retrieved from the specified receiving queue according to the content of the message, and then the data is processed accordingly.

[0019] As a further technical limitation, the receiving thread adopts a load balancing strategy when sending instructions to the working thread.

[0020] According to some embodiments, a second solution of the present disclosure provides an embedded data transmission system, which adopts the following technical solution:

[0021] An embedded data transmission system, comprising:

[0022] A receiving module is configured to receive data information from a client through a receiving thread, write the received client data information into a receiving queue and store it;

[0023] The transmission module is configured to extract parameter information from the receiving thread instruction after the working thread receives the receiving thread instruction, determine the receiving thread to which the receiving queue of the acquired parameter information belongs, and complete the data transmission between the receiving thread and the corresponding working thread;

[0024] Among them, one receiving queue corresponds to one working thread, and one receiving thread corresponds to at least two receiving queues.

[0025] According to some embodiments, a third solution of the present disclosure provides a computer-readable storage medium, which adopts the following technical solution:

[0026] A computer-readable storage medium stores a program, which, when executed by a processor, implements the steps of the embedded data transmission method as described in the first aspect of the present disclosure.

[0027] According to some embodiments, a fourth solution of the present disclosure provides an electronic device, which adopts the following technical solution:

[0028] An electronic device comprises a memory, a processor and a program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps in the embedded data transmission method as described in the first aspect of the present disclosure are implemented.

[0029] Compared with the prior art, the present invention has the following beneficial effects:

[0030] This paper proposes an embedded high-concurrency, high-performance data transmission framework that supports high-concurrency access of data acquisition terminals, effectively improves the real-time upload and data access reliability capabilities of business systems such as substation online monitoring and auxiliary equipment monitoring, and optimizes the uninterrupted and stable data transmission function of business systems. At the same time, it reduces the waste of resources caused by occupying a large amount of server resources and computer room resources, thereby achieving the purpose of optimizing the entire power grid system. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] The accompanying drawings constituting a part of the present disclosure are used to provide a further understanding of the present disclosure. The illustrative embodiments of the present disclosure and their descriptions are used to explain the present disclosure and do not constitute an improper limitation on the present disclosure.

[0032] Figure 1 is a flow chart of the embedded data transmission method in the first embodiment of the present disclosure;

[0033] Figure 2 is a framework diagram of the embedded data transmission method in the first embodiment of the present disclosure;

[0034] Figure 3 is a flowchart of link distribution in the first embodiment of the present disclosure;

[0035] Figure 4 is a flowchart of the Recv thread processing in the first embodiment of the present disclosure;

[0036] Figure 5 is a flowchart of the work thread processing in the first embodiment of the present disclosure;

[0037] Figure 6 It is a structural block diagram of the embedded data transmission system in the second embodiment of the present disclosure. DETAILED DESCRIPTION

[0038] The present disclosure is further described below in conjunction with the accompanying drawings and embodiments.

[0039] It should be noted that the following detailed descriptions are all illustrative and are intended to provide further explanation of the present disclosure. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present disclosure belongs.

[0040] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present disclosure. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.

[0041] In the present disclosure, terms such as "upper", "lower", "left", "right", "front", "back", "vertical", "horizontal", "side", "bottom" and the like indicating directions or positional relationships are based on the directions or positional relationships shown in the accompanying drawings. They are relational words determined only for the convenience of describing the structural relationships of the various parts or elements of the present disclosure, and do not specifically refer to any part or element in the present disclosure and should not be understood as limitations on the present disclosure.

[0042] In the present disclosure, terms such as "fixed connection", "connected", "connection", etc. should be understood in a broad sense, indicating that it can be fixedly connected, integrally connected or detachably connected; it can be directly connected or indirectly connected through an intermediate medium. For relevant scientific research or technical personnel in this field, the specific meanings of the above terms in the present disclosure can be determined according to specific circumstances, and they cannot be understood as limitations on the present disclosure.

[0043] In the absence of conflict, the embodiments in the present disclosure and the features in the embodiments may be combined with each other.

[0044] Embodiment 1

[0045] Embodiment 1 of the present disclosure introduces an embedded data transmission method.

[0046] like Figure 1An embedded data transmission method is shown, comprising:

[0047] The receiving thread receives data information from the client, writes the received client data information into the receiving queue and stores it;

[0048] After receiving the receiving thread instruction, the working thread extracts the parameter information in the receiving thread instruction, determines the receiving thread to which the receiving queue of the acquired parameter information belongs, and completes the data transmission between the receiving thread and the corresponding working thread;

[0049] Among them, one receiving queue corresponds to one working thread, and one receiving thread corresponds to at least two receiving queues.

[0050] In order to improve the concurrency and processing performance, this embodiment adopts Figure 2 The 2-layer design framework shown in the figure is as follows: the first layer consists of receiving threads, which are responsible for receiving client data; the second layer consists of working threads, which are responsible for processing the received data. In order to reduce data duplication and IO operations, the received client data is stored in queues; after receiving the processing instruction, the working thread extracts the corresponding parameters from the instruction to know which thread's queue to get the data from; effectively avoiding competition between working threads; each working thread corresponds to a receiving queue, and each receiving thread only puts the received data in its corresponding queue; when the number of working threads is ≥2*receiving threads, the lock competition between receiving threads can be effectively reduced.

[0051] In this embodiment, the receiving thread adopts the Recv thread.

[0052] When a thread binds a port via TCP, an error will be returned when other threads or processes want to bind the port again. If a Listen socket is added to the select readable set of multiple Recv threads for listening at the same time, a "herd shock" phenomenon will occur: when a new client connection request arrives, all Recv threads will be awakened - this is obviously something that should be avoided. To avoid the "herd shock", this embodiment creates link distribution, as shown in the following example. Figure 3 As shown, when a client connection request comes, the thread calls accept to receive the connection from the client, and then distributes the new SOCKET-FD to a Recv thread. The Recv thread then adds the FD to the FD_SET of select for listening, thereby realizing the communication between the Recv thread and the client.

[0053] "Concurrency" refers to the number of TCP connection requests that the system can accept. "High concurrency" is only a relative concept. For example, some systems have 1K concurrency, while some systems cannot meet the requirements even with 100K concurrency.

[0054] In IO multiplexing, a select function can manage up to FD_SETSIZE (usually 1024) SOCKET sockets. If the concurrency is required to reach 100K, it is obviously much more than the management capacity of 1 select. Therefore, using multiple selects can effectively solve the above problems. 100K is approximately equal to 100*1024, so about 100 selects are required to effectively manage 100K concurrency. Because the management of FD is independent between processes, although the child process will inherit the FD of the parent process when it is created, the FD generated by subsequent connections cannot be inherited by the child process. Therefore, to achieve effective management of 100K concurrency, using multi-threading to achieve high concurrency is an ideal choice.

[0055] Ideally, by starting N receiving threads, the system can handle N*1024 concurrency. However, the more threads there are, the more resources are consumed and the greater the overhead of operating system calls. If the scheduling overhead exceeds the performance improvement brought by multithreading, the system performance will decrease as the number of threads increases. If processing more than 5K requests, multithreading + epoll is the best choice.

[0056] In order to improve the performance of the Recv thread receiving data from the client, its processing process needs to use: IO multiplexing technology, non-blocking IO technology, memory pool technology, locking technology, event triggering mechanism, load balancing strategy, design pattern, etc. Figure 4 As shown, the processing flow of the Recv thread is: start the Recv thread, use epoll to set the readable set, apply IO multiplexing technology and non-blocking IO technology through epoll, determine whether there is an event notification based on the set readable set, set the timeout of the readable set based on epoll, when the TCP link times out, reset the readable set, and perform the socket set traversal process if there is an event notification, and determine whether there is data reception by traversing the socket set. The socket set traversal process is to traverse all sockets managed by this Recv thread. When the traversal is completed and no event is found, return to the set readable set for the next round of judgment. When a data event is found, receive data, and determine whether a complete protocol message is received after receiving the data of each socket. When a complete protocol message is not received, the variable socket set is reset to continue receiving. When a complete protocol message is received, it is placed in the receiving message queue of the memory pool technology and then notifies the working thread.

[0057] Since the receiving message queue is a shared resource of multiple threads, locking technology is used, event triggering mechanism is used in epoll and data receiving queue processing, load balancing technology is used in the writing process between multi-threaded Recv and message queue, and multiple design patterns are used in the entire coding process: abstract factory pattern, singleton pattern, composite pattern, adapter pattern, observer pattern, etc.

[0058] To reduce data duplication, the Recv thread allocates a space for the data to be received from the receiving queue when receiving data. When the Recv thread receives a complete piece of client data, it sends a message through UNINX-UDP to inform a worker thread to take the data from the specified receiving queue for processing. The process of the Recv thread notifying the worker thread requires a load balancing strategy.

[0059] like Figure 5 The processing flow of the working thread shown in the figure is to set a readable set and set an agreed timeout time. It is in a blocked state until no processing message arrives. When a timeout is detected, the timeout processing is performed: the socket link handle is deleted from the epoll queue, and the readable set is set. When there is a processing notification from the Recv thread, it can also be determined that there is new message data to be received. Then, the message content is received, the message is analyzed, and then data is obtained from the specified receiving queue according to the content of the message, and then the data is processed accordingly.

[0060] This embodiment introduces an embedded high-concurrency, high-performance data transmission framework that supports high-concurrency access of data acquisition terminals, effectively improves the real-time upload and data access reliability capabilities of business systems such as substation online monitoring and auxiliary equipment monitoring, and optimizes the uninterrupted and stable data transmission function of business systems. At the same time, it reduces the waste of resources caused by occupying a large amount of server resources and computer room resources, thereby achieving the purpose of optimizing the entire power grid system.

[0061] Embodiment 2

[0062] Embodiment 2 of the present disclosure introduces an embedded data transmission system.

[0063] like Figure 6 An embedded data transmission system shown includes:

[0064] A receiving module is configured to receive data information from a client through a receiving thread, write the received client data information into a receiving queue and store it;

[0065] The transmission module is configured to extract parameter information from the receiving thread instruction after the working thread receives the receiving thread instruction, determine the receiving thread to which the receiving queue of the acquired parameter information belongs, and complete the data transmission between the receiving thread and the corresponding working thread;

[0066] Among them, one receiving queue corresponds to one working thread, and one receiving thread corresponds to at least two receiving queues.

[0067] The detailed steps are the same as those of the embedded data transmission method provided in the first embodiment and will not be repeated here.

[0068] Embodiment 3

[0069] A third embodiment of the present disclosure provides a computer-readable storage medium.

[0070] A computer-readable storage medium stores a program, which, when executed by a processor, implements the steps of the embedded data transmission method as described in the first embodiment of the present disclosure.

[0071] The detailed steps are the same as those of the embedded data transmission method provided in the first embodiment and will not be repeated here.

[0072] Embodiment 4

[0073] A fourth embodiment of the present disclosure provides an electronic device.

[0074] An electronic device comprises a memory, a processor and a program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps in the embedded data transmission method as described in the first embodiment of the present disclosure are implemented.

[0075] The detailed steps are the same as those of the embedded data transmission method provided in the first embodiment and will not be repeated here.

[0076] The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure. For those skilled in the art, the present disclosure may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

[0077] Although the above describes the specific implementation methods of the present disclosure in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present disclosure. Technical personnel in the relevant field should understand that on the basis of the technical solution of the present disclosure, various modifications or variations that can be made by those skilled in the art without creative work are still within the scope of protection of the present disclosure.

Claims

1. An embedded data transmission method, characterized in that: include: The receiving thread receives data information from the client, writes the received client data information into the receiving queue and stores it; In the process of writing the received client data information into the receiving queue and storing it, the receiving thread is started, and the readable set is set using epoll. The IO multiplexing technology and non-blocking IO technology are applied through epoll. It is determined whether there is an event notification according to the set readable set, and the timeout of the readable set is set according to epoll. When the TCP link times out, the readable set is reset; when there is an event notification, the socket set traversal process is performed; by traversing the socket set, it is determined whether there is data reception. The socket set traversal process is to traverse all sockets managed by the receiving thread. When it is traversed, When the history is completed and no event is found, it returns to set the readable set for the next round of judgment. When a data event is found, data is received; data from each socket is received, and it is determined whether the received data is a complete protocol message. If so, it is put into the receiving message queue of the memory pool technology, and a receiving thread instruction is sent to the working thread. If not, it returns to set the readable set for the next round of judgment; the receiving queue is a shared resource of multiple threads, and uses locking technology. The event trigger mechanism is used in epoll and data receiving queue processing, and load balancing technology is used in the writing process between the receiving thread and the message receiving queue; After receiving the receiving thread instruction, the working thread extracts the parameter information in the receiving thread instruction, determines the receiving thread to which the receiving queue of the acquired parameter information belongs, and completes the data transmission between the receiving thread and the corresponding working thread; Among them, one receiving queue corresponds to one working thread, and one receiving thread corresponds to at least two receiving queues.

2. An embedded data transmission method as claimed in claim 1, characterized in that: In the process of the receiving thread receiving data information from the client, when the client sends a connection request, the receiving thread calls the Accept service to receive the connection request from the client, and distributes it to a receiving thread through the SOCKET-FD in the Accept service. The receiving thread that receives the SOCKET-FD adds the FD to the FD_SET of select for listening, thereby realizing the communication between the receiving thread and the client, and completing the receiving thread receiving the data information from the client.

3. An embedded data transmission method as claimed in claim 1, characterized in that: To reduce data duplication, the receiving thread needs to allocate a space from the receiving queue for the data to be received when it starts receiving data; when the receiving thread receives a complete client data message, it sends a message through UNINX-UDP to inform the working thread to extract the corresponding parameter information from the specified receiving queue and process it.

4. An embedded data transmission method as claimed in claim 1, characterized in that: Set the readable set and the agreed timeout. Before no processing message arrives, the working thread is always in a blocked state. When a timeout is detected, perform timeout processing: delete the socket link handle from the epoll queue, set the readable set, and when the processing notification of the receiving thread is received, receive the message content, analyze the message, and then get data from the specified receiving queue according to the content of the message, and then process the data accordingly.

5. An embedded data transmission method as claimed in claim 1, characterized in that: The process in which the receiving thread notifies the working thread needs to adopt a load balancing strategy.

6. An embedded data transmission system, characterized in that: include: A receiving module is configured to receive data information from a client through a receiving thread, write the received client data information into a receiving queue and store it; In the process of writing the received client data information into the receiving queue and storing it, the receiving thread is started, and the readable set is set using epoll. The IO multiplexing technology and non-blocking IO technology are applied through epoll. It is determined whether there is an event notification according to the set readable set, and the timeout of the readable set is set according to epoll. When the TCP link times out, the readable set is reset; when there is an event notification, the socket set traversal process is performed; by traversing the socket set, it is determined whether there is data reception. The socket set traversal process is to traverse all sockets managed by the receiving thread. When it is traversed, When the history is completed and no event is found, it returns to set the readable set for the next round of judgment. When a data event is found, data is received; data from each socket is received, and it is determined whether the received data is a complete protocol message. If so, it is put into the receiving message queue of the memory pool technology, and a receiving thread instruction is sent to the working thread. If not, it returns to set the readable set for the next round of judgment; the receiving queue is a shared resource of multiple threads, and uses locking technology. The event trigger mechanism is used in epoll and data receiving queue processing, and load balancing technology is used in the writing process between the receiving thread and the message receiving queue; The transmission module is configured to extract parameter information from the receiving thread instruction after the working thread receives the receiving thread instruction, determine the receiving thread to which the receiving queue of the acquired parameter information belongs, and complete the data transmission between the receiving thread and the corresponding working thread; Among them, one receiving queue corresponds to one working thread, and one receiving thread corresponds to at least two receiving queues.

7. A computer-readable storage medium having a program stored thereon, characterized in that: When the program is executed by a processor, the steps in the embedded data transmission method according to any one of claims 1 to 5 are implemented.

8. An electronic device comprising a memory, a processor, and a program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps in the embedded data transmission method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Single process contents server device and method based on IO event notification mechanism

    CN101256505A

  • Processing method and system capable of achieving one machine supporting high concurrency

    CN103164256A