Cross-second data alignment with second-level aggregation method and system for network traffic analysis engine

By employing a cross-second detection matrix, K-way merge sort, and a dual-bucket round-robin aggregation mechanism, the uncertainty in data alignment determination in multi-threaded, multi-queue network traffic analysis systems is resolved, achieving low-latency, high-efficiency data alignment and aggregation, suitable for heterogeneous hardware environments.

CN123185101APending Publication Date: 2026-11-27科来网络技术股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611574010.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-12
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies cannot accurately determine whether all data for a specific link in a specific second has arrived in a multi-threaded, multi-queue network traffic analysis system. This results in high memory consumption and high latency, failing to meet the requirements for low-latency DPI/NDR, and is difficult to balance in heterogeneous hybrid deployment scenarios.

Method used

A combined mechanism of cross-second detection matrix, K-way merge sort, dual-bucket round-robin aggregation, and watchdog timeout refresh is adopted. The cross-second detection matrix accurately determines that the data has arrived, K-way merge sort is used to achieve low-latency global time sorting, dual-bucket round-robin aggregation is completed without global lock traversal, and watchdog timeout refresh is used to prevent blocking caused by exceptions.

Benefits of technology

It achieves precise cross-second data alignment in a multi-threaded environment, reduces memory usage and end-to-end latency, ensures data integrity and real-time performance, avoids global avalanche caused by single-point latency, and is adaptable to heterogeneous hybrid hardware environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123185101A_ABST
    Figure CN123185101A_ABST
Patent Text Reader

Abstract

The application discloses a kind of cross-second data alignment and second-level aggregation method and system of network traffic analysis engine, it is related to network data processing technical field, based on the core layered fault-tolerant architecture of packet receiving layer and aggregation layer, including cross-second detection matrix, K-way merge sort, double bucket rotation aggregation and Watchdog timeout strong flush four kinds of combination mechanism, there is strict functional complementation and causal trigger relationship between four kinds of mechanism;The application realizes the real-time tracking of the combination of underlying network card-packet capturing thread state for the first time in DPI engine, breaks the technical prejudice of "unable to obtain underlying hardware state, can only be passive waiting", and opens up a new technical direction for subsequent low-delay DPI / NDR optimization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of network packet processing, network performance optimization, and protocol identification / deep packet inspection, specifically to a method and system for cross-second data alignment and second-level aggregation in a network traffic analysis engine. Background Technology

[0002] In carrier-grade and enterprise-grade network traffic analysis systems, to handle line-rate traffic of 10Gbps or even 100Gbps, multi-queue network interface card (NIC) packet capture (such as DPDK and PF_RING), multi-threaded pluggable analysis pipelines, and flow table aggregation and storage architectures with second-level granularity are commonly used. While multi-NIC and multi-threaded parallel processing improves throughput, it also introduces challenges such as packet out-of-order delivery, cross-second aliasing, and consistency of multi-threaded result convergence. Existing technologies mainly employ the following four types of solutions.

[0003] Represented by DPDK's rte_reorder library are sequence-based reordering and order-preserving schemes, traditional double-buffered parallel result aggregation schemes, multi-threaded stream table aggregation schemes based on message queues, and event time windows and watermark mechanisms in stream processing engines.

[0004] Each of the four approaches has its own characteristics and technical limitations. None of them can accurately determine whether all data for a specific link in a specific second has arrived in a heterogeneous, multi-NIC, multi-threaded environment. The root cause is that none of them can obtain a deterministic signal that all data for the current second has arrived from the underlying packet capture hardware and thread status. They can only passively observe and make empirical guesses at the data flow level, rather than actively tracking and confirming the status of the receiving thread. Therefore, in engineering practice, a conservative latency window strategy is usually forced to be adopted: after receiving data in the Nth second, wait another 1 to 2 seconds before guessing that all data has arrived, and then sort or aggregate it. At line-rate traffic of 10Gbps to 100Gbps, caching the full packet for an extra second means several GB of additional memory overhead, and the end-to-end analysis latency is forced to be higher than the second level, which cannot meet the low-latency DPI / NDR requirements. In addition, when a NIC queue is lagging by hundreds of milliseconds due to uneven load or driver buffering, the fixed latency window is either too large (wasting memory and increasing latency) or too small (data loss), making it difficult to achieve a balance in heterogeneous hybrid deployment scenarios.

[0005] In this technical field, due to the inability to accurately know the packet reception status of the underlying hardware, those skilled in the art, when faced with the problem of second-level aggregation involving multiple threads and queues, can only passively rely on time as the sole reliable criterion, and setting a sufficiently long fixed delay window has become the industry's default engineering practice. This technical bias leads those skilled in the art, when seeking optimization solutions, to instinctively think about how to optimize the size of the waiting window or reduce memory usage during the waiting period, rather than considering tracking the real-time cross-second status of each network card and each packet capture thread, let alone systematically combining active state tracking with lock-free aggregation and exception fallback. Summary of the Invention

[0006] To address the aforementioned problems, this invention proposes a method and system for cross-second data alignment and second-level aggregation in a network traffic analysis engine, achieving the following objectives: Objective 1: In scenarios involving the mixed deployment of multiple network cards, multiple packet capture threads, and heterogeneous packet capture frameworks, how to accurately determine whether all packets in a certain second of a certain link have been collected, thereby ensuring strict cross-second boundaries; Objective 2: How to perform low-latency, low-lock contention global time sorting of multiple out-of-order packets on the receiving side, avoiding the bottleneck of traditional global sorting windows; Objective 3: After multiple analysis threads have completed parallel processing, how to achieve safe aggregation of the flow table results per second without using global lock traversal, and how to trigger aggregation only when all threads have arrived or when there is an abnormal timeout, thus balancing data integrity and real-time performance; Objective 4: When individual analysis threads are delayed or stuck, how to prevent the delay from spreading to the entire pipeline, prevent storage layer avalanche, and at the same time ensure global time ordering between multiple links; Objective 5: How to compress the cache window from the empirical value of several seconds in traditional solutions to a precise two seconds, minimizing memory usage while eliminating end-to-end latency introduced by conservative waiting, and realizing a paradigm shift from passive timeout guessing to proactive deterministic judgment.

[0007] To achieve the above objectives, the present invention adopts the following technical solution: A method for cross-second data alignment and second-level aggregation in a network traffic analysis engine is provided for multi-threaded analysis of link traffic. The link is bound to at least one network interface card (NIC), and each NIC has at least one packet capture queue. Multiple packet capture threads capture packets from the packet capture queues of each NIC. The engine is configured with multiple analysis threads, including fault-tolerant, independent, and mutually redundant threads. The packet receiving layer maintains a two-dimensional cross-second detection state matrix for the link context of each link. The first dimension of the matrix corresponds to the index of the network card in the link, and the second dimension corresponds to the packet capture thread identifier. It performs cross-second determination on the received packet buffer and triggers delivery after the current second has arrived. The packets in the current second are split into multiple ordered packet subsequences according to the two-dimensional dimension of network card index and packet capture thread identifier. Multi-way merge sort is performed on the multiple ordered packet subsequences. The globally ordered packet sequence with increasing timestamp is grouped and delivered according to the preset delivery batch threshold. The last group is marked as a cross-second delivery group to trigger the second boundary. The aggregation layer configures a second-level aggregation module independently for each link. Each analysis thread performs parallel analysis on the received packet groups delivered in strict time order. When the analysis thread processes the cross-second delivery group, it submits the flow table data generated in this second to the second-level aggregation module. Within the second-level aggregation module, different analysis threads are rotated between two aggregation buckets based on the parity indexing mechanism of the second identifier. Fixed slots are pre-allocated within the aggregation bucket according to the global identifier of the analysis thread. The flow table data submitted by each thread is written to the slots in the corresponding aggregation bucket. The atomic counter counts the submitted threads and performs atomic increment until the alignment and delivery are triggered. The second-level timestamp of the submitted data is used to determine if a second jump occurs. If a second jump occurs, the data is forcibly aggregated and delivered to the aggregation buckets that have not yet been output, in ascending order of the second-level timestamp. After resetting, the submitted data is written to the aggregation bucket corresponding to the new second.

[0008] Preferably, a cross-second timestamp record matrix corresponding to the state matrix is ​​maintained, and the cross-second determination includes: The link receives captured packets and reads the packet's second-level timestamp, network card identifier, and packet capture thread identifier; Based on the network interface card (NIC) identifier, query the mapping relationship within the link to obtain the logical index of the NIC in the link; The packet capture thread filtering flag excludes cross-thread packets caused by network card traffic splitting errors; if the second-level timestamp of the network card-packet capture thread combination to which the packet belongs is greater than the cross-second timestamp already recorded for the combination, and the combination has not yet been marked as cross-second, then the combination is marked as cross-second, and the count of cross-second combinations is incremented.

[0009] Preferably, a counter for combinations that have spanned seconds is maintained. When the second-level timestamp of the message buffer corresponding to the combination is greater than the timestamp of the combination that has been recorded across seconds, and the combination has not yet been marked as having spanned seconds, then: Mark this combination as having spanned seconds; Update the combined cross-second timestamp to the current message buffer's second timestamp; Increment the counter for the number of seconds that have already passed.

[0010] Preferably, after delivery is completed in the receiving layer, a progressive reset is performed, including: retaining the combined markers of the next second whose cross-second timestamp is greater than the current processing second identifier of the link, recounting, and clearing the cross-second markers of the remaining combinations.

[0011] Preferably, sorting or non-sorting modes are configured on a per-link basis; in sorting mode, multi-way merging is performed; in non-sorting mode, delivery is done in batches, with the cache only switching at the second mark.

[0012] Preferably, the multi-way merge sort includes: Iterate through all network interface card indices and thread identifiers. If the total number of packets is greater than zero, add the pointer of the first packet to the array of pointers to the first element of the queue, and increment the number of valid paths. When the number of valid paths is greater than zero, the following process is executed repeatedly: Linearly scan the array of pointers to the head element of the queue to determine the packet with the smallest second-level timestamp. Append this packet to the globally sorted result sequence. Locate the original subsequence based on the network card index and packet capture thread identifier corresponding to this packet, and advance the current read position of this path. If there are still messages in the original subsequence, the next message is placed in the corresponding position of the array of pointers to the head element of the queue; otherwise, the position is set to empty.

[0013] Preferably, before writing the flow table data submitted by each thread into the slot in the corresponding aggregation bucket, the following steps are taken: Before entering the critical section, pre-sort the flow table data in the thread output slot according to the stored hash code outside the lock; Locate the target aggregation bucket based on the parity of the second-level timestamp of the submitted data, and read the second-level timestamp currently cached in the target aggregation bucket; If the second-level timestamp of the submitted data is not greater than the most recent aggregate timestamp, then the submitted data is discarded. If the target aggregation bucket is empty, then write the second-level timestamp of the target aggregation bucket as the second-level timestamp of the submitted data. If the second-level timestamp of the submitted data is less than the second-level timestamp currently cached in the target aggregation bucket, then the submitted data is discarded. If the second-level timestamp of the submitted data is greater than the second-level timestamp currently cached in the target bucket, a second skip occurs.

[0014] Preferably, when both aggregation buckets are not empty and both are less than the second-level timestamp of the submitted data, the two aggregation buckets are forcibly aggregated and delivered in ascending order of the second-level timestamp, and the submitted data is accepted after resetting.

[0015] Preferably, the receiving layer periodically calls the timeout detection process of the aggregation layer, including: Read the second-level timestamps of the two aggregation buckets and determine the traversal order based on the second-level timestamps from smallest to largest; For each non-empty aggregation bucket, if the current time exceeds the sum of the second-level time identifier of the aggregation bucket and the preset timeout threshold, verify that the second-level time identifier of the aggregation bucket is still greater than the second identifier of the most recent aggregation. If the verification passes, a forced aggregation delivery is triggered and the timeout reason is recorded. The submitted flow table data in the aggregation bucket is merged and delivered downstream, and the aggregation bucket is reset.

[0016] Preferably, in multi-link deployment scenarios, the second-level aggregation module for each link runs independently. The timing scheduling thread scans the global timing queue of multiple links in ascending order of second-level time identifiers. When it confirms that a timing record for one second has arrived and all smaller seconds have been processed, it notifies the second-level aggregation module of the corresponding link to execute the actual compression task delivery.

[0017] The combination of the four core mechanisms of this invention—the cross-second detection matrix, K-way merge sorting (where K is the total number of network interface card-packet capture thread combinations), dual-bucket round-robin aggregation, and Watchdog timeout refresh—is not an isolated addition to the DPI engine, but rather forms a mutually dependent and synergistic combination under specific technical scenarios. The second-to-second arrival signal output by the cross-second detection matrix is ​​a prerequisite for triggering K-way merge sorting, avoiding invalid sorting before the second boundary is determined; the group delivery after K-way merge sorting provides a precise second boundary trigger signal for downstream analysis threads through the cross-second marker of the last group; the analysis thread only outputs flow table data to the second-level aggregation module at this cross-second marker, thereby compressing the input traffic of the aggregation module to once per second; dual-bucket round-robin aggregation uses second identifier parity index and atomic counting to complete multi-threaded arrival determination without global lock traversal; and Watchdog timeout refresh provides an exception fallback for the deterministic determination of the cross-second detection matrix, preventing single-point delays from causing global pipeline blockage.

[0018] The combination of the four mechanisms produces comprehensive technical effects that a single mechanism cannot achieve: it compresses the memory cache from the traditional multi-second full packet to only two cache buckets for the current second and the next second; it reduces the end-to-end latency from a fixed second-level wait to a dynamic millisecond-level processing; it can still guarantee strict packet time order and second-level statistical integrity at 27Gbps line-rate traffic; and at the same time, it ensures system availability in abnormal scenarios through the Watchdog mechanism.

[0019] In the solution of this invention, if any of the above mechanisms are missing, the entire system will degenerate to the deficient state of the prior art: if a cross-second detection matrix is ​​missing, the system cannot obtain a deterministic arrival signal and will be forced to revert to a conservative delay window, resulting in deterioration of both memory and latency, and the inability to eliminate the uncertainty of the second boundary; if K-way merge sort is missing, the system will either abandon global time order (degenerate to RSS-preserving order) or adopt a global sorting window (facing lock contention and cache contention); if dual-bucket round-robin aggregation is missing, multi-threaded aggregation will require global lock traversal or single-point aggregation threads, and throughput cannot scale linearly with the number of threads; if Watchdog timeout strong refresh is missing, when a network card fails or a thread is stuck, the system will be blocked indefinitely, and availability will be completely lost.

[0020] The deterministic arrival determination of the packet receiving layer and the timeout fallback mechanism of the aggregation layer complement each other in this invention. The cross-second detection matrix of the packet receiving alignment module provides "millisecond-level deterministic arrival triggering under normal traffic", while the Watchdog timeout strong refresh of the second-level aggregation module provides "maximum waiting time guarantee under abnormal traffic or thread blocking". The two fault tolerance layers are independent of each other and serve as backups for each other: even if the packet receiving layer cannot trigger cross-second delivery due to a long period of no packets in a certain network card queue, the aggregation layer can still release bucket resources after the timeout through the Watchdog mechanism; conversely, even if a thread in the aggregation layer is delayed, the packet receiving layer can still continue to process data for subsequent seconds (because the packet receiving alignment module runs independently on a link basis and is not blocked in the aggregation state). This layered fault-tolerant architecture ensures that the system will not be blocked indefinitely under any single point of failure scenario, solving the vulnerability problem of "single point delay leading to global avalanche" in traditional DPI engines from the system architecture level.

[0021] Compared with the prior art, the present invention has the following advantages and beneficial effects: (1) By using a cross-second detection matrix, the time progress of each network card and each packet capture thread is tracked independently. Delivery is only triggered after all network card-thread combinations have crossed the current second. Combined with a progressive reset mechanism, the state of the leading thread is not accidentally cleared to zero, thereby eliminating the uncertainty of the second boundary in normal traffic scenarios and greatly improving the accuracy of downstream analysis results such as second-level traffic statistics and TCP retransmission detection.

[0022] (2) The arrival determination is changed from empirical timeout guessing to active fact confirmation based on physical network card and packet capture thread status. In continuous traffic scenarios, there is no need to rely on human conservative thresholds. The memory cache is compressed from the traditional multi-second full packet to only two cache buckets for the current second and the next second. The end-to-end latency is reduced from a fixed second-level wait to a dynamic millisecond-level wait mainly determined by the hardware queue depth and the time taken to merge processing.

[0023] (3) Taking advantage of the fact that packets captured from the same network card queue by the same packet capture thread are naturally ordered by arrival time, the global sorting is degenerated into K-way merge, which does not require global lock protection and is cache-friendly. In the scenario of extremely small K value, linear scanning is used instead of min-heap to maintain the minimum value of the queue head. It makes full use of the advantages of CPU cache locality and branch prediction. The actual performance is better than the heap implementation and can support ultra-linear traffic.

[0024] (4) Through the triple mechanism of double-bucket rotation, thread slotting and atomic counting, the multi-threaded submission operation is distributed to its respective slot. Only one atomic increment and arrival judgment is performed in the last step. The critical section is extremely short. Before submission, the lock external flow table is pre-sorted to further shorten the critical section. The aggregation throughput expands approximately linearly with the number of analysis threads.

[0025] (5) By using the dual fault tolerance mechanism of forced switching due to second overflow and strong refresh due to watchdog timeout, it is ensured that even if a certain analysis thread is abnormal or the load is uneven, it will not block the data storage of all subsequent seconds, thus avoiding the cascading avalanche of the storage pipeline.

[0026] (6) Through a unified link context abstraction and network card port mapping mechanism, it can simultaneously adapt to DPDK network cards, PF_RING network cards and dedicated acquisition cards, providing a unified second boundary determination and sorting aggregation capability for heterogeneous mixed hardware environments.

[0027] (7) By separating the data plane from the control plane, the multi-link global time-series queue ensures that the compression tasks are executed in strict time order, meeting the needs of cross-link traffic correlation analysis and backtracking query. Attached Figure Description

[0028] To more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of the present invention and should not be considered as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort. In the drawings: Figure 1 This is a diagram illustrating the overall system architecture and data flow of this application; Figure 2 This is a schematic diagram of the cross-second detection matrix structure and state changes in this application; Figure 3 Here is a flowchart of the K-way merge sort process in this application; Figure 4 This is a diagram of the dual-barrel rotary polymerization structure of this application; Figure 5 This is a timing diagram for the progressive reset and Watchdog forced flash in this application; Figure 6This is a complete walkthrough flowchart of an embodiment of this application. Detailed Implementation

[0029] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the embodiments and accompanying drawings. The illustrative embodiments and descriptions of the present invention are only used to explain the present invention and are not intended to limit the present invention.

[0030] Example 1 The network traffic analysis engine in this embodiment, with its cross-second data alignment and second-level aggregation system, mainly comprises two core modules: The packet alignment module is responsible for cross-second detection, multi-second caching, K-way merge sorting, and group delivery. The second-level aggregation module is responsible for dual-bucket rotation, thread-based slot allocation, atomic counting, and Watchdog-based forced flushing.

[0031] The overall system data flow is as follows: Heterogeneous network interface cards (DPDK / PF_RING / dedicated acquisition cards) capture packets through multiple queues and threads, then enter the packet receiving and alignment module. This module performs cross-second detection and multi-path merging and sorting before delivering the packets as analysis tasks. A multi-threaded plug-in pipeline analyzes the packets, and the analysis results are submitted second-by-second to the second-level aggregation module. The second-level aggregation module performs dual-bucket rotation and atomic arrival determination before delivering compression / storage tasks. Finally, strict time ordering across links is ensured through multi-link timing guarantees. Figure 1 As shown.

[0032] The packet receiving alignment module in this embodiment maintains an independent link context for each logical link. This link context records all network interfaces bound to that link and all packet capture threads participating in packet receiving. Key states include: The number of network interface cards (NICs) bound to the link, the total number of packet capture threads, the total number of NIC-thread combinations (i.e., the total number of combinations of all NICs and packet capture threads involved in the link), the current processing second identifier of the link, the current second packet buffer, and the next second packet buffer.

[0033] During initialization, the system establishes a mapping relationship between network interface card (NIC) ports and internal link indices based on the NIC configuration. For each NIC-thread combination, its cross-second timestamp record is initialized to the current time to ensure that cross-second determination starts timing from the first valid packet.

[0034] The packet alignment module in this embodiment maintains a two-dimensional cross-second detection state matrix for the link context of each link. The first dimension of this state matrix corresponds to the logical index of the network interface card (NIC) in the link, and the second dimension corresponds to the packet capture thread identifier. The matrix elements are used to record whether the corresponding NIC-thread combination has crossed the current second, such as... Figure 2As shown. Simultaneously, the system maintains a cross-second timestamp record matrix corresponding to the state matrix, and a cross-second combination counter.

[0035] Whenever a message buffer is received, the packet alignment module performs a cross-second determination process: (1) Read the second-level timestamp, network card identifier, and packet capture thread identifier of the buffer; (2) Query the mapping relationship within the link based on the network card identifier to obtain the logical index of the network card in the link; (3) By filtering out cross-thread packets caused by network card traffic splitting errors through the packet capture thread filter flag, only focus on the packet capture thread data that should be processed by this thread; (4) If the second-level timestamp of the buffer is greater than the cross-second timestamp recorded by the network card-thread combination, and the combination has not yet been marked as having crossed seconds, then mark the combination as having crossed seconds, update the cross-second timestamp of the combination to the current packet timestamp, and increment the cross-second combination counter; (5) When the count of the number of seconds that have been crossed reaches the total number of network card-thread combinations, it is determined that the current second of the link has been received and subsequent delivery is triggered; (6) After delivery is completed, perform a progressive reset: clear the counter for combinations that have crossed seconds, but retain the marks of those combinations that have crossed to the next second (i.e., combinations whose cross-second timestamp is greater than the current processing second identifier of the link still remain in the cross-second state and are re-counted) in order to deal with scenarios where some network cards or threads are ahead while others are lagging behind.

[0036] In this embodiment, the system can accurately track the time progress of each network card and each packet capture thread through this two-dimensional matrix. Only when all threads of all network cards confirm that the current second has passed can it be determined that all packets for that second have arrived.

[0037] The arrival determination in this embodiment is an event-driven deterministic determination: whenever a network interface card-thread combination crosses the current second, the system immediately obtains a definite state increment; when the state matrix reaches full, the system can instantly confirm that the current second has arrived within milliseconds or even microseconds. The progressive reset mechanism ensures that the cross-second state of the leading thread will not be mistakenly cleared to zero after delivery, thereby eliminating the problem of uncertain cross-second boundaries in heterogeneous multi-queue environments under continuous traffic scenarios.

[0038] The packet alignment module in this embodiment executes the following differentiated caching and delivery strategy based on the relationship between the current packet timestamp and the current processing second identifier of the link.

[0039] Non-sorting mode If the message timestamp is equal to the current processing second identifier of the link, it is cached in the current second message cache area. When the number of cached messages exceeds the preset delivery batch size threshold, non-cross-second delivery is triggered. If the message timestamp is the next second after the current processing second of the link, then it is cached in the message cache area for the next second; If the message timestamp is two seconds after the current processing second of the link, the message is first delivered to the current second buffer across the second, and then the message is buffered in the next second message buffer area. If the message timestamp is two seconds later than the current processing second identifier of the link, the current second and the next second buffer are delivered consecutively across seconds. The current processing second identifier of the link is adjusted to the previous second of the message timestamp, and then the message is buffered in the next second's message buffer area.

[0040] Sort mode If the message timestamp is equal to the current processing second identifier of the link, it is cached in the current second message buffer and not delivered immediately; If the message timestamp is the next second after the current processing second of the link, then it is cached in the message cache area for the next second; If the message timestamp is two seconds or later than the current processing second identifier of the link, the current second cache is first globally sorted and delivered, the current processing second identifier of the link is adjusted, and then cached in the next second message cache area.

[0041] This embodiment's dual-buffering structure, combined with multi-second skip processing, ensures that even in scenarios with sudden traffic spikes or significant differences in network interface card queue depth, cross-second packets will not be lost, and the delivery rhythm remains controllable. Since the cross-second detection matrix can accurately determine that all packets have arrived in the current second, the system does not need to rely on a conservative latency window to buffer an additional 1 to 2 seconds of data in continuous traffic scenarios; it only needs to maintain two buffer buckets for the current second and the next second. Furthermore, because the arrival determination is completed instantaneously at the last combined cross-second, triggering delivery immediately, the end-to-end latency of the system under continuous traffic mainly depends on the maximum difference in the actual arrival time of packets (determined by the hardware queue depth) and the processing time of subsequent K-way merge sorting, thereby minimizing both memory usage and end-to-end latency.

[0042] The packet alignment module in this embodiment dynamically selects whether to enable global sorting mode based on link configuration or traffic characteristics.

[0043] The non-sorting mode is suitable for scenarios where packets from the same flow are fixedly distributed to a single network interface card queue by RSS hash. In this case, the packets within the single flow are naturally ordered, and there is no need for global sorting, which can reduce CPU overhead. In this mode, the packet receiving alignment module delivers packets directly according to the batch threshold, and only performs necessary cache switching when the second crosses, without performing global time sorting.

[0044] The sorting mode is suitable for scenarios where there is a single stream across network cards (such as some load balancing scenarios where the same 5-tuple stream is distributed to multiple network card queues) or scenarios that require strict global time order for TCP retransmission detection, latency jitter analysis, and micro-burst detection. In this mode, after the packet receiving alignment module determines that the packets have arrived in the current second, it performs K-way merge sorting to ensure that the packets delivered to the analysis thread are strictly incremented according to the global time.

[0045] This switching is configured on a per-link basis, allowing different links to independently select different modes without affecting each other. The system also supports automatically suggesting mode switching to administrators based on traffic statistics characteristics during operation (such as detecting that the proportion of single-stream cross-NICs exceeds a threshold).

[0046] In this embodiment, when the system enables global sorting mode and determines that the current second has crossed seconds, the packet alignment module performs global time sorting on all packets buffered for that second. The core design of the sorting is based on a key observation: in the DPDK / PF_RING framework, packets received by the same packet capture thread from the same network interface card (NIC) queue are naturally ordered by arrival time. Therefore, global out-of-order sorting only occurs between different NICs or different threads, and the sorting problem can be transformed into a K-way merge of multiple naturally ordered subsequences, such as... Figure 3 As shown.

[0047] The specific steps of K-way merge sort are as follows: Data decomposition involves splitting all packet buffers in the current second into multiple ordered packet subsequences along a two-dimensional dimension of network card index and packet capture thread identifier, with packets within each subsequence maintaining their original order.

[0048] Construct a merge structure, initialize the current read position record for each channel, the total number of packets for each channel, the array of pointers to the head element of each channel, and the original network interface card index and thread identifier record for each channel; traverse all network interface card indices and thread identifiers, if the total number of packets for a channel is greater than zero, put its first packet pointer into the array of pointers to the head element of the queue, and record the corresponding network interface card index and thread identifier, and increment the number of effective channels.

[0049] K-way merging is performed iteratively when the number of valid routes is greater than zero: Linearly scan the array of pointers to the head element to find the packet with the smallest timestamp; append this packet to the global sorting result sequence; locate the original subsequence based on the network card index and thread identifier corresponding to this packet, and advance the currently read position of this route; if the subsequence still has data, push the next packet into the corresponding position in the array of pointers to the head element, and restore the number of valid routes; otherwise, set this position to empty.

[0050] Group delivery divides the sorted total messages into several groups according to a preset batch size threshold. Except for the last group, the remaining groups are marked as non-cross-second delivery groups and delivered directly to the analysis task. The last group is marked as a cross-second delivery group. After delivery, the current processing second identifier of the link is incremented, and the cached data of the next second is promoted to the current second cache.

[0051] The group delivery strategy in this embodiment ensures that the analysis thread can efficiently process sorted messages with a fixed batch size, while the second boundary is accurately notified to the analysis thread by the second-crossing marker of the last group, providing an accurate time trigger signal for subsequent second-level aggregation.

[0052] In this embodiment, an analysis task module is set between the packet alignment module and the second-level aggregation module for analyzing multi-threaded plugins.

[0053] In this embodiment, the analysis task module receives a packet group delivered in strict time sequence and executes a pluggable pipeline. Each analysis thread processes independently without blocking others. The analysis process includes: (1) Phase 1: Execute the capability callbacks of all plugins, perform protocol parsing, flow table maintenance, feature matching, etc.; (2) Phase 2: At the end of each frame, call the frame end cleanup callbacks of all plugins in reverse topology order; (3) Cross-second processing: When processing cross-second delivery groups, each analysis thread outputs the flow table data (active flow and message index of each protocol) generated in this second to the local output structure of the thread.

[0054] For non-second-spanning frames, only the original packet memory references are accumulated in the submission queue; for second-spanning frames, a thread output slot is generated through the aggregation submission construction process, and all flow table data and original packet memory references for the current second are transferred to the thread output slot at once and submitted to the second-level aggregation module.

[0055] In this embodiment, the second-level aggregation module is configured independently for each logical link. It is responsible for collecting the flow table data output by all analysis threads under that link every second, and merging them after confirming that all data has been collected, and then delivering them to the downstream compression task.

[0056] In this embodiment, the second-level aggregation module internally maintains two aggregation buckets. Through an indexing mechanism based on the parity of the second identifier (e.g., using the least significant bit of the second identifier for parity determination), it achieves a natural switch between the current second cache and the next second cache, avoiding read / write conflicts during bucket switching. Figure 4 As shown. Each aggregation bucket contains: The second-level time indicator within the bucket (the current cached time in seconds, initially set to the preset empty bucket indicator value); Count of submitted analysis threads (the number of analysis threads that have been submitted to this bucket). Pre-allocated slot set (fixed slots pre-allocated according to the global identifier of the analysis thread, the number of slots is equal to the total number of analysis threads in this link).

[0057] In this embodiment, after an analysis thread completes one second of analysis, a thread output slot is constructed and the aggregation submission process is invoked. The thread output slot carries all flow table data for that thread in that second, as well as the analysis thread's global identifier and the second-level time identifier. The execution steps of the aggregation submission process are as follows.

[0058] External pre-sorting sorts the various flow table data within the thread's output slots according to their stored hash codes before entering the critical section. This operation only involves data from the current thread, requires no lock protection, and can significantly shorten the length of subsequent critical sections. The sorted flow table data can then be directly merged in an ordered manner during the subsequent merging and delivery phase, reducing merging time.

[0059] Locate and verify the bucket. Based on the parity of the second-level timestamp of the submitted data, locate the target aggregation bucket and read the second-level timestamp currently cached in that bucket: If the second-level timestamp of the submitted data is not greater than the second-level timestamp of the most recent aggregation, it means that the second has already been aggregated and should be discarded directly (late data). If the target bucket is empty (its second-level time identifier is the preset empty bucket identifier value), then the second-level time identifier of the target bucket will be written as the second-level time identifier of the submitted data. If the second-level timestamp of the submitted data is greater than the second-level timestamp currently cached in the target bucket, it indicates a second jump has occurred (e.g., no traffic for a certain second causes the seconds to jump, or a sudden traffic surge causes data to arrive continuously for multiple seconds). In this case, it is necessary to check another aggregation bucket first. If the second-level timestamp of the other bucket is not greater than that of the current bucket, then force aggregation and delivery to the other bucket first, then force aggregation and delivery to the current bucket, and rewrite the new second-level timestamp after resetting; if the second-level timestamp of the submitted data is less than the second-level timestamp currently cached in the target bucket, it indicates that it is more serious late data and is directly discarded.

[0060] There is a boundary case for handling skipped seconds: if both aggregation buckets are not empty and both have a second-level timestamp smaller than the submitted data (e.g., aggregation bucket 0 caches the 10th second, aggregation bucket 1 caches the 11th second, and the submitted data is at the 13th second), then the system will force aggregation and delivery to the two buckets in ascending order of the second-level timestamp, reset them, and then accept the data from the 13th second. This sequential forced aggregation strategy ensures that no data from intermediate seconds will be delayed or lost due to skipped seconds.

[0061] After the thread writes to the slot and verifies that the global identifier of the analysis thread is within the valid range, the thread output slot is moved to the corresponding pre-allocated slot in the target aggregation bucket and the slot is marked as filled.

[0062] Atomic counting and arrival determination: An atomic increment operation is performed on the count of submitted analysis threads in the target aggregation bucket, using a get-release memory order to ensure multi-core cache consistency. If the incremented arrival count reaches the expected total number of analysis threads, it means that the data for this second from all analysis threads in this link has arrived. At this time, the most recent aggregation second identifier is atomically updated, and the arrival merging and delivery process is triggered, merging the data in this bucket and delivering it to the downstream compression task.

[0063] By employing a triple mechanism of least significant second index, thread ID slotting, and atomic counting, the second-level aggregation module achieves accurate multi-threaded arrival determination without using a global lock to traverse all thread data, and the critical section only involves pointer movement and atomic operations.

[0064] In this embodiment, as Figure 5 As shown, the arrival and consolidation delivery process is triggered during arrival determination or forced convergence: (1) Allocate compression task parameters from the object pool; (2) Transfer the data of each pre-allocated slot in the target aggregation bucket to the compression task parameters as a whole, and record the second-level time marker of the bucket; (3) Reset the current aggregation bucket and release resources; (4) The compression task parameters are submitted to the compression task queue, and a record containing the link identifier, bucket type and timestamp is inserted into the multi-link global time-series queue. The time-series queue synchronization lock is used to protect and ensure that the compression tasks between multiple links are also processed in time order. The multi-link time-series guarantee mechanism solves the problem that second-level data from different links may arrive at the compression layer out of order in the multi-link parallel analysis scenario, ensuring the strict time order of the final stored data.

[0065] In this embodiment, in a multi-link deployment scenario, the second-level aggregation module of each link runs independently, and the trigger time for its arrival, merging, and delivery depends on the completion time of each analysis thread in that link. If the compression tasks of each link are directly delivered to a shared downstream compression thread pool, it is possible that the 5-second compression task of link A is executed later than the 6-second compression task of link B, resulting in disordered storage layer time sequence and affecting cross-link traffic correlation analysis and backtracking queries.

[0066] The solution for the multi-link global timing queue in this embodiment is as follows: (1) When the second-level aggregation module of each link triggers the aggregation and delivery, it does not directly deliver the compression task, but first inserts a time sequence record into the multi-link global time sequence queue. This record contains the link identifier, aggregation bucket type (odd / even) and second-level time identifier. (2) The global time-series queue is maintained by an independent time-series scheduling thread, which scans the queue in ascending order of second-level time identifiers; (3) When the timing scheduling thread confirms that the timing record of a certain second has arrived and meets the order requirements (that is, all smaller seconds before the timing record of that second have been processed), it notifies the second-level aggregation module of the corresponding link to execute the actual compression task delivery. (4) Insertion and scanning operations of the time-series queue are protected by a time-series synchronization lock. However, since the lock only involves a very small amount of record insertion and pointer operations (not the copying of the flow table data itself), its impact on system throughput is negligible.

[0067] The essence of this embodiment is to separate the data plane and timing control plane of the compression task: the data plane is merged independently within each link, while the control plane ensures strict ordering across links through a global timing queue. This separation design avoids introducing a global lock on the data plane, thus not sacrificing the lock-free scalability of the aggregation module.

[0068] In this embodiment, when the packet receiving alignment module fails to receive packets (e.g., due to traffic interruption or insufficient memory), it periodically invokes the timeout detection process of the second-level aggregation module on each link as a heartbeat. The execution logic of the timeout detection process is as follows: (1) Read the current second-level time markers of the two aggregation buckets; (2) Determine whether there are non-empty buckets in the two aggregation buckets, and determine the traversal order according to the second-level time identifier from small to large, to ensure that the aggregation buckets are always traversed in time order, and avoid the small seconds being stuck due to the large seconds being brushed first; (3) For each aggregation bucket, read its active second-level time identifier. If the bucket is not empty and the current clock time exceeds the sum of its active second-level time identifier and the preset timeout threshold (i.e. the bucket has been continuously longer than the preset time and still has not been fully completed), then enter the strong refresh judgment. (4) Verify again whether the second-level time indicator of the bucket is still greater than the most recent aggregated second indicator (to prevent duplicate refresh); (5) If it is confirmed that the data has not been scanned, the forced aggregation and delivery process is triggered, the timeout reason is recorded, and the thread data that has arrived in the bucket is forcibly merged and delivered to the downstream. (6) After the forced aggregation is completed, reset the aggregation bucket: restore its second-level time stamp to the preset empty bucket stamp value, clear the count of submitted analysis threads to zero, and wait for the submission in the next second.

[0069] The watchdog mechanism introduces a hard constraint on the maximum waiting time for second-level aggregation. Even if an analysis thread fails to submit in time due to an exception, scheduling delay, or sudden load increase, the data for that second will not block the aggregation and storage of all subsequent seconds indefinitely, thus avoiding the cascading avalanche of the entire analysis-compression-storage pipeline.

[0070] This embodiment constructs a complete low-latency pipeline from out-of-order packet reception to ordered second-level output through the collaboration of the packet alignment module and the second-level aggregation module: the packet reception side uses a cross-second detection matrix to ensure accurate second boundaries, and uses K-way merging to achieve low-overhead global sorting by leveraging the inherent ordering of a single queue; the analysis side performs multi-threaded lock-free parallel analysis, outputting results only across second frames; the aggregation side achieves low-lock second-level aggregation through dual-bucket round-robin, thread-based slotting, and atomic counting, and a watchdog ensures system availability in abnormal scenarios; the storage side ensures that compression tasks are executed in strict time order through multi-link timing guarantees.

[0071] Example 2 Based on Example 1, the system deployment environment of this example is as follows: One logical link (link 0) is bound to two physical network interface cards (NICs): NIC 0 (DPDK driver, 2 RSS queues) and NIC 1 (PF_RING driver, 2 RSS queues). The total number of packet capture threads is four: thread T0 handles queue 0 of NIC 0, thread T1 handles queue 1 of NIC 0, thread T2 handles queue 0 of NIC 1, and thread T3 handles queue 1 of NIC 1. The second-level aggregation module configures four analysis threads (A0 to A3) for this link, with each thread running the plugin pipeline independently. The preset batch size threshold is 256 packets, and the watchdog timeout threshold is 2 seconds. Figure 6 As shown, data detection is performed in stages.

[0072] Phase 1: Packet reception at second 0 and cross-second detection At time T = 0.800 seconds, the cross-second detection matrix status of link 0 is: the current processing second identifier of the link is equal to 0, and the cross-second combination counter is equal to 0. Subsequently, each packet capture thread successively receives the packet buffer of the 1st second (timestamp second-level identifier is 1): When T equals 0.820 seconds, network card 0-T0 receives the first second of the packet. The combined cross-second timestamp is updated from 0 to 1, the cross-second flag is set to yes, and the counter becomes 1. When T equals 0.850 seconds, network card 0-T1 receives the first second of the packet, and the counter becomes 2; When T equals 0.910 seconds, network card 1-T2 receives the first second's message, and the counter becomes 3; When T equals 0.930 seconds, network cards 1-T3 receive the first second's packet, the counter becomes 4, and the total number of network card-thread combinations is reached.

[0073] At this point, the system determines that all packets have arrived in the 0th second of link 0, triggering cross-second delivery. All packets in the current second (0th second) buffer enter the subsequent processing flow. After the delivery is completed, the current processing second identifier of the link is incremented to 1.

[0074] Phase Two: Gradual Reset and Leading / Lagging Thread Scenarios The progressive reset occurs after delivery is complete. The cross-second timestamps of the above four combinations are all 1. Since the current processing second identifier of the link has been updated to 1 after delivery, the cross-second timestamps of all combinations are equal to the current processing second identifier. After the progressive reset, the cross-second markers of all four combinations are restored to no, and the counters are cleared to zero.

[0075] Now consider another scenario: Suppose that network interface cards 0-T0 have received the 3rd second message at T = 1.100 seconds (leading), while network interface cards 1-T3 have only just received the 2nd second message at T = 1.050 seconds (lagging). When the 1st second message arrives and delivery is triggered, the current processing second identifier of the link is updated to 2.

[0076] Network card 0-T0: Cross-second timestamp = 3, Crossed seconds = Yes (2 seconds have passed) Network interface 0-T1: Cross-second timestamp = 2, Crossed seconds = Yes Network Card 1-T2: Cross-second timestamp = 2, Crossed seconds = Yes Network Card 1-T3: Cross-second timestamp = 2, Crossed seconds = Yes After a gradual reset: Network interface card 0-T0: Cross-second timestamp = 3 > current processing second 2 → Retain crossed seconds = Yes, add to counter Network interface 0-T1: Cross-second timestamp = 2 = Current processing second 2 → Clear or not Network Adapter 1-T2: Cross-second timestamp = 2 = Current processing second 2 → Clear or not Network Interface Card 1-T3: Cross-second timestamp = 2 = Current processing second 2 → Clear or not The counter is set to 1. This means that when subsequent network cards 0-T1, 1-T2, and 1-T3 successively cross the 2nd second, the counter only needs to be incremented 3 more times to trigger the 2nd second delivery. The leading state of network cards 0-T0 will not be mistakenly cleared to zero, thus avoiding repeated waiting.

[0077] Phase 3: K-way merge sort process Assuming sorting mode, the buffer receives 800 packets in the 5th second, which can be divided into 4 ordered subsequences according to the network interface card-thread two-dimensional dimension: Subsequence 0 (NIC 0-T0): 200 packets, timestamp range 5.000s ~ 5.180s Subsequence 1 (NIC 0-T1): 200 packets, timestamp range 5.010s ~ 5.190s Subsequence 2 (NIC 1-T2): 200 packets, timestamp range 5.005s ~ 5.185s Subsequence 3 (NIC 1-T3): 200 packets, timestamp range 5.002s ~ 5.182s K-way merging steps: Initialize the array of pointers to the head element: [ptr0→5.000s, ptr1→5.010s, ptr2→5.005s, ptr3→5.002s], effective path count = 4; Minimum value in the first round of scanning: 5.000s minimum value for ptr0 → Output the message, ptr0 advances to the next (5.003s). Minimum value in the second round of scanning: 5.002s minimum for ptr3 → Output the message, ptr3 advances; Minimum value in the third round of scanning: 5.005s is the minimum value for ptr2 → Output the message, ptr2 advances; This process continues until all 800 messages have been output.

[0078] After sorting, group by batch size threshold of 256: Group 1 (messages 0-255): Marked as a non-second-spanning delivery group; Group 2 (messages 256~511): Marked as a non-second-spanning delivery group; Group 3 (messages 512~767): Marked as a non-second-spanning delivery group; Group 4 (messages 768~799): Marked as a cross-second delivery group. After delivery, the current processing second identifier of the link is incremented to 6.

[0079] Phase Four: Submission and Arrival Determination of the Second-Level Aggregation Module Taking the 10th second as an example, the four analysis threads A0~A3 submit their respective thread output slots to the second-level aggregation module at the second-crossing marker. The aggregation bucket uses the second identifier for parity indexing: the 10th second is an even number, corresponding to aggregation bucket 0.

[0080] Before submission, each analysis thread pre-sorts the current second stream table data by hash code outside the lock.

[0081] Submission sequence: T=10.050s: A0 commits → The commit count of bucket 0 increments from 0 atoms to 1; T=10.080s: A2 commits → The commit count of bucket 0 increments from 1 atom to 2; T=10.120s: A1 commits → The commit count of bucket 0 increments from 2 atoms to 3; T=10.150s: A3 commits → The commit count of bucket 0 increments from 3 atoms to 4, reaching the expected total number of analysis threads (4).

[0082] At this point, the merging and delivery are triggered: the data in the four slots of bucket 0 is transferred to the compression task parameters, bucket 0 is reset, and the compression task is delivered to the downstream queue. At the same time, a record (link 0, even-numbered bucket, 10th second) is inserted into the multi-link global time-series queue.

[0083] Phase 5: Watchdog Timeout Forced Refresh Suppose that at the 15th second, analysis thread A2 gets stuck due to an exception, while the other three threads completed their commits before T=15.1s. At this point, the commit count of bucket 1 (where the 15th second is an odd number) is 3, and has never reached 4.

[0084] At T=17.000s, the external heartbeat triggers the tick process of the second-level aggregation module: Read the second-level time stamp of bucket 1 = 15, current wall clock time = 17.000s; Judgment: 17.000s > 15 + 2 seconds timeout threshold → Enter the strong refresh judgment; Verification: The second-level time marker 15 of bucket 1 is greater than the second marker 14 of the most recent aggregation → confirming that it has not been refreshed; Trigger forced aggregation and delivery: merge the data from the 3 slots that have arrived in bucket 1, record the timeout reason as "thread A2 has not committed", and deliver it to the downstream. Reset Bucket 1: The second-level time marker is restored to the empty bucket marker value, and the counter is reset to zero.

[0085] Data from the 16th second (an even number) onwards can be normally entered into bucket 0 for aggregation without being blocked due to the delay in A2.

[0086] Phase Six: Traffic Interruption and Empty Second Scenarios Suppose that at the 20th second, network card 0 stops receiving packets due to a driver failure, while network card 1 continues to receive packets normally.

[0087] The state of the cross-second detection matrix is: Network interface 0-T0, network interface 0-T1: No packets for a long time, the timestamp across seconds remains at 20, whether to keep the cross-second mark; Network cards 1-T2 and 1-T3 are receiving packets normally. The cross-second timestamp has been updated to 21, and the cross-second mark is marked as yes.

[0088] At this point, the cross-second combination counter is 2, which will never reach 4. The packet alignment module will not trigger the cross-second delivery at the 20th second (this is correct: the data from network card 0 has indeed not arrived in full).

[0089] At time T = 22.000, the aggregation layer watchdog detects that the data from the 20th second has been in the bucket for more than 2 seconds, triggering forced aggregation and delivery. At this time, the bucket already contains data from network interface cards 1-T2 and 1-T3 (data from network interface card 0 has never arrived). The system forcibly merges and delivers this part of the data, recording the timeout reason as the cross-second detection matrix not being full.

[0090] The data from the 21st second onwards was then successfully entered into the aggregation bucket. Throughout the entire process, except for the missing data from network interface 0 at the 20th second (which was a physical layer data loss caused by a hardware failure), the system did not experience any blockages, and processing from the 21st second onwards was unaffected.

[0091] This scenario fully illustrates the necessity of a layered fault-tolerant architecture: the cross-second detection matrix of the packet receiving layer provides deterministic arrival triggering under normal traffic, but in hardware failure scenarios, the watchdog of the aggregation layer is needed as a fallback; if either mechanism is missing, the system will either be forced to wait conservatively under normal traffic or be blocked indefinitely under abnormal scenarios.

[0092] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for cross-second data alignment and second-level aggregation in a network traffic analysis engine, used in a network traffic analysis engine for multi-threaded analysis of link traffic, wherein the link is bound to at least one network interface card (NIC), each NIC has at least one packet capture queue, and multiple packet capture threads capture packets from the packet capture queues of each NIC, the engine being configured with multiple analysis threads, characterized in that, include: The packet receiving layer maintains a two-dimensional cross-second detection state matrix for the link context of each link. The first dimension of the matrix corresponds to the index of the network card in the link, and the second dimension corresponds to the packet capture thread identifier. It performs cross-second determination on the received packet buffer and triggers delivery after the current second has arrived. The packets in the current second are split into multiple ordered packet subsequences according to the two-dimensional dimension of network card index and packet capture thread identifier. Multi-way merge sort is performed on the multiple ordered packet subsequences. The globally ordered packet sequence with increasing timestamp is grouped and delivered according to the preset delivery batch threshold. The last group is marked as a cross-second delivery group to trigger the second boundary. The aggregation layer configures a second-level aggregation module independently for each link. Each analysis thread performs parallel analysis on the received packet groups delivered in strict time order. When the analysis thread processes the cross-second delivery group, it submits the flow table data generated in this second to the second-level aggregation module. Within the second-level aggregation module, different analysis threads are rotated between two aggregation buckets based on the parity indexing mechanism of the second identifier. Fixed slots are pre-allocated within the aggregation bucket according to the global identifier of the analysis thread. The flow table data submitted by each thread is written to the slots in the corresponding aggregation bucket. The atomic counter counts the submitted threads and performs atomic increment until the alignment and delivery are triggered. The second-level timestamp of the submitted data is used to determine if a second jump occurs. If a second jump occurs, the data is forcibly aggregated and delivered to the aggregation buckets that have not yet been output, in ascending order of the second-level timestamp. After resetting, the submitted data is written to the aggregation bucket corresponding to the new second.

2. The method for cross-second data alignment and second-level aggregation in a network traffic analysis engine according to claim 1, characterized in that, Maintain a cross-second timestamp record matrix corresponding to the state matrix, wherein the cross-second determination includes: The link receives captured packets and reads the packet's second-level timestamp, network card identifier, and packet capture thread identifier; Based on the network interface card (NIC) identifier, query the mapping relationship within the link to obtain the logical index of the NIC in the link; By filtering out cross-thread packets caused by network card traffic splitting errors using packet capture thread identifiers; If the second-level timestamp of the network card-packet capture thread combination to which the packet belongs is greater than the cross-second timestamp already recorded by the combination, and the combination has not yet been marked as having crossed seconds, then the combination is marked as having crossed seconds, and the count of cross-second combinations is incremented.

3. The method for cross-second data alignment and second-level aggregation in a network traffic analysis engine according to claim 2, characterized in that, Maintain a counter that has spanned seconds. If the second-level timestamp of the message buffer corresponding to the combination is greater than the cross-second timestamp already recorded for the combination, and the combination has not yet been marked as having crossed seconds, then: Mark this combination as having spanned seconds; Update the cross-second timestamp of this combination to the current message buffer's second timestamp; Increment the counter for the number of seconds that have already passed.

4. The method for cross-second data alignment and second-level aggregation in a network traffic analysis engine according to claim 1, characterized in that, After delivery is completed in the receiving layer, a gradual reset is performed, including: retaining the combined flags of the next second whose cross-second timestamp is greater than the current processing second identifier of the link, recounting, and clearing the cross-second flags of the remaining combinations.

5. The method for cross-second data alignment and second-level aggregation in a network traffic analysis engine according to claim 1, characterized in that, Configure sorting or non-sorting modes on a per-link basis; In sorted mode, multi-way merging is performed; in non-sorted mode, delivery is done in batches, with the cache only switching at the second mark.

6. A method for cross-second data alignment and second-level aggregation in a network traffic analysis engine according to claim 1 or 5, characterized in that, The multi-way merge sort includes: Iterate through all network interface card indices and thread identifiers. If the total number of packets is greater than zero, add the pointer of the first packet to the array of pointers to the first element of the queue, and increment the number of valid paths. When the number of valid paths is greater than zero, the following process is executed repeatedly: Linearly scan the array of pointers to the head element of the queue to determine the packet with the smallest timestamp. Append this packet to the global sorting result sequence. Locate the original subsequence based on the network card index and packet capture thread identifier corresponding to this packet, and advance the current read position of this path. If there are still messages in the original subsequence, the next message is placed in the corresponding position of the array of pointers to the head element of the queue; otherwise, the position is set to empty.

7. The method for cross-second data alignment and second-level aggregation in a network traffic analysis engine according to claim 1, characterized in that, Before writing the stream table data submitted by each thread into the slots within the corresponding aggregation bucket, the following steps are included: Before entering the critical section, pre-sort the flow table data in the thread output slot according to the stored hash code outside the lock; Locate the target aggregation bucket based on the parity of the second-level timestamp of the submitted data, and read the second-level timestamp currently cached in the target aggregation bucket; If the second-level timestamp of the submitted data is not greater than the most recent aggregate timestamp, then the submitted data is discarded. If the target aggregation bucket is empty, then write the second-level timestamp of the target aggregation bucket as the second-level timestamp of the submitted data. If the second-level timestamp of the submitted data is less than the second-level timestamp currently cached in the target aggregation bucket, then the submitted data is discarded. If the second-level timestamp of the submitted data is greater than the second-level timestamp currently cached in the target bucket, a second skip occurs.

8. The method for cross-second data alignment and second-level aggregation in a network traffic analysis engine according to claim 7, characterized in that, When both aggregation buckets are not empty and both are less than the second-level timestamp of the submitted data, the two aggregation buckets are forcibly aggregated and delivered in ascending order of the second-level timestamp, and the submitted data is accepted again after resetting.

9. The method for cross-second data alignment and second-level aggregation in a network traffic analysis engine according to claim 1, characterized in that, The receiving layer periodically calls the aggregation layer's timeout detection process, including: Read the second-level timestamps of the two aggregation buckets and determine the traversal order based on the second-level timestamps from smallest to largest; For each non-empty aggregation bucket, if the current time exceeds the sum of the second-level time identifier of the aggregation bucket and the preset timeout threshold, verify that the second-level time identifier of the aggregation bucket is still greater than the second identifier of the most recent aggregation. If the verification passes, a forced aggregation delivery is triggered and the timeout reason is recorded. The submitted flow table data in the aggregation bucket is merged and delivered downstream, and the aggregation bucket is reset.

10. The method for cross-second data alignment and second-level aggregation in a network traffic analysis engine according to claim 1, characterized in that, In multi-link deployment scenarios, the second-level aggregation module for each link runs independently. The timing scheduling thread scans the global timing queue of multiple links in ascending order of second-level time identifiers. When it confirms that a timing record for one second has arrived and all smaller seconds have been processed, it notifies the second-level aggregation module of the corresponding link to execute the actual compression task delivery.

11. A cross-second data alignment and second-level aggregation system for a network traffic analysis engine, characterized in that, include: The packet alignment module is used to maintain a two-dimensional cross-second detection state matrix for the link context of each link and perform cross-second determination on the received packet buffer; This is used to split the packets of the current second into multiple ordered packet subsequences according to the two-dimensional dimension of network card index and packet capture thread identifier, perform multi-way merge sort on the multiple ordered packet subsequences, and group and deliver the globally ordered packet sequence according to the preset delivery batch threshold. The second-level aggregation module is used by each analysis thread to perform parallel analysis on the received packet groups delivered in strict time order. Based on the parity indexing mechanism of the second identifier, it performs round-robin switching between two aggregation buckets. Fixed slots are pre-allocated in the aggregation bucket according to the global identifier of the analysis thread. The flow table data submitted by each thread is written to the slot in the corresponding aggregation bucket. The atomic counter counts the submitted threads and performs atomic increment until the alignment and delivery are triggered.