Gateway device reconnection method, electronic device, storage medium, and program product
By using non-volatile memory to store a reconnection failure counter in the gateway device and employing non-linear discrete mapping and interruptible polling mechanisms, the large-scale reconnection storm and maintenance delay issues after device restart are resolved, enabling flexible reconnection control and rapid fault recovery.
Patent Information
- Application Number
- CN202611026149.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-10
- Publication Date
- 2026-11-27
AI Technical Summary
Existing gateway device reconnection methods reset the counter after device restart, causing a large number of devices to reconnect simultaneously, forming a reconnection storm and affecting the server connection queue; fixed-interval reconnection schemes cannot distinguish between network jitter and server failure, resulting in slow recovery speed; and the lack of an interruptible waiting mechanism affects operation and maintenance efficiency.
A non-volatile memory is used to store the reconnection failure counter. A non-linear discrete mapping relationship and an interruptible polling mechanism are used to achieve cross-restart persistence and flexible control of the backoff waiting time.
Eliminate the reconnection storm caused by reboots, improve recovery speed, differentiate the severity of faults, improve operational efficiency, and ensure that configurations take effect immediately.
Smart Images

Figure CN123185248A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of network communication technology, specifically to a gateway device reconnection method, electronic device, storage medium, and program product. Background Technology
[0002] In the field of embedded Internet of Things (IoT), gateway devices typically need to maintain persistent connections with cloud servers (e.g., Virtual Private Network (VPN) tunnels, Message Queuing Telemetry Transport (MQTT) brokers, Low Power Wide Area Network (LoRa) network servers, etc.). When a network connection is abnormally disconnected, the device needs to restore the connection through a periodic retry mechanism. To avoid overloading the target server due to a massive number of devices concurrently reconnecting at the same time, existing technologies typically employ an exponential backoff strategy. This means that after each failed reconnection, the waiting time increases exponentially until it reaches a preset maximum waiting time limit.
[0003] Currently, the existing backoff control solutions for reconnection of IoT gateway devices after disconnection mainly include the following: (1) Memory-based exponential backoff scheme: The device maintains a reconnection failure counter in volatile memory (such as RAM). After each reconnection failure, the waiting time is calculated according to a specific formula. After the device restarts, the counter will be cleared, causing the device to always start reconnecting from the shortest waiting time.
[0004] (2) Fixed interval reconnection scheme: After each restart or disconnection, the device waits for the same preset time (e.g., 30 seconds) before initiating a reconnection attempt, without accumulating or recording historical failure information.
[0005] (3) Random jitter backoff scheme: Random time jitter is superimposed on the standard exponential backoff scheme to reduce the probability of multiple devices reconnecting at the same time. However, the backoff state of this scheme is not persistently saved across restarts.
[0006] However, the aforementioned existing technical solutions have the following significant drawbacks in practical applications: First, for the above schemes (1) and (3), since the backoff state is only stored in volatile memory, the reconnection failure counter will be zero when the device restarts (whether it is an active restart, watchdog timeout reset, or power failure recovery). In scenarios where the server fails or the network experiences a large-scale outage, when power or network is restored, a large number of gateway devices will simultaneously initiate reconnection requests at the shortest interval (e.g., 0 to 2 seconds), thus triggering a severe "reconnection storm". This pulse-like concurrent impact will instantly exhaust the connection queue resources of the target server, causing all devices to fail to establish a connection, which may trigger a new round of device restarts and reconnections, forming a system-level congestion deadlock.
[0007] Secondly, the fixed reconnection interval in the above scheme (2) lacks flexibility and cannot effectively distinguish between two completely different fault scenarios: "intermittent network jitter" (requiring rapid reconnection to restore services) and "continuous server unavailability" (requiring long-term backoff to reduce server load). This not only severely slows down the service recovery speed after a normal disconnection, but also fails to effectively alleviate the concurrent pressure when the server experiences a continuous failure.
[0008] Finally, all the existing solutions mentioned above share a common drawback: a lack of support for "interruptible waiting" mechanisms. When a user actively modifies the device's network configuration or manually triggers an immediate reconnection command, if the device is in a backoff waiting period, the existing blocking waiting mechanism cannot be interrupted immediately. This means that the new configuration or command must wait until the current lengthy backoff period ends before taking effect. This results in significant response latency, severely impacting the device's operational efficiency and the system's real-time interaction capabilities. Summary of the Invention
[0009] This invention provides a gateway device reconnection method, an electronic device, a storage medium, and a program product.
[0010] According to one aspect of the present invention, a gateway device reconnection method is provided, comprising: in response to the device being powered on or restarted and the network connection being ready, reading a historical value of a network reconnection failure counter from a non-volatile memory; before each network reconnection attempt initiated by the device to the server, incrementing the historical value of the network reconnection failure counter by one to obtain the current value of the network reconnection failure counter, and writing the current value into the non-volatile memory; finding the backoff waiting time corresponding to the current value based on a non-linear discrete mapping relationship between the current value and the backoff waiting time, and obtaining the target backoff waiting time; and entering a backoff waiting state based on the target backoff waiting time. During the backoff waiting phase, the exit flag is periodically polled at a preset time granularity during the corresponding waiting period. If the exit flag is detected as set, the backoff waiting phase is interrupted and a network reconnection attempt is initiated to the server. If the accumulated time in the backoff waiting phase reaches the target backoff waiting duration and the exit flag is still not detected as set, a network reconnection attempt is initiated to the server. If the network reconnection attempt successfully establishes a connection with the server, the current value of the network reconnection failure counter is cleared to zero, and the cleared current value is written to non-volatile memory as the historical value of the network reconnection failure counter.
[0011] According to at least one embodiment of the gateway device reconnection method of the present invention, after reading the historical value of the network reconnection failure counter from the non-volatile memory, the method further includes: in the case of reading failure, initializing the historical value of the network reconnection failure counter to zero, wherein reading failure includes not reading the historical value or the reading data failing to be parsed.
[0012] According to at least one embodiment of the gateway device reconnection method of the present invention, after writing the current value to the non-volatile memory, the method further includes performing a data write-to-disk synchronization operation.
[0013] According to at least one embodiment of the gateway device reconnection method of the present invention, the nonlinear discrete mapping relationship between the current value and the backoff waiting time includes: mapping the current value to multiple discrete backoff waiting intervals, with different backoff waiting intervals corresponding to different backoff waiting times; the mapping function corresponding to the mapping process adopts a piecewise constant step function, so that as the current value increases, the backoff waiting time increases stepwise, and within the same backoff waiting interval, the backoff waiting time remains constant.
[0014] According to at least one embodiment of the gateway device reconnection method of the present invention, the mapping function is expressed as:
[0015] Where n represents the current value, Indicates the duration of the retreat and waiting period.
[0016] According to at least one embodiment of the gateway device reconnection method of the present invention, the setting of the exit flag bit is triggered by an external control signal, which includes a network configuration change command or a reconnection command triggered by a user.
[0017] According to another aspect of the present invention, an electronic device is provided, comprising: a memory storing execution instructions; and a processor executing the execution instructions stored in the memory, causing the processor to perform a gateway device reconnection method according to any embodiment of the present invention.
[0018] According to another aspect of the present invention, a readable storage medium is provided, wherein the readable storage medium stores execution instructions, which, when executed by a processor, are used to implement the gateway device reconnection method of any embodiment of the present invention.
[0019] According to another aspect of the present invention, a computer program product is provided, comprising a computer program that, when executed by a processor, implements a gateway device reconnection method according to any embodiment of the present invention.
[0020] The present invention has the following beneficial effects: (1) By incrementing the counter before each reconnection attempt and immediately writing it to non-volatile memory, and reading the historical value during restart, the lifecycle of the backoff state can be ensured to be elevated from the process level to the device level, so that the device can inherit the historical backoff level after encountering an unexpected power outage or restart, thereby effectively eliminating the pulse reconnection storm caused by the simultaneous restart of a large number of devices and protecting the target server connection queue.
[0021] (2) By using nonlinear discrete mapping relationship to form a piecewise constant ladder function, a customized backoff waiting time is matched for the number of reconnection failures in different intervals. This can take into account both the rapid recovery in occasional disconnection scenarios and the fine-grained hierarchical backoff in continuous fault scenarios, avoiding the recovery delay caused by the traditional exponential backoff entering the saturation zone too early, and effectively distinguishing faults of different severity.
[0022] (3) By periodically polling the exit flag bit at a preset time granularity during the backoff waiting period and immediately interrupting the waiting when the flag is detected, the traditional blocking waiting can be transformed into preemptible cooperative polling, so that network configuration changes or manual reconnection commands can take effect immediately, significantly improving the real-time interaction of the device and the efficiency of operation and maintenance management. Attached Figure Description
[0023] The accompanying drawings illustrate exemplary embodiments of the invention and, together with the description thereof, serve to explain the principles of the invention. These drawings are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification.
[0024] Figure 1 This is a flowchart illustrating a gateway device reconnection method according to an embodiment of the present invention.
[0025] Figure 2 This is a schematic diagram of the fault scenario types corresponding to the nine backoff waiting intervals according to one embodiment of the present invention.
[0026] Figure 3 This is a schematic diagram showing the comparison of backoff waiting times of a piecewise constant step function and a standard exponential backoff function under different retries according to an embodiment of the present invention.
[0027] Figure 4 This is a comparison chart showing the reconnection time distribution after 100 devices are restarted simultaneously according to one embodiment of the present invention.
[0028] Figure 5 This is a schematic diagram illustrating the number of devices located in different backoff waiting intervals after 100 devices are restarted simultaneously according to one embodiment of the present invention.
[0029] Figure 6 This is a schematic structural block diagram of an electronic device employing a processor-based hardware implementation according to an embodiment of the present invention. Detailed Implementation
[0030] The present invention will now be described in further detail with reference to the accompanying drawings and examples. It should be understood that the specific examples described herein are for illustrative purposes only and are not intended to limit the scope of the invention. Furthermore, it should be noted that, for ease of description, only the parts relevant to the present invention are shown in the accompanying drawings.
[0031] It should be noted that, unless otherwise specified, the embodiments and features described in this invention can be combined with each other. The technical solution of this invention will now be described in detail with reference to the accompanying drawings and embodiments.
[0032] Figure 1 A schematic diagram illustrating the overall flow of a gateway device reconnection method according to one embodiment of the present invention is shown. Figure 1 The method shown includes steps S1 to S5.
[0033] S1: In response to device power-on or restart and network connectivity ready, read the historical value of the network reconnection failure counter from non-volatile memory.
[0034] For example, the device can be an embedded IoT gateway device, and the non-volatile memory can be a local file system mounted on the device. In this case, the network reconnection failure counter can be stored in a configuration file of the local file system and stored as a separate counter field (err_flag).
[0035] As one possible implementation, after reading the historical value of the network reconnection failure counter from the non-volatile memory, the method further includes: initializing the historical value of the network reconnection failure counter to zero in the event of a read failure. Here, a read failure includes either not finding a historical value or a failure to parse the read data.
[0036] Step S1 ensures that the backoff state remains continuous after the device is powered on or restarted, and is not reset due to power-on or restart.
[0037] S2: Before each network reconnection attempt to the server, the historical value of the network reconnection failure counter is incremented by one, which is used as the current value of the network reconnection failure counter, and the current value is written to the non-volatile memory.
[0038] As one possible implementation, after writing the current value to non-volatile memory, the method further includes: performing a data write-to-disk synchronization operation (e.g., calling the operating system's fsync interface) to ensure that the current value of the network reconnection failure counter is not lost when the device experiences an unexpected power outage or abnormal restart.
[0039] S3: Based on the nonlinear discrete mapping relationship between the current value and the backoff waiting time, find the backoff waiting time corresponding to the current value and use it as the target backoff waiting time.
[0040] As one possible implementation, the nonlinear discrete mapping relationship between the current value and the backoff waiting time includes mapping the current value to multiple discrete backoff waiting intervals, with different backoff waiting intervals corresponding to different backoff waiting times.
[0041] The mapping function corresponding to the mapping process is a piecewise constant step function, which makes the backoff waiting time increase stepwise as the current value increases, and the backoff waiting time remains constant within the same backoff waiting interval.
[0042] In one example, the current value is mapped to nine discrete backoff waiting intervals, with the fault scenario types corresponding to the nine backoff waiting intervals as follows: Figure 2 As shown, the corresponding mapping function can be expressed as:
[0043] Where n represents the current value, Indicates the duration of the retreat and waiting period.
[0044] The design principles of the mapping function will be explained in detail below.
[0045] 1. Design basis for multiple retreat waiting intervals.
[0046] The backoff waiting time is subject to both a lower and upper limit. The lower limit is set to 0 seconds to ensure that in the event of intermittent network outages, the device can quickly initiate a reconnection attempt to restore the connection. The upper limit is set to 1800 seconds, which corresponds to the upper limit of the average fault response time for the operations and maintenance team. A backoff wait exceeding this duration cannot further reduce the concurrent impact on the server and has no actual business benefit.
[0047] Based on the principle of minimum effective difference threshold for system response perception, the time jump ratio between adjacent backoff waiting intervals should reach approximately 50% or more to ensure that the improvement of the backoff level has practical business control significance.
[0048] Based on the aforementioned constraints of lower and upper limits and jump ratios, to cover the complete backoff time spectrum from 0 seconds to 1800 seconds, at least 7 to 9 discrete backoff waiting intervals are required. This embodiment preferably sets the number of discrete backoff waiting intervals to 9 levels. This setting not only ensures complete coverage of the recovery time spectrum from transient network jitter to severe persistent faults, but also effectively avoids increased system parameter tuning complexity and frequent backoff state jitter caused by overly fine interval divisions.
[0049] 2. The design basis for setting the backoff waiting time of 0 seconds for the first 5 network reconnection attempts.
[0050] Based on statistical analysis of actual operational data from IoT gateways, approximately 60% to 70% of network outages are transient network jitter events lasting no more than 3 seconds (such as lost router heartbeat packets or brief attenuation of wireless signal strength). For such transient failure scenarios, the system should prioritize a zero-latency retry mechanism to accelerate connection recovery.
[0051] Therefore, in this embodiment, the backoff waiting time for the first 5 reconnection attempts is set to 0 seconds. This setting allows the device to maintain continuous reconnection attempts without delay during the period when the cumulative number of failures reaches 5 (corresponding to a dense retry time window of approximately 5 to 15 seconds). This design can effectively cover high-frequency transient failure scenarios, ensuring rapid restoration of network connectivity while avoiding the introduction of additional connection recovery delays due to unnecessary waiting time, thereby significantly improving the service continuity of the device in occasional disconnection scenarios.
[0052] 3. Design basis for non-uniform interval width setting.
[0053] The width of the first two backoff waiting intervals (corresponding to backoff waiting times of 0 seconds and 2 seconds) is set to 5 count units. Since the backoff waiting times of the first two intervals are relatively short, using a narrower interval width allows the device to quickly cross the low-wait-time interval when experiencing continuous connection failures, and then promptly enter the backoff phase with a longer wait time. If the width of the first two intervals is set to 10 count units, the device will maintain a short wait time of 0 seconds or 2 seconds until the cumulative number of failures reaches 20. In scenarios of persistent network failures, this can easily cause a continuous and high-intensity surge of reconnection requests to the target server.
[0054] Starting from the third backoff waiting interval, the width of each subsequent backoff waiting interval is uniformly set to 10 counting units. This setting provides ample space for counting accumulation for each backoff waiting duration level, effectively buffering the brief recovery and re-disconnection of the connection status caused by transient network fluctuations. This avoids frequent switching of the device's backoff level at the boundaries of adjacent intervals, ensuring the stability of the backoff control strategy and the continuity of hierarchical backoff.
[0055] 4. The design basis for setting the maximum retreat waiting time limit to 1800 seconds.
[0056] In this embodiment, the maximum backoff waiting time is set to 1800 seconds (i.e. 30 minutes). The selection of this value is mainly based on the following two constraints.
[0057] First, there's the constraint of enterprise-level IoT (Internet of Things) operation and maintenance response cycles. In actual operation and maintenance scenarios, the average alarm response and troubleshooting time is typically between 15 and 30 minutes. When a network failure lasts for more than 30 minutes, manual intervention becomes the primary means of fault recovery at this stage. At this point, further extending the automatic backoff waiting time of the device will no longer effectively alleviate the concurrent connection pressure on the target server, nor will it bring substantial business recovery benefits.
[0058] Secondly, there are constraints related to maintaining network path state and ensuring device survival. In wide area networks (WANs) or complex network architectures, some network middleware (such as NAT mapping tables and firewall connection tracking tables) typically have session timeout cleanup mechanisms. If a device has no data traffic interaction for an extended period, its network state entry will be automatically cleared by the system. By limiting the maximum backoff wait time to within 1800 seconds and maintaining regular probe reconnection, the active state of the underlying network path can be effectively maintained, avoiding the additional routing renegotiation overhead caused by network path state failures, thereby ensuring the rapid reconstruction of device connections after network failure recovery.
[0059] 5. The mapping function uses a piecewise constant step function instead of the standard exponential backoff function. , This represents the maximum backoff waiting time, and min() represents the minimization operator. This represents the design basis for the backoff waiting time obtained through the standard exponential backoff function.
[0060] (1) Piecewise constant step function has the following characteristics.
[0061] (a) Monotonicity within intervals: The piecewise constant step function remains constant within each interval; the backoff wait time remains unchanged as the current value increases within the same backoff wait interval. The standard exponential backoff function monotonically increases with each failed network reconnection, and the growth rate initially ( This exceeds the solution using a piecewise constant step function as described in this embodiment.
[0062] (b) Interval boundary jumps: The piecewise constant step function undergoes discrete jumps at the interval boundaries, with the jump proportions as follows: (0→2), 5×(2→10), 3×(10→30), 2×(30→60), 5×(60→300), 2×(300→600), 2×(600→1200), 1.5×(1200→1800); The overall trend is non-monotonic jumps, with a small jump ratio in the early stage and a large jump ratio in the middle stage, which can avoid excessively rapid growth in the middle stage.
[0063] (c) Saturation characteristics: Piecewise constant step function in The maintenance constant is 1800 seconds, exhibiting a hard saturation upper bound. Standard exponential backoff, on the other hand, achieves soft saturation through operator truncation. Both behave similarly after saturation, but their paths to saturation differ.
[0064] (2) The quantitative comparison between the piecewise constant step function and the standard exponential backoff function is as follows: Figure 3 The comparison of backoff wait times between the piecewise constant step function and the standard exponential backoff function under different retries is shown. Based on the above comparison results, the following difference analysis is performed: (a) Occasional disconnection scenario (n≤10): The standard exponential backoff function requires 128 seconds to wait after the 8th failure and 512 seconds after the 10th failure. The piecewise constant step function used in this invention only waits 2 seconds, improving the disconnection recovery speed by about 255 times (comparison after the 10th failure).
[0065] (b) Persistent Failure Scenario (n>10): The standard exponential backoff function enters the 1800-second saturation region after the 15th failure, after which it cannot distinguish between "moderate persistent failure" and "severe persistent failure". The piecewise constant step function used in this invention maintains graded backoff (10→30→60→300→600→1200 seconds) during the 11th to 70th failures, preserving the ability to distinguish between different failure levels.
[0066] (3) Quantitative analysis of resistance to reconnection storms: Scenario Assumptions: Assume there are 100 IoT gateway devices that remain operational during a server failure. Due to differences in the initial online time of each device, their accumulated network reconnection failure counters (err_flag) naturally fall into different numerical ranges during the failure period, exhibiting a discrete distribution. When the target server recovers and all 100 devices simultaneously restart, each device will load and inherit its respective historical values.
[0067] Behavior of existing technologies: In existing solutions that do not employ a backoff state persistence mechanism, the network reconnection failure counters of all devices are initialized to zero after a reboot, such as... Figure 4 As shown, all devices will immediately initiate a network reconnection attempt with a 0-second backoff wait period. This results in approximately 100 concurrent connection requests being generated instantaneously within a 0-5 second time window after the restart, triggering a severe pulsed reconnection storm that can easily cause the server connection queue to overflow.
[0068] The behavior of this invention is as follows: Figure 4 and Figure 5 As shown, in this invention, it is assumed that the network reconnection failure counter values of the 100 devices are evenly distributed within the range of 1 to 80. After the devices restart, due to the inheritance of historical values, at the 0th second after the restart, only devices with counter values in the range of 1 to 5 (accounting for approximately 6% of the total) will immediately initiate reconnection, causing the instantaneous concurrent connection request count to drop significantly from 100 to approximately 6, and the peak concurrency to decrease by approximately 94%. Subsequently, the reconnection requests of the remaining devices will be naturally and smoothly distributed across 9 different backoff time nodes over a time span of approximately 30 minutes, based on a nonlinear discrete mapping relationship.
[0069] Technical Results Summary: Through the above mechanism, the server's connection queue load is consistently maintained at a safe and controllable level. The quantitative analysis results demonstrate that this invention, through cross-restart persistence of the backoff state, enables the reconnection requests of the device cluster to achieve a natural, discrete distribution over time after a large-scale restart event. This solution reduces the instantaneous concurrent connection count by over 90% without relying on additional random jitter algorithms or centralized coordination mechanisms, fundamentally eliminating the reconnection storm problem caused by concentrated device restarts.
[0070] S4: Enter the backoff waiting phase based on the target backoff waiting duration. During the waiting period corresponding to the backoff waiting phase, periodically poll the exit flag at a preset time granularity (e.g., 1 second). If the exit flag is detected to be set, interrupt the backoff waiting phase and initiate a network reconnection attempt to the server. If the cumulative time in the backoff waiting phase reaches the target backoff waiting duration and the exit flag is still not detected to be set, initiate a network reconnection attempt to the server.
[0071] As one possible implementation, the exit flag being set can be triggered by an external control signal. External control signals include user-triggered network configuration change commands or reconnection commands.
[0072] In step S4, by setting an interruption method, user operations can be prevented from being blocked by a backoff period of up to 30 minutes.
[0073] S5: If the network reconnection attempt successfully establishes a connection with the server, clear the current value of the network reconnection failure counter to zero, and write the cleared current value to non-volatile memory as the historical value of the network reconnection failure counter.
[0074] Step S5 resets the backoff state after the connection is restored, so that the next disconnection starts with a fast retry and is not affected by historical failures.
[0075] As one possible implementation, the non-volatile memory is an embedded non-volatile memory module, suitable for embedded IoT gateway devices that do not have a local file system or have limited storage space. In this case, writing the current value to the non-volatile memory specifically includes: calling the key-value pair storage interface of the embedded non-volatile memory module to write data. The atomicity of the data write is guaranteed by the underlying driver of the embedded non-volatile memory module, replacing the explicit call to the operating system's forced synchronization interface for data persistence to disk.
[0076] As one possible implementation, when the device runs multiple long-connection services (such as VPN, MQTT, LoRaNS, etc.) simultaneously, an independent network reconnection failure counter field is assigned to each long-connection service, and all network reconnection failure counter fields are stored uniformly in non-volatile memory. Each long-connection service independently updates its corresponding historical value based on its corresponding network reconnection failure counter field, thereby achieving independent control of the backoff rhythm of each service without interference.
[0077] The present invention has the following significant and beneficial technical effects: (1) Achieve the persistence of the backoff state across restarts, fundamentally eliminating the "reconnection storm" caused by large-scale device restarts.
[0078] Existing technology stores the backoff counter in memory (RAM). When the device restarts, the counter is reset to zero, causing all devices to restart reconnection from the shortest waiting time. This can easily create a pulse-like "reconnection storm" when the server recovers from a failure or a large-scale power outage, instantly filling the server connection queue.
[0079] This invention achieves cross-reboot persistence of the backoff state by incrementing a counter and immediately writing it to non-volatile memory before each reconnection attempt. This invention elevates the backoff state's lifecycle from the "process level" to the "device level," making restarts no longer the boundary of the backoff state. In scenarios involving centralized restarts of device clusters, each device can inherit historical failure counts and maintain a corresponding high level of backoff, significantly reducing instantaneous concurrent connection requests (e.g., peak concurrency reduced by approximately 94%), effectively protecting the target server's connection queue and avoiding a vicious cycle of restarts and reconnections.
[0080] (2) A multi-level nonlinear discrete mapping is adopted to take into account both the rapid recovery of sporadic disconnection and the fine-grained distinction of continuous fault.
[0081] The standard exponential backoff strategy of existing technology requires a wait of 128 seconds after the 8th failure and 512 seconds after the 10th failure, which seriously slows down the recovery speed of occasional disconnections; and after the 15th failure, it quickly enters the 1800-second saturation zone, making it impossible to distinguish between moderate and severe persistent faults.
[0082] This invention innovatively employs a piecewise constant ladder function composed of nine discrete intervals, and performs piecewise customized optimization based on the actual disconnection distribution characteristics of IoT gateways: For transient jitter (fast recovery): The first 5 failures are set to wait for 0 seconds, covering about 65% of transient network jitter scenarios, which makes the recovery speed after occasional disconnection about 255 times faster than the standard exponential backoff (only 2 seconds are waited for the 10th failure), avoiding unnecessary recovery delays.
[0083] For persistent failures (fine-grained grading): During the 11th to 70th failures, a fine-grained grading backoff is maintained for 10 to 1200 seconds, mapping nine business semantic intervals (transient recovery region to saturation stable region) to the fault scenario assumptions. This enables the system to effectively distinguish persistent failures of different severity levels, avoiding the problem of traditional exponential backoff prematurely entering the saturation region and losing its fault differentiation ability, thus achieving a perfect balance between rapid recovery and long-term steady-state detection.
[0084] (3) An interruptible second-level polling waiting mechanism is introduced to significantly improve the real-time interaction of the device and the efficiency of operation and maintenance response.
[0085] Existing technologies typically employ blocking wait (such as the sleep(N) function or a timer) to complete the entire backoff period. This means that when a user actively modifies the network configuration or manually triggers a reconnection, the changes must take effect after the current backoff period ends, with a maximum delay of up to 30 minutes.
[0086] This invention designs an interruptible polling waiting mechanism with a 1-second time granularity, transforming traditional blocking waiting into preemptible cooperative polling. During the backoff waiting period, the system periodically checks the external exit flag. Any external event (such as configuration changes or manual reconnection commands) can immediately interrupt the current backoff waiting period and re-initiate a connection attempt within 1 second. This completely solves the configuration activation delay problem caused by long-cycle backoff, ensuring the effective execution of the backoff control strategy while also considering the system's real-time response capability and operational management efficiency.
[0087] According to a further embodiment of the present invention, an electronic device is also provided. Figure 6This diagram illustrates a schematic block diagram of an electronic device employing a processor-based hardware implementation according to an embodiment of the present invention. The hardware structure of the electronic device of the present invention can be implemented using a bus architecture. The bus architecture can include any number of interconnect buses and bridges, depending on the specific application and overall design constraints of the hardware. Bus 1100 connects various circuits including one or more processors 1200, memory 1300, and / or hardware modules. Bus 1100 can also connect various other circuits 1400 such as peripheral devices, voltage regulators, power management circuits, external antennas, etc. Bus 1100 can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Component (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, only one connecting line is used in this diagram, but this does not imply that there is only one bus or one type of bus. Memory 1300 stores a computer program, and when processor 1200 executes the computer program, processor 1200 is able to perform the following processes. In response to device power-on or restart and network connectivity readiness, the system reads the historical value of the network reconnection failure counter from non-volatile memory. Before each network reconnection attempt to the server, the historical value of the network reconnection failure counter is incremented by one, becoming the current value of the counter, and written to the non-volatile memory. Based on the non-linear discrete mapping between the current value and the backoff waiting time, the system finds the corresponding backoff waiting time as the target backoff waiting time. The system enters the backoff waiting phase based on the target backoff waiting time, and periodically polls the exit flag at a preset time granularity during the corresponding waiting period. If the exit flag is detected as set, the backoff waiting phase is interrupted, and a network reconnection attempt is initiated to the server. If the cumulative time in the backoff waiting phase reaches the target backoff waiting time and the exit flag is still not detected as set, a network reconnection attempt is initiated to the server. If a network reconnection attempt successfully establishes a connection with the server, the current value of the network reconnection failure counter is cleared to zero, and the cleared current value is written to non-volatile memory as the historical value of the network reconnection failure counter.
[0088] The present invention also provides a readable storage medium storing a computer program, which, when executed by a processor, is used to implement the methods described above. A "readable storage medium" can be any means capable of containing, storing, communicating, propagating, or transmitting a program for use by or in conjunction with an instruction execution system, apparatus, or device. More specific examples of a readable storage medium include: an electrical connection (electronic device) having one or more wires, a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and programmable read-only memory (EPROM or flash memory), fiber optic devices, and portable read-only memory (CDROM), etc.
[0089] This invention also provides a computer program product. The method of this invention can be implemented wholly or partially through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented wholly or partially in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instructions are loaded and executed, the processes or functions of this invention are performed wholly or partially.
[0090] Computer programs or instructions can be stored in a readable storage medium or transferred from one readable storage medium to another. For example, the computer program or instructions can be transferred from one website, computer, server, or data center to another website, computer, server, or data center via wired or wireless means. The readable storage medium can be any available medium capable of access, or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium, such as a floppy disk, hard disk, or magnetic tape; an optical medium, such as a digital video optical disc; or a semiconductor medium, such as a solid-state drive. The computer-readable storage medium can be a volatile or non-volatile storage medium, or it can include both volatile and non-volatile types of storage media.
[0091] 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.
[0092] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus, and computer program products according to 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.
[0093] 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.
[0094] 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.
[0095] In the description of this specification, the references to terms such as "one embodiment / mode," "some embodiments / modes," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, or characteristic described in connection with that embodiment / mode or example is included in at least one embodiment / mode or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment / mode or example. Moreover, the specific features, structures, or characteristics described may be combined in any suitable manner in one or more embodiments / modes or examples. Furthermore, without contradiction, those skilled in the art can combine and integrate the different embodiments / modes or examples described in this specification, as well as the features of different embodiments / modes or examples.
[0096] Those skilled in the art should understand that the above embodiments are merely for illustrating the present invention and are not intended to limit the scope of the invention. Those skilled in the art can make other changes or modifications based on the above disclosure, and these changes or modifications still fall within the scope of the present invention.
Claims
1. A method for reconnecting a gateway device, characterized in that, include: In response to device power-on or restart and network connectivity ready, read the historical value of the network reconnection failure counter from non-volatile memory; Before each network reconnection attempt to the server, the device increments the historical value of the network reconnection failure counter by one, uses it as the current value of the network reconnection failure counter, and writes the current value to non-volatile memory. Based on the nonlinear discrete mapping relationship between the current value and the backoff waiting time, find the backoff waiting time corresponding to the current value and use it as the target backoff waiting time. The system enters a backoff waiting phase based on the target backoff waiting time. During the waiting period corresponding to the backoff waiting phase, the exit flag is periodically polled at a preset time granularity. If the exit flag is detected to be set, the backoff waiting phase is interrupted and a network reconnection attempt is initiated to the server. If the cumulative time in the backoff waiting phase reaches the target backoff waiting time and the exit flag is still not detected to be set, a network reconnection attempt is initiated to the server. If a network reconnection attempt successfully establishes a connection with the server, the current value of the network reconnection failure counter is cleared to zero, and the cleared current value is written to non-volatile memory as the historical value of the network reconnection failure counter.
2. The gateway device reconnection method as described in claim 1, characterized in that, After reading the historical value of the network reconnection failure counter from non-volatile memory, the process also includes: In the event of a read failure, the historical value of the network reconnection failure counter is initialized to zero. A read failure includes either not reading a historical value or a failure to parse the read data.
3. The gateway device reconnection method as described in claim 1, characterized in that, After writing the current value to non-volatile memory, the process also includes performing a data write-to-disk synchronization operation.
4. The gateway device reconnection method as described in claim 1, characterized in that, The nonlinear discrete mapping relationship between the current value and the backoff waiting time includes: The current value is mapped to multiple discrete backoff waiting intervals, and different backoff waiting intervals correspond to different backoff waiting durations; The mapping function corresponding to the mapping process adopts a piecewise constant step function, which makes the backoff waiting time increase stepwise as the current value increases, and the backoff waiting time remains constant within the same backoff waiting interval.
5. The gateway device reconnection method as described in claim 4, characterized in that, The mapping function is expressed as: Where n represents the current value, Indicates the duration of the retreat and waiting period.
6. The gateway device reconnection method as described in claim 1, characterized in that, The exit flag is set when triggered by an external control signal, which may include a user-triggered network configuration change command or reconnection command.
7. An electronic device, characterized in that, include: The memory stores execution instructions; as well as A processor that executes the execution instructions stored in the memory, causing the processor to perform the gateway device reconnection method according to any one of claims 1 to 6.
8. A readable storage medium, characterized in that, The readable storage medium stores execution instructions, which, when executed by a processor, are used to implement the gateway device reconnection method according to any one of claims 1 to 6.
9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the gateway device reconnection method according to any one of claims 1 to 6.
