IEC104 Protocol Processing Methods and Systems for High Concurrency

By employing I/O multiplexing technology and thread pool optimization at the IEC104 master station, stable communication under high concurrency scenarios was achieved, solving the resource exhaustion and latency problems of the traditional IEC104 master station under high concurrency scenarios, and improving the system's concurrent processing capability and data transmission efficiency.

CN123123320APending Publication Date: 2026-11-17STATE GRID INFORMATION & TELECOMM GRP CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611237851.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-14
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Traditional IEC104 master stations are prone to thread resource exhaustion, frequent context switching, low protocol processing efficiency, slow sliding window response, and unstable heartbeat and retransmission mechanisms in high-concurrency scenarios, resulting in connection jitter, data delay, and packet loss and retransmission storms, making it difficult to meet the requirements of large-scale access, low-latency transmission, and stable operation.

Method used

I/O multiplexing technology is used to uniformly monitor network events on multiple IEC104 links. A message reading thread pool and a data parsing thread pool are established at the IEC104 master station. Message events are monitored through I/O multiplexing, reading tasks are encapsulated and submitted to the thread pool for processing, thereby decoupling message reading and parsing. Priority blocking queues and core thread count configurations are used to optimize thread resource utilization, ensuring stability and efficiency under high concurrency.

Benefits of technology

Significantly reduces thread resource consumption, improves main station access capacity and real-time response capability, ensures stable packet reception without packet loss or delay in high-concurrency scenarios, increases data processing throughput, reduces latency, and ensures correct data timing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123123320A_ABST
    Figure CN123123320A_ABST
Patent Text Reader

Abstract

This application provides a method and system for high-concurrency IEC104 protocol processing. The method includes: establishing a communication connection between the IEC104 master station and the IEC104 slave station; initializing the configuration of the selected I / O multiplexing, the IEC104 message read thread pool, and the IEC104 data parsing thread pool; the I / O multiplexing listens for message events in the IEC104 slave station, and when a message arrives, it encapsulates a read task; it uses an idle read thread in the IEC104 message read thread pool to retrieve a task from the task queue and read it, and after processing, the thread returns to the IEC104 message read thread pool; it uses an idle parsing thread in the IEC104 data parsing thread pool to parse the read message, and after processing, the thread returns to the IEC104 data parsing thread pool; if parsing is successful, the message is converted into standardized data. This solves the problems of unstable communication and excessive latency in IEC104 protocol under high-concurrency architectures.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method and system for processing IEC104 protocol under high concurrency. Background Technology

[0002] IEC 60870-5-104 (IEC 104) is a telemetry communication standard protocol based on Transmission Control Protocol / Internet Protocol (TCP / IP) in the fields of power dispatching, substation automation, and industrial monitoring. It is widely used for critical business interactions such as telemetry, remote signaling, remote control, remote adjustment, sequence of events (SOE) uploading, and general dispatch between the master station and remote terminal units (RTUs), intelligent electronic devices (IEDs), and data transfer units (DTUs). With the rapid development of smart grids, distributed renewable energy, and distribution network automation, master stations need to simultaneously connect to hundreds or thousands of substation nodes, processing high-frequency reporting of massive amounts of measurement data, sudden fault information, and concurrent control commands, forming typical high-concurrency, high-real-time, and high-reliability communication scenarios.

[0003] Traditional IEC104 master stations generally adopt blocking input / output (IO) interfaces and a single-connection, single-threaded mode. Under high-concurrency access, they are prone to problems such as thread resource exhaustion, frequent context switching, low protocol processing efficiency, slow sliding window response, and unstable heartbeat and retransmission mechanisms. This leads to connection jitter, data latency, packet loss and retransmission storms, and decreased system throughput, making it difficult to meet the engineering requirements of large-scale access, low-latency transmission, and stable operation. Therefore, it is urgent to improve the high-concurrency architecture, protocol stack optimization, task scheduling, and link self-healing. Summary of the Invention

[0004] In view of this, the purpose of this application is to propose a method and system for processing the IEC104 protocol under high concurrency, which solves the problems of unstable communication and excessive latency of the IEC104 protocol under high concurrency architecture.

[0005] To achieve one of the above objectives, this application provides a method for processing IEC104 protocols under high concurrency, the method comprising:

[0006] Establish a communication connection between the IEC104 master station and the IEC104 substation; wherein, the IEC104 master station includes an IEC104 message reading thread pool and an IEC104 data parsing thread pool; Based on the operating system, the type of I / O multiplexing is selected, the selected I / O multiplexing is initialized, and the configuration of the IEC104 message read thread pool and the configuration of the IEC104 data parsing thread pool are initialized; wherein, the configuration includes the core thread count and task queue; The I / O multiplexing is used to listen for message events in the IEC104 substation. When a message arrives, a reading task is encapsulated and submitted to the task queue of the IEC104 message reading thread pool. The idle read thread in the IEC104 message read thread pool retrieves a task from the task queue and reads the message. After processing, the thread returns to the IEC104 message read thread pool for reuse. The message read is parsed using an idle parsing thread in the IEC104 data parsing thread pool. After processing is complete, the thread returns to the IEC104 data parsing thread pool for reuse. If the parsing is successful, the message is converted into standardized data and the standardized data is output to the business layer.

[0007] As a further improvement to one embodiment of this application, the initialization of the selected I / O multiplexing includes: Initialize the connection management list in the operating system, which is used to record currently valid connection information; Create an I / O multiplexing instance and configure the event buffer; The method of using the I / O multiplexing to monitor message events in the IEC104 substation, when a message is detected to arrive, encapsulates a reading task, including: Start a single core event loop thread and use the I / O multiplexing thread to continuously monitor I / O events in the instance; When an I / O event is detected, the file descriptors of the detected I / O events are traversed. If the IO event is a read event, it is determined that a message has arrived. At least the file descriptor and connection context of the IO event are encapsulated into a read task, and the read task is submitted to the task queue of the IEC104 message read thread pool.

[0008] As a further improvement to one embodiment of this application, after traversing the file descriptors of the detected IO events when an IO event is detected, the method further includes: If the IO event is an abnormal event, it is determined to be a connection abnormality. The file descriptor of the abnormal event is deleted from the IO multiplexing thread, and the connection resources are released.

[0009] As a further improvement to one embodiment of this application, the initialization of the IEC104 message read thread pool configuration includes: The number of threads in the thread pool is determined based on the number of CPU cores and a preset multiplier. Configure the task queue as a bounded blocking queue.

[0010] As a further improvement to one embodiment of this application, the step of obtaining a task from the task queue and reading the message using an idle read thread in the IEC104 message read thread pool includes: Retrieve a read task from the task queue and verify the connection status of the file descriptor in the read task; In response to a successful connection, message data is read from the file descriptor, and the reading time is recorded. In response to the fact that the reading time has not exceeded the preset timeout, the fragments of the message are spliced ​​together according to the identification information of the message to generate a complete message; The complete message and context information are at least encapsulated into a parsing task, and the parsing task is submitted to the IEC104 data parsing thread pool.

[0011] As a further improvement to one embodiment of this application, the initialization of the configuration of the IEC104 data parsing thread pool includes: Based on the parsing complexity of the message, the parsing throughput is predicted, and the number of threads in the IEC104 data parsing thread pool is determined based on the number of CPU cores and a preset multiplier. Configure the task queue as a priority blocking queue; wherein the priority blocking queue includes the priority order of each type of message.

[0012] As a further improvement to one embodiment of this application, the step of parsing the read message using an idle parsing thread in the IEC104 data parsing thread pool includes: The parsing task of the IEC104 message read thread pool is received, and the type of the message is identified according to the header control field of the message; The messages are sorted according to their priority order. The messages are parsed according to their order.

[0013] As a further improvement to one embodiment of this application, the step of sorting the messages according to the priority order of each type of message includes: According to the frame format of the IEC104 protocol, the message type is divided into I-frame, S-frame and U-frame, with U-frame having the highest processing authority; The step of parsing the message according to the sort order includes: For the U-frame message, the control information in the control field of the message is parsed, the validity of the message is verified, and a link control response is generated; For the message in the S frame, the receiving sequence number of the message is parsed, its continuity and validity are verified, the link sending window status is updated, and the message transmission confirmation is completed. For the message in the I-frame, verify the integrity of the message, parse the application service data unit in the message, extract the service parameters, and encapsulate the parsing result.

[0014] As a further improvement to one embodiment of this application, the step of parsing the read message using an idle parsing thread in the IEC104 data parsing thread pool includes: During the parsing process, if at least one of the following conditions is found in the parsing: format error, incomplete data, or verification failure, the message is marked as invalid and the thread corresponding to the invalid message is released. A timeout is set for each parsing task. If the processing time of a parsing task exceeds the timeout, the parsing is terminated and the timed-out thread is released. In response to an exception occurring while the thread used for parsing is running, the exception thread is destroyed and a new thread is created in the IEC104 data parsing thread pool.

[0015] Based on the same inventive concept, this application also provides a high-concurrency IEC104 protocol processing system, comprising: A module is established to establish a communication connection between the IEC104 master station and the IEC104 substation; wherein, the IEC104 master station includes an IEC104 message reading thread pool and an IEC104 data parsing thread pool. An initialization module is used to select the type of I / O multiplexing based on the operating system, initialize the selected I / O multiplexing, and initialize the configuration of the IEC104 message read thread pool and the configuration of the IEC104 data parsing thread pool; wherein, the configuration includes the core thread count and task queue; The monitoring module is used to monitor message events in the IEC104 substation using the IO multiplexing. When a message arrives, it encapsulates a reading task and submits the encapsulated reading task to the task queue of the IEC104 message reading thread pool. The reading module uses an idle reading thread in the IEC104 message reading thread pool to obtain a task from the task queue and read the message. After processing is completed, the thread returns to the IEC104 message reading thread pool for reuse. The parsing module is used to parse the read message using an idle parsing thread in the IEC104 data parsing thread pool. After processing is completed, the thread returns to the IEC104 data parsing thread pool for reuse. If the parsing is successful, the output module converts the message into standardized data and outputs the standardized data to the service layer.

[0016] Compared to existing technologies, the technical advantages of this application are as follows: By employing I / O multiplexing technology, the main station uniformly monitors network events on multiple IEC104 links, achieving concurrent management of massive connections, significantly reducing thread resource consumption, and substantially improving the main station's access capacity and real-time response capabilities. Furthermore, by using an IEC104 message read thread pool, network data reading and caching are completed asynchronously, avoiding I / O blocking and ensuring stable message reception without packet loss or delay under high-concurrency scenarios. Finally, an IEC104 data parsing thread pool independently completes protocol parsing and logical processing, improving data processing throughput and ensuring correct data timing and lower transmission latency under high concurrency. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in this application or related technologies, the drawings used in the description of the implementation methods or related technologies will be briefly introduced below. Obviously, the drawings described below are only the implementation methods of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 A flowchart illustrating a high-concurrency IEC104 protocol processing method provided in one embodiment of this application; Figure 2 A flowchart of a listening message provided in one embodiment of this application; Figure 3 A flowchart illustrating the use of an IEC104 message read thread pool to read messages is provided as an embodiment of this application; Figure 4 A schematic diagram of a high-concurrency IEC104 protocol processing system provided for another embodiment of this application; Figure 5 This is a schematic diagram of the hardware structure of an electronic device provided for another embodiment of this application. Detailed Implementation

[0019] The present application will now be described in detail with reference to the specific embodiments shown in the accompanying drawings. However, these embodiments do not limit the present application, and any structural, methodological, or functional modifications made by those skilled in the art based on these embodiments are included within the scope of protection of this application.

[0020] It should be noted that, unless otherwise defined, the technical or scientific terms used in the embodiments of this application should have the ordinary meaning understood by those skilled in the art to which this application pertains. The terms "first," "second," and similar terms used in the embodiments of this application do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects.

[0021] In existing technologies, the design schemes for IEC104 master stations mainly include the following: First, an implementation using I / O multiplexing combined with a single connection and single thread is used, allocating a separate thread for each network data read and IEC104 message parsing task. Second, an I / O multiplexing combined with a thread pool processing mode is used, unifying network data read and IEC104 message parsing tasks into a single thread pool. This application focuses on the technical problems of the second scheme. In existing related technologies, most implementations place network data read and IEC104 message parsing within the same thread, without performing layering or pre-scheduling optimization of the above processing flow.

[0022] The existing processing model that uses I / O multiplexing combined with thread pools has the following main technical problems: First, data reading and packet parsing logic are coupled and executed in the same thread, resulting in a significant reduction in data processing efficiency, an increase in business response latency, and ultimately a decrease in overall system throughput. Second, the sliding window, retransmission timer, and heartbeat mechanism of each link are not independently isolated and managed, which makes it easy for single-link anomalies to affect the overall system stability.

[0023] To address the aforementioned problems, this application provides a method for processing the IEC104 protocol under high concurrency, such as... Figure 1 As shown, the method includes the following steps: Step S100: Establish a communication connection between the IEC104 master station and the IEC104 substation; wherein, the IEC104 master station includes an IEC104 message reading thread pool and an IEC104 data parsing thread pool.

[0024] Specifically, the IEC104 master station refers to a device or system that conforms to the IEC 60870-5-104 remote control communication protocol, acts as the master control terminal in a power automation system, establishes communication connections with multiple substation devices, and realizes data interaction and centralized control such as remote signaling, telemetry, remote control, and remote adjustment. A thread pool is a task processing collection consisting of several pre-created and reusable worker threads, used to receive and asynchronously execute tasks such as data reading and message parsing, avoiding frequent thread creation and destruction, and improving the system's concurrent processing capacity and resource utilization.

[0025] Step S200: Select the type of I / O multiplexing based on the operating system, initialize the selected I / O multiplexing, and initialize the configuration of the IEC104 message read thread pool and the IEC104 data parsing thread pool; wherein, the configuration includes the core thread count and task queue.

[0026] Specifically, I / O multiplexing is an I / O processing mechanism that uses a single or small number of threads to simultaneously monitor the I / O event status of multiple network connections, triggering the corresponding processing flow only when a connection has a readable, writable, or abnormal event. This allows for efficient monitoring and management of multiple connections with low system overhead in high-concurrency scenarios. Different operating systems support different I / O multiplexing types. For example, Windows systems support select and Windows Socket Event Select (WSAEventSelect), while Linux systems support select, poll, and epoll. Among these, epoll offers superior performance in high-concurrency, multi-connection scenarios, with no connection limit and higher event triggering efficiency. Therefore, the optimal I / O multiplexing type adapted to the current operating system should be prioritized.

[0027] In one specific implementation, the operating system is Linux, and the I / O multiplexing type is epoll. During epoll initialization, an epoll instance is created. The epoll control function (epoll_ctl) adds, modifies, and deletes the file descriptors to be monitored and their corresponding events (such as read events and exception events) to the instance. The event buffer size is configured to ensure efficient caching of pending I / O events and avoid event loss.

[0028] In one possible implementation of this application, step S200, which initializes the configuration of the IEC104 message read thread pool, includes: Step S210: Determine the number of threads in the thread pool based on the number of CPU cores and the preset multiplier.

[0029] Step S220: Configure the task queue as a bounded blocking queue.

[0030] Specifically, the bounded blocking queue has a configurable capacity and is used to cache read tasks distributed by the I / O multiplexing module to prevent task loss. The number of threads in the thread pool is determined based on the number of CPU cores and a preset multiplier, ensuring that there are enough threads to handle concurrent read tasks and avoid task backlog due to insufficient threads, while also preventing frequent CPU context switching and resource waste due to excessive threads. The capacity of the bounded blocking queue is reasonably configured according to the system concurrency and message transmission rate. When the queue is full, new read tasks will be blocked and wait until there is free space in the queue, preventing system memory overflow due to excessive tasks. At the same time, the blocking mechanism ensures orderly scheduling of tasks and guarantees the stability of task processing.

[0031] In one possible implementation of this application, step S200, initializing the configuration of the IEC104 data parsing thread pool, includes: Step S230: Based on the parsing complexity of the message, predict the parsing throughput, and determine the number of threads in the thread pool based on the number of CPU cores and the preset multiplier.

[0032] Step S240: Configure the task queue as a priority blocking queue; wherein, the priority blocking queue includes the priority order of each type of message.

[0033] Specifically, message parsing is a CPU-intensive task. The number of threads in the thread pool is determined based on the number of CPU cores and a preset multiplier, fully utilizing CPU resources to achieve parallel parsing of multiple messages and improve parsing throughput. Simultaneously, the thread allocation weight is dynamically adjusted based on message parsing complexity (e.g., I-frames contain application data, making parsing more complex than S-frames and U-frames), ensuring sufficient thread resources for complex message parsing tasks. The priority blocking queue can preset a priority order based on message importance, prioritizing critical tasks and preventing ordinary data messages from crowding out critical resources, ensuring real-time response of critical business operations in high-concurrency scenarios. Internally, a priority sorting algorithm ensures that high-priority tasks are acquired by parsing threads first, while low-priority tasks wait in an orderly manner, achieving differentiated task scheduling.

[0034] Step S300: Use IO multiplexing to listen for message events in the IEC104 substation. When a message arrives, encapsulate the reading task and submit the encapsulated reading task to the task queue of the IEC104 message reading thread pool.

[0035] This step utilizes I / O multiplexing technology to achieve efficient listening and I / O event distribution for multiple client connections, providing an event-driven foundation for subsequent message reading.

[0036] In one possible implementation of this application, step S200, which initializes the selected I / O multiplexing, includes: Step S201: Initialize the connection management list in the operating system. The connection management list is used to record currently valid connection information.

[0037] Step S202: Create an I / O multiplexing instance and configure the event buffer.

[0038] Specifically, the connection management list is implemented using a hash table structure. The key is the file descriptor of the substation connection, and the value is the context information of the corresponding connection (including substation device ID, connection status, communication parameters, message sequence number, sliding window configuration, etc.). This facilitates quick querying, modification, and deletion of connection information, enabling centralized management of all valid connections. After creating the I / O multiplexing instance, the size of the event buffer is configured. The buffer is used to store the monitored I / O events. The buffer capacity is reasonably set according to the maximum number of concurrent connections in the system and the event triggering frequency to ensure that it can accommodate all pending events and avoid event overflow. At the same time, an event triggering mode (such as the edge triggering mode of epoll) is set to trigger processing only when the event status changes, reducing invalid event queries and lowering system overhead.

[0039] like Figure 2 As shown, step S300 includes: step S310, starting a single core event loop thread and using an IO multiplexing thread to continuously monitor IO events in the instance.

[0040] Specifically, the I / O multiplexing core function continuously monitors the I / O events in the instance, blocking until an event occurs or a timeout occurs. The core event loop thread is single-threaded and responsible for uniformly monitoring I / O events of all substation connections, avoiding event conflicts and resource contention caused by multi-threaded monitoring. A reasonable timeout can be set for the I / O multiplexing core function (such as epoll_wait) when it blocks. When an I / O event occurs, the function returns an event list, and the core event loop thread performs preliminary judgment and processing of the events, achieving rapid event distribution.

[0041] Step S320: When an IO event is detected, traverse the file descriptors of the detected IO events.

[0042] In step S330, in response to an IO event being a read event, it is determined that an IEC104 message has arrived. At least the file descriptor and connection context of the IO event are encapsulated into a read task, and the read task is submitted to the task queue of the IEC104 message read thread pool. The idle thread in the thread pool is responsible for subsequent message reading, preventing the event loop thread from being blocked by IO operations.

[0043] A single-core event loop thread is used to listen for I / O events, and a message reading thread pool is used to asynchronously process reading tasks. This decouples event listening from I / O operations, avoids the core thread being blocked by I / O, and improves the efficiency of event listening. At the same time, file descriptors and connection contexts are encapsulated as reading tasks, ensuring that the thread pool can quickly obtain connection information when processing tasks, thereby improving the accuracy and efficiency of message reading.

[0044] In one possible implementation of this application, after step S320, the following is included: In step S340, if the IO event is an abnormal event, it is determined to be a connection abnormality. The file descriptor of the abnormal event is deleted from the IO multiplexing thread, and the connection resources are released.

[0045] Specifically, upon detecting a connection anomaly, the file descriptor is immediately removed from the I / O multiplexing instance monitoring list, connection resources are released, and an anomaly log is recorded for troubleshooting. Connection anomalies include situations such as substation-initiated disconnection, network interruption, and packet transmission timeout. After detecting an anomaly through I / O multiplexing, resources related to the connection are quickly cleaned up, including deleting the connection information from the connection management list and releasing the corresponding thread resources, to prevent abnormal connections from consuming system resources and to prevent the anomaly from spreading and affecting other normal connections. The anomaly log must record detailed information such as the time of the anomaly, file descriptor, connection information, and anomaly type to provide data support for subsequent fault location and system optimization.

[0046] In step S400, an idle read thread in the IEC104 message read thread pool is used to obtain a task from the task queue and read the message. After processing is completed, the thread returns to the IEC104 message read thread pool for reuse.

[0047] Specifically, the process utilizes the thread reuse mechanism of the message reading thread pool to achieve parallel reading of messages from multiple clients, resolving issues of IO blocking and thread resource waste, and ensuring the timeliness and integrity of message reading. Idle threads in the thread pool acquire reading tasks and independently execute message reading operations. Multiple threads can simultaneously handle message reading tasks from different substations, significantly improving message receiving efficiency in high-concurrency scenarios. After completing a reading task, a thread returns to the thread pool to wait for the next task, avoiding the resource overhead caused by frequent thread creation and destruction, and improving thread resource utilization.

[0048] In one possible implementation of this application, such as Figure 3 As shown, step S400 includes: Step S410: Obtain a read task from the task queue and verify the connection status of the file descriptor in the read task.

[0049] Specifically, before reading a message, the availability and connection status of the client's connection file descriptor are checked. If a connection error is detected, the read operation is terminated, thread resources are released, and the I / O multiplexing module is notified to remove the connection listener. By checking the connection status in advance, blocking or failure of threads due to connection errors during message reading can be avoided, reducing invalid I / O operations and saving thread resources. If a connection error is detected, in addition to terminating the read operation, the connection management list must be updated synchronously, the abnormal connection information must be deleted, and an error log must be recorded to ensure the reasonable release of system resources.

[0050] In step S420, in response to a normal connection, message data is read from the file descriptor and the reading time is recorded.

[0051] Specifically, combining the edge-triggered mode with I / O multiplexing, a non-blocking read method is used to read packet data from the file descriptor. A read timeout is set to prevent the thread from being blocked for a long time due to network anomalies. The edge-triggered mode triggers a read event only once when a packet arrives, ensuring that the thread can respond to packet reading in a timely manner; the non-blocking read method allows the thread to return immediately when there is no data to read, avoiding the thread being blocked on the read operation; the read timeout is reasonably set according to the network transmission rate and packet size. After the timeout, the read operation is terminated, thread resources are released, the connection is marked as abnormal, and relevant modules are notified to handle it, preventing thread resources from being occupied for a long time.

[0052] In step S430, in response to the fact that the reading time has not exceeded the preset timeout, the message fragments are spliced ​​together according to the message identification information to generate a complete message.

[0053] Specifically, for some packets fragmented due to TCP (Transmission Control Protocol) packet splicing or reassembly, the read data is stored in a temporary buffer. The complete IEC104 packet is then assembled using information such as the packet header length field and frame identifier to verify packet integrity.

[0054] Step S440: At least the complete message and context information are encapsulated into a parsing task, and the parsing task is submitted to the IEC104 data parsing thread pool.

[0055] Specifically, after reading the complete message, the message data, connection context, and other information are encapsulated into a parsing task and submitted to the IEC104 data parsing thread pool. This thread is then released and returns to the thread pool, awaiting the next read task, thus achieving thread reuse. Submitting the parsing task to an independent data parsing thread pool decouples message reading and parsing, allowing the reading and parsing threads to work in parallel, significantly improving the system's data processing efficiency. Furthermore, the return of the reading thread to the thread pool after completing its task further improves thread resource utilization and reduces system overhead.

[0056] In one possible implementation of this application, after step S440, exception handling is also required. If exceptions such as network interruption, read timeout, or incomplete message occur, a detailed exception log is recorded, and connection and thread resources are released to ensure the stable operation of the thread pool. The exception log should include the time of the exception, the exception type, the connection information involved, and related message data to facilitate subsequent troubleshooting; at the same time, the abnormal connections and thread resources are released in a timely manner to avoid resource leaks, ensure that the thread pool can normally receive and process new tasks, and guarantee the stability and reliability of the system.

[0057] In step S500, the idle parsing thread in the IEC104 data parsing thread pool is used to parse the read message. After processing is completed, the thread returns to the IEC104 data parsing thread pool for reuse.

[0058] Specifically, this step decouples and parallelizes message reading and parsing through a data parsing thread pool. Combined with message type-specific parsing, this improves parsing efficiency and accuracy. Idle threads in the data parsing thread pool acquire parsing tasks and independently execute message parsing operations. Multiple parsing threads can handle different parsing tasks simultaneously, achieving parallel parsing of multiple messages and improving parsing throughput. Because message reading and parsing are decoupled, reading threads can continue to receive new messages, while parsing threads focus on message parsing, avoiding read blocking caused by excessive parsing time and further enhancing the system's concurrent processing capabilities.

[0059] In one possible implementation of this application, step S500 further includes: Step S510: Receive the parsing task of the IEC104 message read thread pool and identify the message type based on the message header control field.

[0060] Step S520: Sort the messages according to the priority order of each type of message.

[0061] Step S530: Parse the messages according to the sorting order.

[0062] By identifying message types and parsing them in order of priority, critical messages can be processed first, ensuring real-time response to critical business operations and preventing ordinary messages from crowding out critical resources.

[0063] In one possible implementation of this application, step S520 further includes: Step S521: According to the frame format of the IEC104 protocol, the message type is divided into I-frame, S-frame and U-frame, with U-frame having the highest processing authority.

[0064] Specifically, I-frames, S-frames, and U-frames are the classification methods for messages in the HDLC (High-Level Data Link Control) protocol. I-frames are numbered information transmission formats used to transmit application data. U-frames are unnumbered control function formats used to control link status. S-frames are numbered monitoring function formats used to confirm successful reception of I-frames from the other party.

[0065] Step S530 also includes: Step S531: For the U frame message, parse the control information in the control field of the message, verify the validity of the message, and generate a link control response.

[0066] The results will then need to be fed back to the system's business layer.

[0067] Specifically, the control field of a U frame contains link control commands (start / stop data transmission, test link). During parsing, the command codes in the control field are extracted to identify the specific control functions; at the same time, the format, length and other information of the message are checked to verify the legality of the message.

[0068] Step S532: For the S-frame message, parse the message's received sequence number, verify its continuity and validity, update the link sending window status, and complete the message transmission confirmation.

[0069] Specifically, the control field of an S-frame contains a receive sequence number, used to acknowledge successfully received I-frames. During parsing, the receive sequence number is extracted from the control field, and its continuity and validity are verified. Simultaneously, based on the parsed receive sequence number information, the local transmission status is updated, and all transmitted I-frames with sequence numbers less than the receive sequence number are removed from the transmission buffer, signifying that these messages have been successfully received by the other party.

[0070] Step S533: For I-frame messages, verify the integrity of the message, parse the application service data unit in the message, extract the business parameters, and encapsulate the parsing results.

[0071] Specifically, an I-frame contains application protocol control information and application service data units. During parsing, the start character (0x68) and the application protocol data unit length field are first verified to ensure the integrity of the message structure. Then, the control field in the application protocol control information is parsed to extract the send sequence number and receive sequence number. Next, the application service data unit is parsed to extract key information such as type identifier, variable structure qualifier, transmission reason, and information body. The parsed key information and application data are encapsulated into standardized parsing results for easy submission to the business layer for processing.

[0072] In step S600, if parsing is successful, the message is converted into standardized data and the standardized data is output to the business layer.

[0073] Specifically, after successful parsing, the parsing results are converted into standardized data according to the format agreed upon by the system business layer to ensure that the business layer can quickly identify and process the data. The standardized data includes key content such as application data, message type, connection information, and parsing time. After being output to the business layer, the business layer completes the subsequent business logic processing (such as data display, anomaly alarms, etc.).

[0074] In one possible implementation of this application, the execution of step S500 further includes exception handling and fault tolerance, specifically including: Step S701: During the parsing process, if at least one of the following conditions is found in the parsing: incorrect message format, incomplete data, or failed verification, the message is marked as invalid and the thread corresponding to the invalid message is released.

[0075] Step S702: Set a timeout for each parsing task. If the processing time of a parsing task exceeds the timeout, the parsing is terminated and the timed-out thread is released.

[0076] In step S703, in response to an exception occurring in the thread used for parsing, the exceptioning thread is destroyed and a new thread is created in the IEC104 data parsing thread pool.

[0077] Steps S701-S703 describe three scenarios and their handling methods for unsuccessful parsing. Parsing fails when at least one of the following occurs: incorrect message format, incomplete data, or verification failure; parsing task timeout; or thread execution exception. Steps S701 and S702 indicate that the parsing task itself is abnormal; in these cases, the thread should be released immediately so that it can perform parsing other tasks to avoid excessive delay. Step S703 indicates that the thread itself is abnormal; in this case, the thread should be destroyed immediately, and a new thread should be created to execute the parsing task to ensure the stability of the thread pool.

[0078] In one possible implementation of this application, the beneficial effects of the high-concurrency IEC104 protocol processing method are as follows: By employing I / O multiplexing technology, the master station uniformly listens to network events on multiple IEC104 links, achieving massive connection concurrency management, significantly reducing thread resource consumption, and significantly improving the master station's access capacity and real-time response capability. Furthermore, by using an IEC104 message read thread pool, network data reading and caching are completed asynchronously, avoiding I / O blocking and ensuring stable message reception, no packet loss, and no delay under high-concurrency scenarios. Finally, an IEC104 data parsing thread pool independently completes protocol parsing and logical processing, improving data processing throughput and ensuring correct data timing and lower transmission latency under high concurrency.

[0079] Another embodiment of this application discloses a high-concurrency IEC104 protocol processing system, such as... Figure 4 As shown, it includes: The module establishes a communication connection between the IEC104 master station and the IEC104 substation; the IEC104 master station includes an IEC104 message reading thread pool and an IEC104 data parsing thread pool. The initialization module is used to select the type of I / O multiplexing based on the operating system, initialize the selected I / O multiplexing, and initialize the configuration of the IEC104 message read thread pool and the IEC104 data parsing thread pool; the configuration includes the core thread count and task queue. The listening module is used to listen for message events in the IEC104 substation using IO multiplexing. When a message arrives, it encapsulates a reading task and submits the encapsulated reading task to the task queue of the IEC104 message reading thread pool. The reading module is used to retrieve tasks from the task queue and read messages using idle reading threads in the IEC104 message reading thread pool. After processing is completed, the thread returns to the IEC104 message reading thread pool for reuse. The parsing module is used to parse the read message using an idle parsing thread in the IEC104 data parsing thread pool. After processing is completed, the thread returns to the IEC104 data parsing thread pool for reuse. The output module, if parsing is successful, is used to convert the message into standardized data and output the standardized data to the business layer.

[0080] Figure 5 This diagram illustrates a more specific hardware structure of an electronic device provided in this embodiment. The device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, memory 1020, input / output interface 1030, and communication interface 1040 are interconnected internally via the bus 1050.

[0081] The processor 1010 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0082] The memory 1020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 can store the operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program code is stored in the memory 1020 and is called and executed by the processor 1010.

[0083] The input / output interface 1030 is used to connect input / output modules to realize information input and output. The input / output modules can be configured as components in the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Input devices may include keyboards, mice, touch screens, microphones, various sensors, etc., and output devices may include displays, speakers, vibrators, indicator lights, etc.

[0084] The communication interface 1040 is used to connect the communication module (not shown in the figure) to enable communication between this device and other devices. The communication module can communicate via wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, radio (shortwave / ultra-shortwave) communication, satellite communication, data link communication, etc.).

[0085] Bus 1050 includes pathways for transmitting information between various components of the device, such as processor 1010, memory 1020, input / output interface 1030, and communication interface 1040.

[0086] It should be noted that although the above-described device only shows the processor 1010, memory 1020, input / output interface 1030, communication interface 1040, and bus 1050, in specific implementations, the device may also include other components necessary for normal operation. Furthermore, those skilled in the art will understand that the above-described device may only include the components necessary for implementing the embodiments described in this specification, and need not include all the components shown in the figures.

[0087] The electronic devices described above are used to implement the corresponding high-concurrency IEC104 protocol processing methods in any of the foregoing embodiments, and have the beneficial effects of the corresponding method implementations, which will not be elaborated here.

[0088] Based on the same inventive concept, corresponding to any of the above-described embodiments, this application also provides a non-transitory computer-readable storage medium storing computer instructions for causing the computer to execute the high-concurrency IEC104 protocol processing method as described in any of the above embodiments.

[0089] The computer-readable medium in this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.

[0090] The computer instructions stored in the storage medium of the above embodiments are used to cause the computer to execute the IEC104 protocol processing method for high concurrency as described in any of the above embodiments, and have the beneficial effects of the corresponding method implementation, which will not be repeated here.

[0091] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of this application (including the claims) is limited to these examples; this manner of description is merely for clarity, and those skilled in the art should consider the specification as a whole. Within the framework of this application, the above embodiments or the technical features of different embodiments can also be appropriately combined, the steps can be implemented in any order, and there are many other variations of different aspects of the embodiments of this application as described above, which are not provided in the details for the sake of brevity.

[0092] Additionally, to simplify the description and discussion, and to avoid obscuring the embodiments of this application, the well-known power / ground connections to integrated circuit (IC) chips and other components may or may not be shown in the provided drawings. Furthermore, the apparatus may be shown in block diagram form to avoid obscuring the embodiments of this application, and this also takes into account the fact that the details of the implementation of these block diagram apparatuses are highly dependent on the platform on which the embodiments of this application will be implemented (i.e., these details should be entirely within the understanding of those skilled in the art). While specific details (e.g., circuits) are set forth to describe exemplary embodiments of this application, it will be apparent to those skilled in the art that the embodiments of this application can be implemented without these specific details or with variations thereof. Therefore, these descriptions should be considered illustrative rather than restrictive.

[0093] Although this application has been described in conjunction with specific embodiments thereof, many substitutions, modifications, and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the embodiments discussed.

[0094] The embodiments described herein are intended to cover all such substitutions, modifications, and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made without departing from the spirit and principles of the embodiments described herein should be included within the protection scope of this application.

Claims

1. A method for processing IEC104 protocol under high concurrency, characterized in that, The method includes: Establish a communication connection between the IEC104 master station and the IEC104 substation; wherein, the IEC104 master station includes an IEC104 message reading thread pool and an IEC104 data parsing thread pool; Based on the operating system, the type of I / O multiplexing is selected, the selected I / O multiplexing is initialized, and the configuration of the IEC104 message read thread pool and the configuration of the IEC104 data parsing thread pool are initialized; wherein, the configuration includes the core thread count and task queue; The I / O multiplexing is used to listen for message events in the IEC104 substation. When a message arrives, a reading task is encapsulated and submitted to the task queue of the IEC104 message reading thread pool. The idle read thread in the IEC104 message read thread pool retrieves a task from the task queue and reads the message. After processing is completed, the thread returns to the IEC104 message read thread pool for reuse. The message read is parsed using an idle parsing thread in the IEC104 data parsing thread pool. After processing is complete, the thread returns to the IEC104 data parsing thread pool for reuse. If the parsing is successful, the message is converted into standardized data and the standardized data is output to the business layer.

2. The IEC104 protocol processing method for high concurrency according to claim 1, characterized in that, The initialization of the selected I / O multiplexing includes: Initialize the connection management list in the operating system, which is used to record currently valid connection information; Create an I / O multiplexing instance and configure the event buffer; The method of using the I / O multiplexing to monitor message events in the IEC104 substation, when a message is detected to arrive, encapsulates a reading task, including: Start a single core event loop thread and use the I / O multiplexing thread to continuously monitor I / O events in the instance; When the IO event is detected, the file descriptors of the detected IO events are traversed; In response to the IO event being a read event, it is determined that the message has arrived. At least the file descriptor and connection context of the IO event are encapsulated into the read task, and the read task is submitted to the task queue of the IEC104 message read thread pool.

3. The IEC104 protocol processing method for high concurrency according to claim 2, characterized in that, When an IO event is detected, after traversing the file descriptors of the detected IO events, the process further includes: If the IO event is an abnormal event, it is determined to be a connection abnormality. The file descriptor of the abnormal event is deleted from the IO multiplexing thread, and the connection resources are released.

4. The IEC104 protocol processing method for high concurrency according to claim 1, characterized in that, The initialization of the IEC104 message read thread pool configuration includes: The number of threads in the thread pool is determined based on the number of CPU cores and a preset multiplier. Configure the task queue as a bounded blocking queue.

5. The IEC104 protocol processing method for high concurrency according to claim 1, characterized in that, The step of using an idle read thread from the IEC104 message read thread pool to obtain a task from the task queue and read the message includes: The read task is retrieved from the task queue, and the connection status of the file descriptor in the read task is verified. In response to a successful connection, message data is read from the file descriptor, and the reading time is recorded. In response to the fact that the reading time has not exceeded the preset timeout, the fragments of the message are spliced ​​together according to the identification information of the message to generate a complete message; The complete message and context information are at least encapsulated into a parsing task, and the parsing task is submitted to the IEC104 data parsing thread pool.

6. The IEC104 protocol processing method for high concurrency according to claim 1, characterized in that, The initialization of the IEC104 data parsing thread pool configuration includes: Based on the parsing complexity of the message, the parsing throughput is predicted, and the number of threads in the IEC104 data parsing thread pool is determined based on the number of CPU cores and a preset multiplier. Configure the task queue as a priority blocking queue; wherein the priority blocking queue includes the priority order of each type of message.

7. The IEC104 protocol processing method for high concurrency according to claim 1, characterized in that, The process of parsing the read message using an idle parsing thread in the IEC104 data parsing thread pool includes: The parsing task of the IEC104 message read thread pool is received, and the type of the message is identified according to the header control field of the message; The messages are sorted according to their priority order. The messages are parsed according to their order.

8. The IEC104 protocol processing method for high concurrency according to claim 7, characterized in that, The step of sorting the messages according to their priority order includes: According to the frame format of the IEC104 protocol, the message type is divided into I-frame, S-frame and U-frame, with U-frame having the highest processing authority; The step of parsing the message according to the sort order includes: For the U-frame message, the control information in the control field of the message is parsed, the validity of the message is verified, and a link control response is generated; For the message in the S frame, the receiving sequence number of the message is parsed, its continuity and validity are verified, the link sending window status is updated, and the message transmission confirmation is completed. For the message in the I-frame, verify the integrity of the message, parse the application service data unit in the message, extract the service parameters, and encapsulate the parsing result.

9. The IEC104 protocol processing method for high concurrency according to claim 1, characterized in that, The process of parsing the read message using an idle parsing thread in the IEC104 data parsing thread pool includes: During the parsing process, if at least one of the following conditions is found in the parsing: format error, incomplete data, or verification failure, the message is marked as invalid and the thread corresponding to the invalid message is released. A timeout is set for each parsing task. If the processing time of a parsing task exceeds the timeout, the parsing is terminated and the timed-out thread is released. In response to an exception occurring while the thread used for parsing is running, the exception thread is destroyed and a new thread is created in the IEC104 data parsing thread pool.

10. A high-concurrency IEC104 protocol processing system, characterized in that, The system includes: A module is established to establish a communication connection between the IEC104 master station and the IEC104 substation; wherein, the IEC104 master station includes an IEC104 message reading thread pool and an IEC104 data parsing thread pool. An initialization module is used to select the type of I / O multiplexing based on the operating system, initialize the selected I / O multiplexing, and initialize the configuration of the IEC104 message read thread pool and the configuration of the IEC104 data parsing thread pool; wherein, the configuration includes the core thread count and task queue; The monitoring module is used to monitor message events in the IEC104 substation using the IO multiplexing. When a message arrives, it encapsulates a reading task and submits the encapsulated reading task to the task queue of the IEC104 message reading thread pool. The reading module is used to obtain a task from the task queue and read the message using an idle reading thread in the IEC104 message reading thread pool. After processing is completed, the thread returns to the IEC104 message reading thread pool for reuse. The parsing module is used to parse the read message using an idle parsing thread in the IEC104 data parsing thread pool. After processing is completed, the thread returns to the IEC104 data parsing thread pool for reuse. If the parsing is successful, the output module converts the message into standardized data and outputs the standardized data to the service layer.