A method and apparatus for detecting channel anomalies in Go programs based on deadlock risk graphs
By constructing a three-dimensional deadlock risk map and implementing lightweight data collection and risk assessment, the accuracy problem of Go program channel anomaly detection under high-concurrency big data computing nodes was solved, and efficient blocking source location and system recovery were achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-03
- Publication Date
- 2026-04-03
AI Technical Summary
Existing technologies lack the accuracy for dynamic adjustment of channel anomaly detection in Go programs under high-concurrency big data computing node scenarios. They are also unable to build a channel operation dependency network across different levels of coroutines in real time, resulting in a high false negative rate and an inability to locate the source of the blockage.
By using a deadlock risk graph-based approach, lightweight data collection is implemented to conduct asymmetric read/write risk assessment, circular wait chain risk assessment, and blocking/leakage risk assessment, thereby constructing a three-dimensional deadlock risk graph and enabling abnormal channel detection in Go programs.
It improves the dynamic adjustment accuracy of Go program channel anomaly detection in high-concurrency big data computing node scenarios, reduces CPU overhead and memory usage, shortens system recovery time, and improves detection efficiency and the effectiveness of preventive measures.
Smart Images

Figure CN121255488B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of program data anomaly detection and processing technology, and in particular to a method and apparatus for detecting channel anomalies in Go programs based on deadlock risk graphs. Background Technology
[0002] With the widespread adoption of Go programs in infrastructure, frequent inter-service communication exacerbates the risk of service avalanche caused by deadlocks. For applications requiring high timeliness and real-time performance, the downtime losses caused by deadlocks are substantial.
[0003] Existing technologies primarily rely on Go runtime's basic deadlock detection, static code analysis tools, third-party dynamic detection libraries, and resource allocation models from graph theory. However, these methods have significant limitations: the Go runtime can only capture global deadlocks, static tools cannot cover runtime dependencies, traditional graph models struggle to model the dynamic behavior of Go channels (such as buffer adjustments and cross-goroutine nesting), and distributed deadlock detection is constrained by network state consistency. The deadlock risk graph technology was proposed precisely to overcome these limitations—by dynamically constructing a dependency graph between channels and goroutines, it quantifies local deadlock risks in real time, achieving a leap from "passive detection" to "active prediction."
[0004] For example, the invention patent announcement CN117473504B discloses a Go program channel blocking detection method and device based on channel operation priority, which includes: a Go program channel operation priority calculation module; a channel operation priority instrumentation module; a channel operation blocking detection module; and identifies and calculates the Go program channel operation priority, inserts a scheduler based on the Go program channel operation priority, and performs fuzzy testing of the instrumentation-based directional region.
[0005] For example, the invention patent announcement CN116974649B, which describes a method and apparatus for automatic deployment and chaos testing of a blockchain based on Go language and ChaosBlade, includes: preparing a unified custom environment configuration file, reading the configuration file, and creating a blockchain; after the blockchain is created, importing the ethclient package of Go language and calling API functions, then automatically detecting the created blockchain and returning the detection results; creating a node failure simulation scheme through the configuration file, reading the failure simulation scheme, and calling ChaosBlade to perform failure simulation; during blockchain failure simulation, automatically generating a report by detecting and testing the blockchain's operating status.
[0006] However, in the process of implementing the inventive technical solution in the embodiments of this application, it was found that the above-mentioned technology has at least the following technical problems:
[0007] In existing technologies, high-frequency, large-volume data computation in common distributed edge computing nodes requires the coordination of thousands of concurrent channels via Go goroutines, such as market data reception → risk control filtering → price matching → settlement channels, to achieve millisecond-level latency response. However, current technology faces three core defects: dependency chain tracing failure: at throughputs of millions of messages per second, it is impossible to build a cross-level goroutine channel operation dependency network in real time; difficulty in distinguishing between local deadlock risks and reasonable blocking, resulting in an extremely high false negative rate; and a lack of ability to dynamically generate deadlock risk maps, making it impossible to locate the source of blocking when hidden parts are paralyzed. There is also the problem of insufficient accuracy in Go program channel anomaly detection for dynamically adjusting in high-concurrency, large-volume computing node scenarios. Summary of the Invention
[0008] This application provides a method and apparatus for detecting Go program channel anomalies based on deadlock risk graphs. This solves the problem in the prior art where the accuracy of dynamic adjustment in Go program channel anomaly detection is insufficient in high-concurrency big data computing node scenarios, and achieves the effect of improving the accuracy of dynamic adjustment in Go program channel anomaly detection in high-concurrency big data computing node scenarios.
[0009] This application provides a method for detecting Go program channel anomalies based on a deadlock risk graph, comprising the following steps: During Go program execution, lightweight data acquisition is performed to obtain raw Go program channel data; deadlock risk pattern classification and assessment are performed based on the raw Go program channel data, including asymmetric read / write risk assessment, circular wait chain risk assessment, and blocking / leakage risk assessment; a first detection of Go program channel anomalies is performed based on the assessment results; a three-dimensional deadlock risk graph is constructed based on the assessment results; and a second detection of Go program channel anomalies is performed based on the three-dimensional deadlock risk graph.
[0010] This application provides a Go program channel anomaly detection device based on a deadlock risk graph, including a lightweight Go program data acquisition module, a first assessment and detection module for Go program channel anomalies, a module for constructing a three-dimensional deadlock risk graph, and a second assessment and detection module for Go program channel anomalies: The lightweight Go program data acquisition module is used to perform lightweight data acquisition during Go program runtime to obtain raw Go program channel data; the first assessment and detection module for Go program channel anomalies is used to perform deadlock risk pattern classification and assessment based on the raw Go program channel data. The deadlock risk pattern classification and assessment includes asymmetric read / write risk assessment, circular wait chain risk assessment, and blocking / leakage risk assessment, and performs first-level detection of Go program channel anomalies based on the assessment results; the module for constructing a three-dimensional deadlock risk graph is used to construct a three-dimensional deadlock risk graph based on the assessment results; and the second assessment and detection module for Go program channel anomalies is used to perform second-level detection of Go program channel anomalies based on the three-dimensional deadlock risk graph.
[0011] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages:
[0012] 1. This invention improves the accuracy of Go program channel anomaly detection in high-concurrency, big data computing node scenarios by implementing lightweight data acquisition; classifying and evaluating deadlock risk patterns based on raw Go program channel data; performing first-stage anomaly detection based on the evaluation results; constructing a three-dimensional deadlock risk map based on the evaluation results; and performing second-stage anomaly detection based on the three-dimensional deadlock risk map. This solves the problem of insufficient accuracy in existing technologies for dynamic adjustment of Go program channel anomaly detection in high-concurrency, big data computing node scenarios.
[0013] 2. By modifying the Go runtime source code through lightweight data acquisition and inserting monitoring code into the channel operation functions, a lock-free circular buffer is implemented to store quadruple data. A sampling strategy is used to process high-frequency channel data, and independent coroutines process data in batches and calculate blocking durations. On the ARM Cortex-A53 edge nodes of the smart factory, this solution significantly reduces memory usage. Through high-frequency channel sampling and batch processing, CPU overhead is greatly reduced, ensuring the stable operation of real-time filtering coroutines for tens of thousands of sensors per second. The data drop rate is significantly reduced, enabling the system to capture aggregate coroutine blocking events within milliseconds when network jitter causes upload timeouts, and accurately identify fault points by calculating blocking durations.
[0014] 3. Outlier pruning and normalization are performed on the three risk values. A three-dimensional coordinate system is created to map the risks of congestion leakage, asymmetric read / write, and circular wait. The kernel density field strength is calculated in a gridded space to generate a risk propagation map. Thus, in the financial trading system, the three-dimensional heat map intuitively presents the channel congestion hotspots. Operation and maintenance personnel can locate the core problem channels through HSV color mapping, which greatly improves the detection efficiency. At the same time, the LSTM model trained based on historical data triggers weight adjustment in advance when the system load reaches a high number of coroutines, dynamically expanding the buffer of high-risk channels. This achieves preventive measures to reduce the deadlock rate and significantly shorten the system recovery time. Attached Figure Description
[0015] Figure 1 A flowchart of a Go program channel anomaly detection method based on deadlock risk graph provided in this application embodiment.
[0016] Figure 2 This is a schematic diagram of the first evaluation and detection process for Go program channel anomalies provided in an embodiment of this application.
[0017] Figure 3 This is a schematic diagram of the second detection process for Go program channel anomalies based on a three-dimensional deadlock risk map in an embodiment of this application.
[0018] Figure 4 This is a structural diagram of a Go program channel anomaly detection device based on deadlock risk graph provided in an embodiment of this application. Detailed Implementation
[0019] This application provides a method and apparatus for detecting channel anomalies in Go programs based on deadlock risk graphs, which solves the problem in the prior art where the accuracy of dynamic adjustment in detecting channel anomalies in Go programs is insufficient in dealing with high-concurrency big data computing node scenarios.
[0020] To better understand the above technical solutions, the following will provide a detailed explanation of the technical solutions in conjunction with the accompanying drawings and specific implementation methods.
[0021] like Figure 1 The diagram shows a flowchart of a Go program channel anomaly detection method based on a deadlock risk graph provided in this application embodiment. This method is applied in a device and includes the following steps: During Go program execution, lightweight data acquisition is performed to obtain raw Go program channel data; deadlock risk pattern classification and assessment are performed based on the raw Go program channel data, including asymmetric read / write risk assessment, circular wait chain risk assessment, and blocking / leakage risk assessment; a first detection of Go program channel anomalies is performed based on the assessment results; a three-dimensional deadlock risk graph is constructed based on the assessment results; and a second detection of Go program channel anomalies is performed based on the three-dimensional deadlock risk graph.
[0022] In this embodiment, in a high-frequency trading system sensitive to millisecond-level latency, the order routing core built by Go goroutine groups needs to dynamically coordinate thousands of concurrent channels (e.g., market data reception pointing to risk control filtering pointing to price matching pointing to clearing channels). The core contradiction lies in the fact that existing technologies cannot, under ultra-high throughput (millions of messages per second) conditions, track the channel operation dependency chain of cross-level goroutines in real time, accurately identify the local deadlock risks caused by asymmetric channel read / write, circular waiting, and blocking leakage, and synchronously generate a visual dynamic deadlock risk heat map. This leads to the paralysis of implicit parts, the freezing of local modules of the trading engine but the system not completely crashing, resulting in continuous order packet loss and matching failures; catastrophic recovery delays, traditional deadlock detection requires active triggering or post-event shutdown; and loss of control over risk tracing, making it impossible to locate the source of the blockage channel (e.g., the risk control channel not being consumed due to clearing goroutine blockage), forcing manual debugging layer by layer. This innovative solution completely solves the channel management challenges of high-frequency trading systems through three core technologies: Dynamic Topology Real-Time Deconstruction Technology utilizes coroutine coloring tracing and lightweight event tracing to achieve millisecond-level routing network reconstruction; a three-dimensional phase deadlock identification algorithm integrates asymmetric read / write exponents, congestion leakage factors, and circular wait markers to achieve microsecond-level hidden deadlock detection; and a radiation thermogram imaging system, based on a channel congestion energy model and gradient tracing algorithm, generates a dynamic risk visualization map. This technological system forms a closed-loop solution, transforming abstract deadlock risks into quantifiable spatial coordinates and establishing a millisecond-level response mechanism from risk perception to self-healing protection.
[0023] Furthermore, during Go program execution, lightweight data acquisition is implemented. The specific process involves dynamic instrumentation, including modifications to Go runtime core functions and high-frequency channel sampling optimizations. Modifications to the Go runtime core functions include inserting monitoring code into the channel send (`chansend`) and receive (`chanrecv`) functions during Go runtime; capturing the following four-tuple data when channel operations are blocked; and writing the captured data to a pre-allocated lock-free circular buffer. The four-tuple data contains the Goroutine ID of the executed operation. ID), the memory address of the channel being operated on, the operation type (send / receive / close), and the operation start timestamp; the captured data is written to a pre-allocated lock-free circular buffer; high-frequency channel sampling optimization includes: enabling downsampling strategy for high-frequency channels (such as channels with more than 1000 operations per second), collecting data only once every 10 operations, and dynamically adjusting the sampling rate to balance data integrity and performance overhead; high-frequency channel sampling optimization includes real-time monitoring of channel operation frequency, batch data extraction and processing, dynamic updating of dependency graph, cross-level dependency detection, data lifecycle management, data serialization and transmission, system initialization and monitoring; batch data extraction and processing includes a timed batch processing mechanism and data structure initialization; the timed batch processing mechanism includes: performing data processing every 50 microseconds, extracting all new data records added since the last processing from the lock-free circular buffer, and supplementing each record with the actual blocking time (the time from the current timestamp to the operation start timestamp); data structure initialization includes: 1. Creating a global dependency graph data structure: node set: storing the state information of all active coroutines; edge set: storing 1. Store the operational relationships between coroutines and channels; 2. Maintain for each coroutine node: the address of the currently blocked channel (if any), and the nested waiting chain (recording the predecessor channels that it depends on); Dynamic updates of the dependency graph include node management, edge creation and updating, and nested dependency handling; Node management includes: creating nodes for newly emerging coroutines, updating the status of existing coroutine nodes: if the operation is blocked, mark the currently blocked channel, and if the operation is completed, clear the blocking status; Edge creation and updating includes: creating new edges for each channel operation: source coroutine ID, target channel address, operation type, blocking duration, and nested waiting chain, and adding the edge to the edge set of the corresponding channel; Nested dependency handling includes: if the coroutine is already in a blocked state during the operation: add the currently blocked channel to the waiting chain of the new operation, and establish cross-level dependency relationships; Cross-level dependency detection includes: periodic scanning and dependency chain analysis; Periodic scanning: perform a full graph scan every 5 milliseconds, traversing all coroutine nodes in a blocked state; Dependency chain analysis: for each blocked coroutine: 1. Traverse all channels in its waiting chain; 2. Find other coroutines associated through these channels; 3.Establish implicit cross-level dependencies; detect potential circular wait chains (coroutine A → channel 1 → coroutine B → channel 2 → coroutine A); data lifecycle management includes: expired node cleanup and memory optimization; expired node cleanup includes: performing cleanup every 100 milliseconds, removing coroutine nodes that have not been updated for more than 1 millisecond, and synchronously cleaning up related edge data; memory optimization includes: using object pools to pre-allocate data structures and adopting lock-free concurrency control mechanisms; data serialization and transmission includes: efficient serialization and zero-copy transmission; efficient serialization includes: converting the current dependency graph state into a compact binary format and using efficient encoding schemes to reduce data volume; zero-copy transmission includes: transmitting serialized data through shared memory areas, creating dedicated memory-mapped files (mmap), directly copying data to shared memory areas, and notifying downstream analysis modules that data is ready; system initialization and monitoring includes: startup process and resource monitoring; startup process includes: enabling data acquisition during the application initialization phase and starting all background processing coroutines; resource monitoring includes: real-time tracking of memory usage, monitoring CPU overhead and dynamically adjusting the sampling rate, and recording key performance indicators for system optimization.
[0024] In this embodiment, as Figure 2 The diagram shown illustrates the first evaluation and detection process for Go program channel anomalies provided in this application embodiment. It also illustrates the lightweight data collection and subsequent evaluation and control in this implementation. Deadlock is essentially a resource dependency loop, requiring global collection of coroutine-channel interaction data to locate the closed-loop path. However, a high log sampling rate leads to a significant increase in CPU overhead and makes it impossible to reconstruct the timing relationships of operations (such as interleaved concurrent writes). In this case, traditional logging solutions fail. If Gopprof / trackers cannot correlate blocked operations with business channels, and the latency exceeds 100ms, the 500μs detection window cannot be met. Therefore, tools with built-in Go programs have significant limitations and cannot achieve the desired technical effects.
[0025] The raw data from the Go program channel is all the data used in the analysis below, and all data is transmitted and stored in the form of serialized data, which helps to save computing power and improve data processing efficiency.
[0026] In the Go runtime source code, the following data structure is used to determine whether a channel operation is blocking:
[0027] type hchan struct {
[0028] / / Channel core fields
[0029] qcount uint / / Number of elements in the current queue
[0030] dataqsiz uint / / Size of the circular queue
[0031] buf unsafe.Pointer / / Pointer to the circular queue
[0032] sendx uint / / Send index
[0033] recvx uint / / Receive index
[0034] / / Key blocking determination field
[0035] recvq waitq / / A linked list of goroutines waiting to receive data (in a blocked state)
[0036] sendq waitq / / A linked list of goroutines waiting to be sent (in a blocked state)
[0037] closed uint32 / / Channel closed flag
[0038] }
[0039] Note that after edge creation and update, the edge set contains the source coroutine ID, target channel address, operation type, blocking duration, and nested wait chain.
[0040] Using encoding schemes to reduce data volume, in high-frequency trading scenarios, a combination of time series differential encoding, channel address remapping, and operation type bitmasking is the most efficient solution. An example is shown below:
[0041] func encodeEvent(ev TraceEvent) [ ]byte {
[0042] delta := ev.Timestamp - lastTimestamp
[0043] d2 := delta - lastDelta / / 1. Timestamp differential encoding
[0044] chanID := getChannelID(ev.ChanAddr) / / 2. Address mapping
[0045] opCode := (ev.OpType << 1) | ev.BlockingFlag / / 3. Operation type compression
[0046] return [ ]byte{
[0047] byte(d2 >> 8), byte(d2),
[0048] byte(chanID >> 8), byte(chanID),
[0049] opCode,
[0050] }
[0051] / / Combined output
[0052] The above technical solutions enable high-fidelity, low-latency acquisition of runtime topology data, providing a reliable data foundation for subsequent deadlock risk detection.
[0053] Further, the asymmetric read / write risk assessment specifically includes: obtaining the number of Go program channel transmissions using the first function built into the `go` function; obtaining the number of Go program channel receptions using the second function built into the `go` function; extracting a preset smoothing factor from the deadlock risk graph Go program channel database; performing a proportion analysis on the coupling results of the Go program channel transmission count with the number of Go program channel transmissions, the number of Go program channel receptions, and the preset smoothing factor to obtain the channel transmission / reception ratio component; performing a difference analysis on the coupling analysis results of the Go program channel transmission count with the Go program channel ratio threshold and the number of Go program channel receptions to obtain a significance development component; performing a square root analysis on the coupling results of the Go program channel transmission count and the number of Go program channel receptions, and then performing a coupling analysis with the preset smoothing factor to obtain a sample size development component; performing a proportion analysis on the significance development component and the sample size development component, and then performing activation function analysis to obtain the channel asymmetric significance component; and continuing the coupling analysis between the channel transmission / reception ratio component and the channel asymmetric significance component to obtain the asymmetric read / write risk index.
[0054] In this embodiment, the Go program channels are numbered. This indicates the channel number of the Go program. This indicates the total number of channel numbers in the Go program. .
[0055] ;
[0056] Indicates the first The asymmetric read / write risk index of a Go program channel is dimensionless.
[0057] Indicates the first The number of times the Go program channel sends data, dimensionless.
[0058] Indicates the first The number of times a Go program channel receives data, dimensionless.
[0059] Indicates the first The threshold for the proportion of each Go program channel, dimensionless, with a value range of 0-10.
[0060] This represents the preset smoothing factor, extracted from the deadlock risk graph Go program channel database. It can be set to 0.001 to avoid division by zero errors.
[0061] The number of times a channel can be sent in a Go program can be obtained using the first built-in function in the `go` function.
[0062] The specific implementation location for obtaining the number of channel sends in a Go program is: the `chansend` function call within the `go` function.
[0063] The number of times a channel receives data in a Go program can be obtained using the second function built into the `go` function.
[0064] The specific implementation location for obtaining the channel receive count in a Go program is: the chanrecv function call within the go function.
[0065] The Go program channel ratio threshold is extracted from the deadlock risk graph Go program channel database. This ratio threshold is based on the producer-consumer queuing theory. The ratio threshold can be the sending rate (producer rate) divided by the receiving rate (consumer rate). In a stable system, extraction and calculation are performed on historical data to obtain the mapping relationship between the average waiting time of different channels and the corresponding ratio threshold. The average waiting time of the channel is input to obtain the corresponding Go program channel ratio threshold.
[0066] Furthermore, the risk assessment of the circular waiting chain specifically includes: when a Go program goroutine enters a waiting state due to channel blockage, its waiting chain is automatically recorded; the waiting path of the Go program goroutine is traced through depth-first search; the total number of nodes on the path is calculated to obtain the length of the blocking chain; a third function built into the Go program records the start timestamp of the blocking wait due to channel blockage; the end timestamp of the blocking wait is recorded when the operation is completed; the difference between the end timestamp and the start timestamp is analyzed to obtain the single blocking duration of each node; and the single blocking duration of each node in the entire waiting chain is summed to obtain the total blocking duration. The Tarjan algorithm is used to detect waiting chain graphs. When a closed dependency cycle is found, the cycle structure flag is set to 1, and when there is no cycle structure, the cycle structure flag is set to 0. The length of the blocked chain and the total blocking time are normalized to obtain normalized length and normalized time. The length weight and duration weight are extracted from the deadlock risk graph Go program channel database. The normalized length and length weight are coupled and analyzed to obtain the circular waiting chain length component. The normalized time and duration weight are coupled and analyzed to obtain the circular waiting chain duration component. The circular waiting chain length component and the circular waiting chain duration component are coupled and analyzed to obtain the circular waiting chain risk index.
[0067] In this embodiment, when a Go program goroutine enters a waiting state due to channel blocking, the system automatically records its waiting chain. Example code is as follows:
[0068] func recordGoroutineBlock(gp g, c hchan) { / / Get coroutine ID
[0069] gid := gp.goid
[0070] chanAddr := uintptr(unsafe.Pointer(c)) / / Get the channel address
[0071] currentChain := getCurrentChain(gid) / / Check the current waiting chain
[0072] newChain := append(currentChain, BlockPoint{ / / Add a new blocking point
[0073] ChanAddr: chanAddr,
[0074] Timestamp: nanotime(),
[0075] })
[0076] blockMap[gid] = newChain / / Update global state
[0077] `go updateDependencyGraph(gid, newChain)` / / Asynchronously refreshes the graph database.
[0078] }
[0079] Depth-first search (DFS) is a graph traversal algorithm. Its core logic is: starting from a starting node, explore as deep as possible along the path, backtracking to the nearest branch point when encountering the end, repeating until all nodes are visited. Example code for using DFS to track the waiting path of a Go program's goroutines is as follows:
[0080] def detect_wait_cycle(start_id): # Initialize data structure
[0081] visited = set()
[0082] stack = [ ]
[0083] cycles = [ ]
[0084] def dfs(current_id, parent_id): # Recursive DFS function
[0085] if current_id is in visited:
[0086] If current_id is in stack: # A cycle has been detected (the current node is in the access path).
[0087] cycle_start = stack.index(current_id)
[0088] cycles.append(stack[cycle_start:] + [current_id])
[0089] return
[0090] visited.add(current_id)
[0091] stack.append(current_id)
[0092] blocking_chans = get_blocking_channels(current_id) # Get the currently blocked channels of the node
[0093] for chan in blocking_chans:
[0094] dependent_goroutines = get_waiting_goroutines(chan) # Get the goroutines that depend on this channel.
[0095] for gid in dependent_goroutines:
[0096] if gid != parent_id:
[0097] dfs(gid, current_id)
[0098] stack.pop()
[0099] dfs(start_id, None) # Start DFS
[0100] return cycles
[0101] The Tarjan algorithm is used to detect waiting chains in a graph. When a closed dependency cycle is found, a flag is set to 1; otherwise, the flag remains 0. Example code is shown below:
[0102] func strongConnect(v TarjanNode) { / / Initialize node attributes
[0103] v.Index = indexCounter
[0104] v.LowLink = indexCounter
[0105] indexCounter++
[0106] stack = append(stack, v) / / Push the node onto the stack
[0107] v.OnStack = true
[0108] for _, wID := range getNeighbors(v.NodeID) { / / Iterate through all adjacent nodes
[0109] w := nodes[wID]
[0110] if w.Index == -1 { / / Unvisited node
[0111] strongConnect(w)
[0112] if w.LowLink < v.LowLink {
[0113] v.LowLink = w.LowLink
[0114] }
[0115] } else if w.OnStack { / / Visited and in the stack
[0116] if w.Index < v.LowLink {
[0117] v.LowLink = w.Index
[0118] }
[0119] }
[0120] }
[0121] if v.LowLink == v.Index { / / Determine if SCC has formed
[0122] sccNodes := [ ] TarjanNode{} / / Pop nodes from the stack up to the current node
[0123] for {
[0124] w := stack[len(stack)-1]
[0125] stack = stack[:len(stack)-1]
[0126] w.OnStack = false
[0127] sccNodes = append(sccNodes, w)
[0128] if len(sccNodes) > 1 {
[0129] setCircleFlag(w.NodeID, 1)
[0130] }
[0131] if w.NodeID == v.NodeID {
[0132] break
[0133] }
[0134] }
[0135] if len(sccNodes) == 1 { / / Special handling for a single node
[0136] if hasSelfLoop(v.NodeID) { / / Check for self-loops
[0137] setCircleFlag(v.NodeID, 1)
[0138] } else {
[0139] setCircleFlag(v.NodeID, 0)
[0140] }
[0141] }
[0142] }
[0143] }
[0144] The following weights are extracted from the deadlock risk graph Go program channel database: length weight, duration weight, base weight of length weight, and base weight of duration weight. Length weight = base weight of length weight + mutation factor of length weight × [1 / (1+e^(-k×(load - load midpoint))]. Duration weight = base weight of duration weight + mutation factor of duration weight × [1 / (1+e^(-k×(load - load midpoint))]. k represents the derivative of the load change rate at the current moment. The load is quantified according to the number of coroutines. The load midpoint is set to the average value of coroutines at different nodes in the current channel. When the ring structure is marked as unit 1, the base weights of length weight and duration weight are set to 0.5 and 0.5 respectively. The closed-loop structure has a deterministic deadlock risk, requiring improved early warning sensitivity. e is a natural constant.
[0145] The length weight mutation factor represents the absolute value of the difference between the current blocking chain length and the blocking chain length threshold, divided by the blocking chain length threshold; the duration weight mutation factor represents the absolute value of the difference between the current total blocking duration and the total blocking duration threshold, divided by the total blocking duration threshold.
[0146] When the loop structure flag is set to zero, the base weights for length and duration are set to 0.25 and 0.25, respectively. Open-loop structures may automatically dissolve, reducing false alarm priority. Note that the above parameter calculations are performed across different channels, each corresponding to a different circular waiting chain risk index.
[0147] Furthermore, the blocking leakage risk assessment specifically includes: inserting monitoring points into predefined functions of the Go program via bytecode instrumentation to collect the blocking duration of all threads; obtaining the current cycle maximum value through the first predefined function of the Go program to obtain the maximum blocking duration of the Go program; comparing and analyzing the maximum blocking duration of the Go program with the corresponding risk threshold for the maximum blocking duration of the Go program to obtain the blocking offset; amplifying the blocking offset by a curve steepness coefficient to obtain the blocking offset amplification component; mapping the blocking offset amplification component to a unit range of zero to one using an activation function to obtain the blocking duration mapping component; scanning the target code block using predefined analysis to obtain the maximum timeout feedback coefficient of the Go program; setting the maximum timeout feedback coefficient of the Go program to one if a timeout parameter is detected, otherwise setting it to zero; and coupling the blocking duration mapping component and the maximum timeout feedback coefficient of the Go program for analysis to obtain the blocking leakage risk assessment index.
[0148] In this embodiment, the Go program channels are numbered. This indicates the channel number of the Go program. This indicates the total number of channel numbers in the Go program. .
[0149] ;
[0150] Represents the natural constant.
[0151] Indicates the first A dimensionless index for assessing the risk of blocking and leakage in a Go program channel.
[0152] Indicates the first The curve steepness coefficient for each Go program channel is loaded by default from the configuration file risk_model.curve_factor. The curve steepness can be extracted from the rate of change derivative in the historical file data called by risk_model.curve_factor, with a value range of 1.5-3.0.
[0153] Indicates the first The maximum blocking time of a Go program channel is dimensionless. It is calculated by inserting monitoring points in `synchronized / Lock.lock()` via bytecode instrumentation, collecting the blocking duration of all threads every 500ms, and using `max(block_durations)` to obtain the maximum value in the current period, thus yielding the maximum blocking time of the Go program.
[0154] Indicates the first The maximum blocking time risk threshold for each Go program channel is dimensionless. It is obtained from the configuration file `blocking.risk_threshold`, based on expert prior knowledge. Note that both the maximum blocking time risk threshold and the maximum blocking time of the Go program need to be normalized for consistent measurement.
[0155] Indicates the first The maximum timeout feedback coefficient for each Go program channel is dimensionless. It is calculated by scanning the target code block using AST analysis, checking for keywords such as `wait(timeout)` and `tryLock(timeout)`. If a timeout parameter exists, it returns 1; otherwise, it returns 0. This indicates that the maximum timeout feedback coefficient for the Go program has a value of either 0 or 1.
[0156] Furthermore, the congestion and leakage risk assessment also includes: if the congestion and leakage risk assessment index is less than the third threshold, then pre-occupied memory resources are released and a three-dimensional deadlock risk map is constructed based on the assessment results; if the congestion and leakage risk assessment index is equal to or greater than the third threshold and less than the second threshold, then CPU affinity optimization is performed; if the congestion and leakage risk assessment index is equal to or greater than the second threshold and less than the first threshold, then concurrent channel restrictions and dynamic resource expansion are implemented, and the nodes in the corresponding channels are recorded as risk nodes; if the congestion and leakage risk assessment index is equal to or greater than the first threshold, then concurrent channel restrictions and physical isolation of hardware fault nodes are implemented, and the nodes in the corresponding channels are recorded as risk nodes.
[0157] In this embodiment, a first threshold, a second threshold, and a third threshold for blocking and leaking risk assessment are extracted from the deadlock risk graph Go program channel database. The first threshold for blocking and leaking risk assessment is greater than the second threshold, which is greater than the third threshold.
[0158] The following is an example code demonstrating the order of releasing pre-occupied memory resources and the three-level cache:
[0159] echo 1 > / proc / sys / vm / drop_caches # Release page cache.
[0160] echo 2 > / proc / sys / vm / drop_caches # Release dentries and inode caches.
[0161] echo 3 > / proc / sys / vm / drop_caches # Release all caches.
[0162] CPU affinity optimization: Use the taskset command to bind threads to specific CPU cores.
[0163] taskset -c <cpu-list> <thread-id>This method avoids cross-node access latency in NUMA architectures.
[0164] The following is an example code for limiting concurrent channels:
[0165] func handleWarningRisk(leakRisk float64, serviceName string) {
[0166] maxConn := serviceRegistry.GetMaxConnections(serviceName) / / Get the current maximum number of connections
[0167] newLimit:= int(float64(maxConn) (1 - leakRisk) / / Calculate the new concurrency limit (reduce the number of connections)
[0168] limiter := concurrency.NewLimiter(serviceName, newLimit) / / Apply concurrency limit
[0169] if err := limiter.Apply(); err != nil {
[0170] log.Printf("Concurrency limit failed: %v", err)
[0171] } else {
[0172] log.Printf("Application concurrency limit: %d (original maximum number of connections %d, risk value %.2f)",
[0173] newLimit, maxConn, leakRisk)
[0174] }
[0175] The following is an example of dynamic resource expansion:
[0176] cmd:= exec.Command("aws", "ec2", "run-instances",
[0177] "--image-id", "ami-abcdef123456",
[0178] "--instance-type", "c5.xlarge",
[0179] "--count", "2",
[0180] "--tag-specifications", fmt.Sprintf("ResourceType=instance, Tags=[{Key=Service, Value=%s}]", serviceName))
[0181] lbManager.AddNodesToPool(serviceName, 2) / / Execute the scaling command and update the load balancer.
[0182] }
[0183] }
[0184] The following is an example code for physical isolation of hardware fault nodes:
[0185] `nodeIP, err := nodeRegistry.GetIP(nodeName)` / / Get the node IP
[0186] if err != nil {
[0187] log.Printf("Failed to obtain node IP: %v", err)
[0188] return
[0189] }
[0190] ipmiCmd:= fmt.Sprintf("ipmitool -I lanplus -H %s -U ADMIN -PADMIN power off", nodeIP)
[0191] if err := exec.Command("bash", "-c", ipmiCmd).Run(); err != nil / / Execute hardware isolation command
[0192] }
[0193] Furthermore, a three-dimensional deadlock risk map is constructed based on the assessment results. Specifically, this includes: applying an adaptive outlier pruning algorithm to the asymmetric read / write risk index, circular wait chain risk index, and congestion / leakage risk assessment index, performing scaling combined with data standardization to scale them to a predefined data range, resulting in scaled data ranges for the asymmetric read / write risk index, circular wait chain risk index, and congestion / leakage risk assessment index; creating a three-dimensional risk coordinate system based on these data ranges; using LSTM to predict near-future weight requirements, and applying a constrained optimization model to adjust the three-dimensional risk coordinate system.
[0194] In this embodiment, as Figure 3 The diagram shown illustrates the second detection process for Go program channel anomalies based on a 3D deadlock risk map in this embodiment of the application. Example code using an adaptive outlier pruning algorithm and min-max scaling combined with Z-score normalization is as follows:
[0195] def robust_normalize(value, min, max, mean, std):
[0196] iqr = calculate_iqr(values) # IQR outlier handling
[0197] clipped = np.clip(value, mean-3 iqr, mean+3 iqr)
[0198] scaled = (clipped - min) / (max - min) # Double standardization transformation
[0199] return (scaled - scaled.mean()) / scaled.std() 2.5
[0200] Technical effect: Eliminates dimensional differences, making different types of risk values comparable in the range of [-5, 5]. Note that the range of [-5, 5] is an example and can be set arbitrarily without affecting the computing power.
[0201] A three-dimensional risk coordinate system is created to visualize risk distribution patterns and identify high-risk clusters.
[0202] The following is an example code snippet for using LSTM to predict near-future weight requirements and applying a constrained optimization model to adjust the weights: `def calculate_weights(risks, history):`
[0203] grad = np.gradient(risks, axis=0) # Calculate the gradient of change
[0204] lstm_model = load_pretrained('risk_weight_predictor') # LSTM predicts weight trends
[0205] base_weights = lstm_model.predict(grad[-10:])
[0206] return scipy.optimize.minimize( # Weight adjustment)
[0207] objective_fn,
[0208] base_weights,
[0209] constraints=[
[0210] {'type': 'ineq', 'fun': lambda w: w.sum()-1},
[0211] {'type': 'ineq', 'fun': lambda w: w[0]-0.3} ]
[0213] In order to adapt to the system status in real time and highlight the dominant risk factors.
[0214] Furthermore, a second detection of Go program channel anomalies is performed based on the three-dimensional deadlock risk map. Specifically, this includes: if the field strength value on the regular three-dimensional grid in the three-dimensional deadlock risk map is greater than the first warning threshold, the corresponding regular three-dimensional grid point is recorded as a warning regular three-dimensional grid point; the regular three-dimensional grid point corresponding to the largest value among the warning regular three-dimensional grid points is recorded as the core warning regular three-dimensional grid point; the number of non-warning regular three-dimensional grid points that are closest to the core warning regular three-dimensional grid point is recorded as the radius of influence; based on the radius of influence and the core warning regular three-dimensional grid points, the three-dimensional region affected by the core warning regular three-dimensional grid is obtained; a circuit breaker mechanism is triggered for all corresponding channels in the three-dimensional region affected by the core warning regular three-dimensional grid, and resource expansion and allocation are performed for non-core warning regular three-dimensional grid points outside the three-dimensional region affected by the core warning regular three-dimensional grid.
[0215] In this embodiment, based on the radius of the number of influencing points and the three-dimensional grid points of the core early warning rule, the three-dimensional region affected by the three-dimensional grid of the core early warning rule is obtained. That is, the three-dimensional region affected by the three-dimensional grid of the core early warning rule is the spherical region centered on the three-dimensional grid points of the core early warning rule and the radius of the number of influencing points.
[0216] The first warning threshold is extracted from the deadlock risk graph Go program channel database.
[0217] Constructing a three-dimensional deadlock risk map based on the assessment results also includes: creating an equally spaced three-dimensional grid, assigning different three-dimensional risk coordinate data to corresponding grid cells to obtain a regular three-dimensional grid data structure model; calculating the risk impact degree of the surrounding neighborhood for each grid cell under the regular three-dimensional grid data structure model according to a predefined kernel density radius, applying Gaussian kernel weighting to calculate the comprehensive field strength, and obtaining a three-dimensional field strength matrix; calculating the time series correlation between risk nodes, generating risk propagation edges, and obtaining a risk propagation map; and calculating the risk correlation matrix based on the three-dimensional field strength matrix and the risk propagation map to construct a three-dimensional deadlock risk map.
[0218] The following is an example code for a three-dimensional field strength matrix:
[0219] func CalculateFieldStrength(grid [ ][ ][ ] RiskCoordinate, kernelRadius float64) [ ][ ][ ]float64 {
[0220] size := len(grid)
[0221] field:= make([ ][ ][ ]float64, size)
[0222] var wg sync.WaitGroup
[0223] wg.Add(size)
[0224] for i := range field {
[0225] field[i] = make([ ][ ]float64, size)
[0226] for j := range field[i] {
[0227] field[i][j] = make([ ]float64, size)
[0228] }
[0229] go func(i int) {
[0230] defer wg.Done()
[0231] for j := 0; j < size; j++ {
[0232] for k := 0; k < size; k++ {
[0233] field[i][j][k] = calculateCellStrength(i, j, k, grid, kernelRadius)
[0234] }
[0235] }
[0236] }
[0237] }
[0238] wg.Wait()
[0239] return field
[0240] }
[0241] The following is sample code for calculating the time series correlation between risk nodes and generating risk propagation edges:
[0242] func BuildPropagationGraph(coords [ ]RiskCoordinate, timeWindowtime.Duration) PropagationGraph {
[0243] graph := &PropagationGraph{}
[0244] for i := range coords { / / Add node
[0245] graph.Nodes = append(graph.Nodes, RiskNode{
[0246] ID: coords[i].ID
[0247] Coord: coords[i],
[0248] }
[0249] }
[0250] for i := range coords { / / Construct risk propagation edges
[0251] for j := range coords {
[0252] if i != j {
[0253] similarity := calculateTimeSimilarity( / / Calculate time series similarity)
[0254] coords[i].History,
[0255] coords[j].History,
[0256] timeWindow )
[0258] distance := euclideanDistance( / / Spatial correlation)
[0259] coords[i].Position,
[0260] coords[j].Position, )
[0262] weight := similarity math.Exp(-distance) / / propagation weight
[0263] if weight > 0.2 {
[0264] graph.Edges = append(graph.Edges, RiskEdge{
[0265] Source: coords[i].ID
[0266] Target: coords[j].ID
[0267] RiskWeight: weight
[0268] })
[0269] }
[0270] }
[0271] }
[0272] }
[0273] return graph
[0274] }
[0275] The following is sample code for constructing a 3D deadlock risk map by calculating the risk correlation matrix based on the 3D field strength matrix and the risk propagation map:
[0276] type RiskGraph struct {
[0277] Nodes [ ] RiskNode
[0278] Edges [ ] RiskEdge
[0279] Hotspots [ ][3]int / / Hotspot grid coordinates
[0280] FieldGrid [ ][ ][ ]float64 / / 3D field strength grid
[0281] }
[0282] func BuildRiskGraph(field [ ][ ][ ]float64, graph PropagationGraph RiskGraph {
[0283] rg := &RiskGraph{
[0284] FieldGrid: field,
[0285] }
[0286] for i := range graph.Nodes { / / Copy nodes
[0287] rg.Nodes = append(rg.Nodes, &graph.Nodes[i])
[0288] }
[0289] for i := range graph.Edges { / / Copy edges
[0290] rg.Edges = append(rg.Edges, &graph.Edges[i])
[0291] }
[0292] rg.identifyHotspots(0.8)
[0293] return rg
[0294] }
[0295] func (rg RiskGraph) identifyHotspots(percentile float64) {
[0296] var values []float64 / / Collect all field strength values
[0297] for i := range rg.FieldGrid { threshold := stat.Quantile(percentile, stat.Empirical, values, nil)
[0306] for i := range rg.FieldGrid { / / Mark hotspots
[0307] for j := range rg.FieldGrid[i] {
[0308] for k := range rg.FieldGrid[i][j] {
[0309] if rg.FieldGrid[i][j][k] >= threshold {
[0310] rg.Hotspots = append(rg.Hotspots, [3]int{i, j, k})
[0311] }
[0312] }
[0313] }
[0314] }
[0315] }
[0316] For non-core early warning rule 3D grid points outside the 3D region affected by the core early warning rule 3D grid, resource expansion and allocation are performed. Example code is as follows:
[0317] func handleChannelWarning(warning ChannelWarning) {
[0318] radius := getAffectedRadius(warning.RiskLevel) / / Determine the range of influence
[0319] scope := determineAffectedScope(warning, radius) / / Dynamic augmentation detection
[0320] inspectionTargets := prioritizeInspection(scope) / / Preventive measures
[0321] runPreventiveActions(inspectionTargets)
[0322] monitorGroup := createMonitoringGroup(scope) / / Establish a monitoring feedback loop
[0323] go monitorGroup.RunEnhancedMonitoring() / / Predictive protection
[0324] if warning.RiskLevel > 0.7 {
[0325] injectPreventiveMeasures(scope)
[0326] }
[0327] updateSystemStatus() / / Update the global status
[0328] }
[0329] The circuit breaker mechanism is triggered for all corresponding channels in the three-dimensional region affected by the core early warning rule three-dimensional grid. Resource expansion and allocation are performed for non-core early warning rule three-dimensional grid points outside the three-dimensional region affected by the core early warning rule three-dimensional grid. Because after the circuit breaker mechanism is triggered, the non-core early warning rule three-dimensional grid points closest to the three-dimensional region affected by the core early warning rule three-dimensional grid will be prioritized to receive load impact, which may trigger a new round of deadlock. Therefore, resource expansion and allocation need to be performed in advance, which may be a short-term expansion of running memory, etc.
[0330] like Figure 4 The diagram shows the structure of the Go program channel anomaly detection device based on deadlock risk graph provided in this application embodiment. It includes a lightweight Go program data acquisition module, a first assessment and detection module for Go program channel anomalies, a module for constructing a three-dimensional deadlock risk graph, and a second assessment and detection module for Go program channel anomalies. The lightweight Go program data acquisition module is used to perform lightweight data acquisition during Go program runtime to obtain the raw data of the Go program channel. The first assessment and detection module for Go program channel anomalies is used to perform deadlock risk pattern classification assessment based on the raw data of the Go program channel. The deadlock risk pattern classification assessment includes asymmetric read / write risk assessment, circular wait chain risk assessment, and blocking / leakage risk assessment. Based on the assessment results, the first detection of Go program channel anomalies is performed. The module for constructing a three-dimensional deadlock risk graph is used to construct a three-dimensional deadlock risk graph based on the assessment results. The second assessment and detection module for Go program channel anomalies is used to perform a second detection of Go program channel anomalies based on the three-dimensional deadlock risk graph.
[0331] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0332] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0333] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0334] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0335] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0336] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations. < / cpu-list>
Claims
1. A method for detecting channel anomalies in Go programs based on deadlock risk graphs, characterized in that, Includes the following steps: During Go program execution, lightweight data acquisition is performed to obtain raw data from the Go program channel; Based on the raw data of the Go program channel, a deadlock risk mode classification and assessment is performed. The deadlock risk mode classification and assessment includes asymmetric read-write risk assessment, circular wait chain risk assessment and blocking leakage risk assessment. Based on the assessment results, the first detection of Go program channel anomalies is performed. A three-dimensional deadlock risk map is constructed based on the assessment results; Secondary detection of Go program channel anomalies based on 3D deadlock risk map; When the Go program runs, it performs lightweight data collection, the specific process of which is as follows: Insert monitoring code into the channel send and receive functions of the Go runtime. When the channel operation of the Go runtime is blocked, capture the four-tuple data and write the captured four-tuple data into a pre-allocated lock-free circular buffer. A downsampling strategy is enabled for the high-frequency channel, and all new data records added since the last processing are extracted from the unlocked circular buffer. The actual blocking time is calculated for each record. Create a global dependency graph data structure, which contains a set of nodes and a set of edges. For each coroutine node, maintain the currently blocked channel address and nested wait chain. Create nodes for newly emerging coroutines, update the state of existing coroutine nodes, create new edges for each channel operation, add the edges to the edge set of the corresponding channel, and if the coroutine is already in a blocked state during the operation, add the currently blocked channel to the waiting chain of the new operation and establish cross-level dependencies. According to the predefined first time step, perform a traversal of all blocked coroutine nodes, and for each blocked coroutine, traverse all channels in its waiting chain and find other coroutines associated through these channels. Perform a cleanup at a predefined second time step, removing coroutine nodes that have not been updated for more than a predefined third time step, and simultaneously clean up the related edge data. The current dependency graph state is converted into a compact binary format, the data volume is reduced using an encoding scheme, serialized data is obtained, and the serialized data is transmitted through a shared memory region.
2. The Go program channel anomaly detection method based on deadlock risk graph as described in claim 1, characterized in that, The asymmetric read / write risk assessment specifically includes: The number of times the Go program sends a message through the channel is obtained using the first built-in function of the go function; The number of times the Go program's channel receives data can be obtained through the built-in second function of the `go` function. Preset smoothing factor extracted from the deadlock risk graph Go program channel database; The coupling results of the number of times the Go program channel sends data, the number of times the Go program channel receives data, and the preset smoothing factor are analyzed to obtain the channel sending and receiving ratio components. By performing a differential analysis on the coupling analysis results of the number of times the Go program channel sends data with the Go program channel ratio threshold and the number of times the Go program channel receives data, significant development components are obtained. The results of the coupling between the number of times the Go program channel sends data and the number of times the Go program channel receives data are subjected to square root analysis, and then coupled with a preset smoothing factor to obtain the sample size development component. The significance development component and the sample size development component are compared and analyzed to obtain the channel asymmetric significance component. The asymmetric read / write risk index is obtained by further coupling the channel transmit / receive ratio component with the channel asymmetric significance component.
3. The Go program channel anomaly detection method based on deadlock risk graph as described in claim 1, characterized in that, The risk assessment of the circular waiting chain specifically includes: When a Go program goroutine enters a waiting state due to channel blocking, its waiting chain is automatically recorded. The waiting path of the Go program goroutine is traced by depth-first search, and the total number of all nodes on the path is calculated to obtain the length of the blocking chain. The Go program has a built-in third function that records the start timestamp of the blocking wait due to channel blockage, records the end timestamp of the blocking wait when the operation is completed, performs a difference analysis between the end timestamp and the start timestamp of the blocking wait to obtain the single blocking duration of each node, and sums up the single blocking duration of each node in the entire waiting chain to obtain the total blocking duration. The Tarjan algorithm is used to detect waiting chain graphs. When a closed dependency cycle is found, the cycle structure flag is set to unit 1, and when there is no cycle structure, the cycle structure flag is set to unit 0. The length of the blocked chain and the total blocking time are normalized to obtain the normalized length and normalized time. The length weight and duration weight are extracted from the deadlock risk graph Go program channel database. The normalized length and length weight are coupled and analyzed to obtain the circular waiting chain length component. The normalized duration and duration weight are coupled and analyzed to obtain the circular waiting chain duration component. By coupling the cyclic waiting chain length component and the cyclic waiting chain duration component, a cyclic waiting chain risk index is obtained.
4. The Go program channel anomaly detection method based on deadlock risk graph as described in claim 1, characterized in that, The blockage and leakage risk assessment specifically includes: By instrumenting bytecode into predefined functions of the Go program to monitor points, the blocking duration of all threads is collected. The maximum value of the current cycle is obtained through the first predefined function of the Go program, thus obtaining the maximum blocking duration of the Go program. The maximum blocking duration of the Go program is compared and analyzed with the corresponding risk threshold of the maximum blocking duration of the Go program to obtain the blocking offset. The blocking offset is amplified by the curve steepness coefficient to obtain the blocking offset amplification component. The blocking offset amplification component is mapped to the interval from unit zero to unit one through the activation function to obtain the blocking duration mapping component. The target code block is scanned using predefined analysis to obtain the maximum timeout feedback coefficient of the Go program. If a timeout parameter is detected, the maximum timeout feedback coefficient of the Go program is set to one; otherwise, the maximum timeout feedback coefficient of the Go program is set to zero. By coupling the blocking duration mapping component with the maximum timeout feedback coefficient of the Go program, a blocking leakage risk assessment index is obtained.
5. The Go program channel anomaly detection method based on deadlock risk graph as described in claim 4, characterized in that, The blockage and leakage risk assessment also includes: If the blocking leakage risk assessment index is less than the third threshold of the blocking leakage risk assessment, then the pre-occupied memory resources are released and a three-dimensional deadlock risk map is constructed based on the assessment results. If the blocking leakage risk assessment index is equal to or greater than the third threshold of blocking leakage risk assessment and less than the second threshold of blocking leakage risk assessment, then CPU affinity optimization is performed. If the blocking leakage risk assessment index is equal to or greater than the second threshold of blocking leakage risk assessment and less than the first threshold of blocking leakage risk assessment, then concurrent channel restrictions and dynamic resource expansion will be implemented, and the nodes in the corresponding channels will be recorded as risk nodes. If the blockage and leakage risk assessment index is equal to or greater than the first threshold of the blockage and leakage risk assessment, then concurrent channel restrictions and physical isolation of hardware fault nodes will be implemented, and the nodes in the corresponding channels will be recorded as risk nodes.
6. The Go program channel anomaly detection method based on deadlock risk graph as described in claim 5, characterized in that, The construction of a three-dimensional deadlock risk map based on the assessment results specifically includes: For the asymmetric read / write risk index, circular wait chain risk index, and congestion / leakage risk assessment index, an adaptive outlier pruning algorithm is used. Scaling is combined with data standardization to scale them to a predefined data range, resulting in the scaled data ranges for the asymmetric read / write risk index, the circular wait chain risk index, and the congestion / leakage risk assessment index. A three-dimensional risk coordinate system is created based on the data ranges of the asymmetric read / write risk index, the circular wait chain risk index, and the blockage / leakage risk assessment index. LSTM is used to predict near-future weight requirements, and a constrained optimization model is applied to adjust the three-dimensional risk coordinate system.
7. The Go program channel anomaly detection method based on deadlock risk graph as described in claim 5, characterized in that, The construction of a three-dimensional deadlock risk map based on the assessment results also includes: Create an equally spaced 3D mesh, and assign different 3D risk coordinate data to the corresponding mesh cells to obtain a regular 3D mesh data structure model; Based on the predefined kernel density radius, the risk impact degree of the surrounding neighborhood is calculated for each grid cell under the regular three-dimensional grid data structure model. The comprehensive field strength is calculated by applying Gaussian kernel weighting to obtain the three-dimensional field strength matrix. Calculate the time series correlation between risk nodes, generate risk propagation edges, and obtain the risk propagation graph; Based on the three-dimensional field strength matrix and the risk propagation map, the risk correlation matrix is calculated, and a three-dimensional deadlock risk map is constructed.
8. The Go program channel anomaly detection method based on deadlock risk graph as described in claim 1, characterized in that, The second detection of Go program channel anomalies based on the three-dimensional deadlock risk map specifically includes: If the field strength value on the regular 3D grid in the 3D deadlock risk map is greater than the first warning threshold, then the corresponding regular 3D grid point is recorded as the warning regular 3D grid point, the regular 3D grid point corresponding to the largest value among the warning regular 3D grid points is recorded as the core warning regular 3D grid point, and the number of non-warning regular 3D grid points that are the closest to the core warning regular 3D grid point is recorded as the radius of influence points. Based on the radius of the number of influence points and the three-dimensional grid points of the core early warning rule, the three-dimensional area affected by the three-dimensional grid of the core early warning rule is obtained; The circuit breaker mechanism is triggered for all corresponding channels in the three-dimensional region affected by the core early warning rule three-dimensional grid, and resource expansion and allocation are performed for non-core early warning rule three-dimensional grid points outside the three-dimensional region affected by the core early warning rule three-dimensional grid.
9. A Go program channel anomaly detection device based on deadlock risk graph, employing the Go program channel anomaly detection method based on deadlock risk graph as described in any one of claims 1-8, characterized in that, This includes a lightweight data acquisition module for Go programs, a first-stage evaluation and detection module for Go program channel anomalies, a module for constructing a 3D deadlock risk map, and a second-stage evaluation and detection module for Go program channel anomalies. Lightweight data acquisition module for Go programs: Used to perform lightweight data acquisition during Go program runtime to obtain raw data from Go program channels; The first assessment and detection module for Go program channel anomalies is used to classify and assess deadlock risk patterns based on the raw data of the Go program channel. The deadlock risk pattern classification and assessment includes asymmetric read-write risk assessment, circular wait chain risk assessment, and blocking and leakage risk assessment. Based on the assessment results, the first assessment and detection of Go program channel anomalies is performed. Module for constructing a 3D deadlock risk map: Used to construct a 3D deadlock risk map based on the assessment results; The Go program channel anomaly second assessment and detection module is used to perform Go program channel anomaly second detection based on the three-dimensional deadlock risk map.
Citation Information
Patent Citations
Method and device for automatic deployment and chaos testing of blockchain based on Go language and ChaosBlade
CN116974649B
Go program channel blocking detection method and device based on channel operation priority
CN117473504B
Multi-transaction deadlock detection and processing method in resource-constrained equipment
CN120371556A
Database abnormal root cause positioning method and system based on knowledge graph
CN120849171A