Anti-shake and update mutual exclusion based resident data acquisition process keep-alive method and system
By employing debouncing and update mutual exclusion to keep the resident data acquisition process alive, the problem of duplicate processes and resource consumption caused by multiple trigger sources is solved, and stable data acquisition is achieved under software updates and multiple operating environments.
Patent Information
- Application Number
- CN202611607565.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-16
- Publication Date
- 2026-11-27
AI Technical Summary
Existing resident data acquisition processes are prone to duplicate processes, port contention, and resource consumption under multiple triggering sources. Residual old versions can cause data acquisition interruptions during software updates, and process status judgments are inaccurate.
A method based on debouncing and update mutual exclusion is adopted. The keep-alive request is handled by debouncing through a shared heartbeat file and the current running baseline identifier. The update lock file is checked to ensure mutual exclusion with software updates. Health checks and process management are performed in combination with local monitoring configuration and service registration file.
It effectively avoids repeated triggering and inconsistencies after version switching, ensuring the stable operation of the data collection process in multi-trigger and self-updating scenarios, and reducing resource consumption and misjudgment.
Smart Images

Figure CN123178017A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of persistent data acquisition process keeping technology, and in particular to a persistent data acquisition process keeping method and system based on anti-jitter and update mutual exclusion. Background Technology
[0002] The technology for keeping resident data acquisition processes alive belongs to the technical fields of computer software operation and maintenance, background service management and process reliability assurance. It is mainly aimed at software processes that need to run for a long time and continuously perform data acquisition, status monitoring, communication interaction or device access tasks.
[0003] Existing persistent data acquisition process keep-alive technologies typically revolve around process existence, fixed-period checks, or scheduled task triggers. When login, periodic, and manual triggers occur simultaneously within a short period, each trigger may independently determine the acquisition process status and initiate startup operations separately. For example, a system login might trigger the acquisition service startup, followed immediately by a periodic scheduled task check. At this point, the previous process is still in the initialization phase, and subsequent checks may restart the same type of process, leading to duplicate processes, port contention, and resource consumption. In software update scenarios, the update program needs to replace executable files, configuration files, or dependent files. However, existing keep-alive processes may continue to execute according to the original plan. If the acquisition process exits during the update process, the old executable will be restarted, potentially causing files to be replaced to be occupied, parallel updates of old and new versions, and inconsistencies between update results and the current running instance. When relying solely on process identifiers to determine running status, the operating system can still consider the process alive. However, internal thread blocking, unresponsive local communication, or abnormal data acquisition capabilities may not be detected in time. For example, if the process identifier persists but the local service port does not return a healthy response, the daemon process may still consider it normal, resulting in prolonged data acquisition interruptions. Therefore, improvements are needed. Summary of the Invention
[0004] The purpose of this invention is to overcome the shortcomings of the existing technology and to propose a method and system for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion.
[0005] To achieve the above objectives, the present invention adopts the following technical solution: a persistent data acquisition process keep-alive method based on mutual exclusion of jitter and update, responding to keep-alive requests generated by multiple triggering sources, including the following steps:
[0006] Enter the headless entry point with headless command line parameters, and execute the keep-alive request before the single instance lock is requested in the graphical interface;
[0007] Read the local monitoring configuration to determine whether to continue keeping the application alive. If to continue, obtain the task namespace, expected capability declaration, current application execution path, and generate the current running baseline identifier.
[0008] Based on the shared heartbeat file and the current running baseline identifier debouncing, a keep-alive execution qualification is formed;
[0009] Check and update the lock file to determine whether to continue or terminate keep-alive;
[0010] Migrate keep-alive scheduled tasks based on the current application execution path and the headless command line parameters;
[0011] Read the service registration file, perform a level 2 health check according to the current operating baseline identifier, and generate a data collection service start request;
[0012] Based on the current operating baseline identifier, the collection service launch request is processed by single-flight merging, retry, and start-up grace period;
[0013] When the data collection service starts, a local loopback communication port is allocated, and the process identifier, the local loopback communication port, the authentication token, and the current running baseline identifier are written into the service registration file.
[0014] Preferably, the steps for establishing keep-alive execution eligibility based on the shared heartbeat file and the current running baseline identifier debouncing are as follows:
[0015] The keep-alive requests generated by login triggers, periodic scheduled task triggers, and manual triggers are associated with the same shared heartbeat file. The modification time and heartbeat baseline identifier of the shared heartbeat file are read, and the current time is obtained.
[0016] When the heartbeat baseline identifier is consistent with the current running baseline identifier, the time interval between the current time and the modified time is calculated, and the anti-shake window is read from the local monitoring configuration. If the time interval is less than the anti-shake window, the keep-alive request is terminated. If the time interval is not less than the anti-shake window, the modified time is updated and the keep-alive execution qualification is formed.
[0017] When the heartbeat baseline identifier is inconsistent with the current running baseline identifier, the current running baseline identifier is written as the heartbeat baseline identifier into the shared heartbeat file, the modification time is updated, and the keep-alive execution qualification is formed.
[0018] Preferably, the steps to check and update the lock file to determine whether to continue or terminate keep-alive are as follows:
[0019] After the keep-alive execution qualification is established, the update lock file is checked. When the software update starts, the update lock file is created and the lock modification time is recorded. When the update is completed, the update lock file is deleted.
[0020] If the update lock file exists, read the lock modification time and check time, read the update window from the local monitoring configuration, and calculate the lock duration between the check time and the lock modification time;
[0021] The keep-alive operation is terminated when the lock duration is less than the update window; the keep-alive operation continues when the update lock file does not exist; and the keep-alive operation continues when the update lock file exists and the lock duration is not less than the update window.
[0022] Preferably, the steps for reading the local monitoring configuration, determining whether to continue keeping the application alive, and obtaining the task namespace, expected capability declaration, current application execution path, and generating the current runtime baseline identifier are as follows:
[0023] Read the development mode flag, task namespace identifier, and expected capability declaration from the local monitoring configuration;
[0024] The development mode marker indicates that the current keep-alive operation ends when the development mode is activated.
[0025] When the development mode marker indicates the production mode, the task namespace is determined based on the task namespace identifier, the current application execution path is obtained, and serialization is performed in the order of the task namespace, the current application execution path, and the expected capability declaration. A digest is calculated on the serialization result to obtain the current running baseline identifier.
[0026] Preferably, the steps of reading the service registration file, performing a secondary health check according to the current operating baseline identifier, and generating a data collection service start request are as follows:
[0027] The service registration file is checked. If the service registration file does not exist, the collection service start request is generated and the secondary health check is terminated. If the service registration file exists, the process identifier, local loopback communication port, authentication token, registered running baseline identifier are read, and the consecutive failure count is obtained.
[0028] The process identifier is used to determine whether the data collection service process is alive. If the data collection service process does not exist, a data collection service start-up request is generated.
[0029] When the data collection service process is alive and the registered running baseline identifier is inconsistent with the current running baseline identifier, the data collection service process is terminated and the data collection service restart request is generated.
[0030] When the data collection service process is alive and the registered running baseline identifier is consistent with the current running baseline identifier, a health request is initiated to the local loopback health check endpoint based on the local loopback communication port and the authentication token. If the health request response is successful and the returned capability statement is consistent with the expected capability statement, the secondary health check is determined to have passed; otherwise, the secondary health check is determined to have failed.
[0031] When the Level 2 health check passes, the consecutive failure count is reset to zero; when it fails, the consecutive failure count is incremented and the consecutive failure threshold is read. When the consecutive failure count reaches the consecutive failure threshold, the data collection service process is terminated and a data collection service restart request is generated; otherwise, the data collection service process is retained.
[0032] Preferably, the steps of entering the headless entry point with headless command-line parameters and executing the keep-alive request before the single-instance lock is requested in the graphical interface are as follows:
[0033] After the application process starts, the command line parameters are parsed, and the headless entry point is entered when the command line parameters match the headless command line parameters.
[0034] Once the application is ready, the keep-alive request is executed through the headless entry point. After the keep-alive request is completed, the application process exits and skips the graphical interface single-instance lock application and graphical interface creation.
[0035] Preferably, the steps for migrating keep-alive scheduled tasks based on the current application execution path and the headless command-line parameters are as follows:
[0036] Query the keep-alive scheduled tasks in the task namespace, and extract the execution body path, script call information, and command line parameters from the execution commands of the keep-alive scheduled tasks;
[0037] When at least one of the following is true: the execution path is inconsistent with the current application execution path, the script call information points to an external script, or the command line parameters do not include the headless command line parameters, the keep-alive scheduled task needs to be migrated.
[0038] Delete the keep-alive scheduled task that needs to be migrated, and reconstruct the keep-alive scheduled task that calls the headless entry point according to the current application execution path, the headless command line parameters, and the task namespace.
[0039] Preferably, the steps of performing single-flight merging, retry, and start-up grace processing on the collection service launch request based on the current operating baseline identifier are as follows:
[0040] A start-up key is generated based on the current running baseline identifier. The shared start-up status corresponding to the start-up key is queried. If it does not exist, the shared start-up status is created and the process is started. If it exists, the collection service start-up requests with the same start-up key are merged and the start-up results are reused.
[0041] When the process fails to start, the maximum number of retries and the baseline waiting time are read from the local monitoring configuration, and the process is retried according to the maximum number of retries. The waiting time formula is: ,in Indicates the first Waiting time before the next retry This represents a dimensionless integer starting from 1 and not greater than the maximum number of retries. This represents the baseline waiting time;
[0042] Before each retry, the secondary health check is performed. If the secondary health check passes, subsequent retries are terminated and the data collection service process is reused.
[0043] After the new data collection service process is successfully started, the start time is recorded and the start grace period is read from the local monitoring configuration. The consecutive failure count is not increased during the start grace period starting from the start time. The start grace period ends early when the secondary health check is passed. After the expiration, the consecutive failure count is restored and updated according to the results of the secondary health check.
[0044] When the process restart process ends, the restart result is recorded and the shared restart state is released.
[0045] Preferably, the steps of allocating a local loopback communication port and writing the process identifier, the local loopback communication port, the authentication token, and the current running baseline identifier into the service registration file when the data collection service starts are as follows:
[0046] After the data collection service is started, it binds port number 0 to the local loopback address, and the operating system allocates the local loopback communication port from the unused ports.
[0047] Obtain the process identifier of the collection service and generate the authentication token, determine the current running baseline identifier as the registered running baseline identifier, and form service registration information including the process identifier, the local loopback communication port, the authentication token and the registered running baseline identifier;
[0048] The service registration information is written to a temporary registration file, and the temporary registration file is then atomically replaced after the temporary registration file is written.
[0049] The present invention also provides a system comprising:
[0050] Headless Entry Module: Enters the headless entry point with headless command line parameters and executes the keep-alive request before the single-instance lock is requested in the graphical interface;
[0051] Configuration determination module: Reads local monitoring configuration, determines whether to continue keeping the application alive, and if so, obtains the task namespace, expected capability declaration, current application execution path and generates the current running baseline identifier;
[0052] Anti-shake qualification module: Based on the shared heartbeat file and the current running baseline identifier, anti-shake is used to form keep-alive execution qualification;
[0053] Update mutex module: Check the update lock file to determine whether to continue or terminate keep-alive;
[0054] Task migration module: Migrate keep-alive scheduled tasks based on the current application execution path and the headless command line parameters;
[0055] Health check module: Reads the service registration file, performs a secondary health check according to the current operating baseline identifier, and generates a data collection service start request;
[0056] The start-up control module performs single-flight merging, retry, and start-up grace period processing on the acquisition service start-up request based on the current operating baseline identifier.
[0057] Service registration module: When the collection service starts, it allocates a local loopback communication port and writes the process identifier, the local loopback communication port, the authentication token, and the current running baseline identifier into the service registration file.
[0058] Compared with the prior art, the advantages and positive effects of the present invention are as follows:
[0059] In this invention, by identifying headless command-line parameters before applying for a single-instance lock in the graphical interface, keep-alive requests can enter background processing along an execution path independent of the graphical interface startup process, reducing the interference of keep-alive triggers on the interface instance state, focus state, and single-instance mutual exclusion relationship. After reading the local monitoring configuration, the task namespace, expected capability declaration, and current application execution body path are jointly incorporated into the current running baseline identifier, so that subsequent debouncing, scheduled task migration, health checks, process startup, and service registration are associated around the same running baseline, avoiding contradictory judgments made by each link based on local states. The shared heartbeat file performs debouncing by combining the current running baseline identifier with the trigger time, which can merge similar keep-alive requests formed by login, periodic scheduled tasks, and manual operations in the same running environment, while ensuring that keep-alive requests after changes in execution body path, running environment, or capability requirements are not erroneously suppressed by the old running state, thus taking into account both repeated trigger suppression and timely recovery after version switching. After obtaining keep-alive execution qualification, the update lock file is checked, so that the process protection action and the software update process form a time-sequential mutual exclusion relationship, reducing the probability of old process restarting, file occupation, and coexistence of old and new versions during file replacement. By checking and migrating keep-alive scheduled tasks based on the current application execution path and headless command-line parameters, the trigger entry point after software upgrades can be kept consistent with the current execution body, reducing version deviations caused by old scripts and paths continuing to participate in keep-alive. The service registration file further stores process identifiers, local loopback communication ports, authentication tokens, and the current running baseline identifier. The secondary health check not only determines whether the data collection service process exists but also, based on local communication responses, capability declarations, and running baseline consistency, determines whether the current process belongs to the expected running instance. This ensures that processes that are alive but have communication failures, capability mismatches, or old version remnants can all enter targeted exception handling processes. After generating a data collection service launch request, the scope of single-flight merging is constrained by the current running baseline identifier, allowing concurrent launch requests corresponding to the same running target to reuse the same execution result. Simultaneously, failure retries and startup grace periods mitigate misjudgments caused by momentary startup failures and new processes not yet completing service registration. After the data collection service starts, the operating system allocates a local loopback communication port and writes the port information, process identity, authentication information, and operating benchmark into the service registration file. This allows the startup results to be used as input for subsequent health checks, forming a closed-loop, live link from triggering, debouncing, update yielding, health judgment, abnormal startup to service re-registration. This enhances the overall stability of the resident data collection process in scenarios with multiple trigger sources, self-updates, and multiple operating environments. Attached Figure Description
[0060] Figure 1 This is a schematic diagram of the steps of the present invention. Detailed Implementation
[0061] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0062] This embodiment is applicable to data acquisition clients that need to reside and run on a terminal device for a long time. The terminal device can be a personal computer, industrial computer, or data acquisition terminal running a Windows operating system. The data acquisition client includes an application executor and an acquisition service process launched by the application executor. The acquisition service process is used to continuously complete data acquisition, local communication, and operation status response.
[0063] In this embodiment, login triggering, periodic scheduled task triggering, and manual triggering all invoke the same application executor and form a keep-alive request. Login triggering refers to the application executor being invoked by the login startup item or scheduled task after the user completes operating system login. Periodic scheduled task triggering refers to the operating system invoking the application executor according to a preset time period. Manual triggering refers to maintenance personnel actively executing application execution commands with headless command-line parameters. This embodiment sets the trigger period of the periodic scheduled task to 60 seconds. This setting is greater than the 50-second debouncing window, allowing normal adjacent periodic checks to continue executing, while login triggering, periodic triggering, and manual triggering that overlap within a short period are debounced.
[0064] This implementation uses a local monitoring configuration file to store the runtime parameters required for the keep-alive process. The local monitoring configuration file is a UTF-8 encoded JSON file, written during software installation or initial initialization, and allows modification during software updates according to a predetermined configuration strategy. When reading the local monitoring configuration file, integrity checks and value range checks are performed on all required fields. If any required field is missing, has an incorrect data type, or exceeds the allowed range, the keep-alive operation ends and a configuration anomaly is recorded. The production data acquisition service is not terminated or restarted under uncertain configuration conditions.
[0065] Table 1 Parameter settings for this embodiment
[0066] Configuration Project Specific settings Setup method Basis for setting and purpose Development mode tags false Set the devMode field in the local monitoring configuration. false indicates that production keep-alive is allowed. Task namespace identifier collector-prod Set the namespace field in the local monitoring configuration Differentiate between planned tasks and operational status documents in the production environment Expected Capability Statement collector-v2 Set the expectedCapability field in the local monitoring configuration. Used to verify whether the current data collection service has the expected capabilities. Cyclic planning task cycle 60 seconds Write the trigger period when creating a scheduled task Larger than the debounce window, ensuring that normal cycle keep-alive is not suppressed. Image stabilization window 50 seconds Configure the debounceWindow field in the local monitoring configuration. Suppressing short-term repeated keep-alive requests Shared heartbeat file exclusive lock wait limit 1 second Configure the heartbeatLockTimeout field in the local monitoring configuration. To prevent concurrent keep-alive requests from waiting for an extended period of time on the same shared file. Update window 900 seconds Configure the updateWindow field in the local monitoring configuration. Determine if the update lock still indicates a valid update process. Update lock refresh cycle 60 seconds Update program internal settings During long-term update periods, the update lock modification time is periodically refreshed. Health request timeout 1 second Set the healthTimeout field in the local monitoring configuration. Limit the maximum waiting time for a single local health check. consecutive failure threshold 5 times Configure the failureThreshold field in the local monitoring configuration. Processes that are identified as alive but continue to fail to respond normally. Normal exit waiting time 3 seconds Configure the shutdownTimeout field in the local monitoring configuration. Provide a normal exit time for the collection service to be recycled. Maximum number of retries 3 times Configure the maxRetry field in the local monitoring configuration. Limit the number of times a single pull-up process can be restarted. Baseline waiting time 1 second Configure the retryBaseInterval field in the local monitoring configuration. Calculate the waiting time before each pull-up retry. Start the grace period 5 seconds Configure the startupGracePeriod field in the local monitoring configuration. Protect the normal initialization process of the data acquisition service Solo flight results awaiting upper limit 30 seconds Set the singleflightTimeout field in the local monitoring configuration. To prevent processes waiting for other start requests from being blocked indefinitely. Solo Flight Status Inquiry Cycle 100 milliseconds Configure the singleflightPollInterval field in the local monitoring configuration. Regularly check the shared startup status and registration results. Authentication token length 128-bit Fixed settings in the data collection service startup logic Provides random authentication data for local health requests Headless command line arguments --guard-collector Predefined in application startup parameter parsing logic Enter the non-graphical interface keep-alive execution entry point
[0067] As shown in Table 1, each time threshold, count threshold, and limit has a defined storage location, retrieval method, and example value. Specifically, the debouncing window, update window, consecutive failure threshold, maximum number of retries, and startup grace period are set to 50 seconds, 900 seconds, 5 times, 3 times, and 5 seconds, respectively. For different operating environments, the corresponding fields can be modified in the local monitoring configuration; however, during a single keep-alive execution, each parameter remains unchanged after a successful read.
[0068] Example 1, please refer to Figure 1 This invention provides a technical solution for keeping a resident data acquisition process alive based on the mutual exclusion of jitter stabilization and updates, responding to keep-alive requests generated by multiple triggering sources, including the following steps:
[0069] Specifically, login triggers, periodic scheduled task triggers, and manual triggers all generate keep-alive requests by invoking the current application executor. Each trigger source does not establish an independent daemon state; instead, they access the shared heartbeat file, update lock file, and service registration file corresponding to the current task's namespace, enabling different trigger sources to perform keep-alive checks based on the same running state.
[0070] Enter the headless entry point with headless command-line parameters and execute a keep-alive request before the single-instance lock is requested in the graphical interface;
[0071] Specifically, in the first stage after the application executor starts, the runtime basic environment is initialized and the startup command line is parsed. In this implementation, `--guard-collector` is set as a headless command-line parameter. When the command-line parameter includes `--guard-collector`, the application executor enters the headless entry point. The headless entry point is located before the graphical interface single-instance lock request logic. Therefore, after entering the headless entry point, no graphical interface single-instance lock is requested, and no window, tray icon, or interface objects requiring user interaction are created.
[0072] Read the local monitoring configuration to determine whether to continue keeping the application alive. If to continue, obtain the task namespace, expected capability declaration, current application execution path, and generate the current running baseline identifier.
[0073] Specifically, the development mode flag, task namespace identifier, expected capability declaration, and various runtime parameters are read from Table 1. When the development mode flag is false, production keep-alive is executed. The collector-prod is obtained as the task namespace based on the namespace field, the collector-v2 is obtained as the expected capability declaration based on the expectedCapability field, and the current application execution path is obtained by calling the operating system's current process executable file path query interface.
[0074] After obtaining the current application execution path, the path is converted into a normalized absolute path. In the Windows implementation environment, the relative path components in the path are parsed and the directory separator rules are standardized. Path comparisons use the case-insensitive Windows path comparison rules. Subsequently, a summary input is constructed according to a fixed order of task namespace, current application execution path, and expected capability declarations.
[0075] To prevent ambiguity at field boundaries caused by simple delimiters, this implementation uses a length prefix for serialization. Each field is converted to a UTF-8 byte sequence, and a 4-byte unsigned integer representing the field's byte length is written before each field. The integer follows network byte order. After writing the three fields sequentially, a unique serialized byte sequence is obtained. A SHA-256 digest operation is performed on the serialized byte sequence, and the resulting 256-bit digest is converted into 64 hexadecimal characters to obtain the current running baseline identifier.
[0076] Based on shared heartbeat files and current operating baseline identifiers, debouncing is performed to establish keep-alive execution qualifications;
[0077] Specifically, all keep-alive requests within the same task namespace access the same shared heartbeat file. The shared heartbeat file stores at least a heartbeat baseline identifier, and the file system modification time is used to record the time when keep-alive execution was most recently acquired. Exclusive file locks are acquired during the reading, comparison, and updating of the shared heartbeat file, preventing two concurrent keep-alive requests from simultaneously acquiring keep-alive execution qualification based on the same old state.
[0078] Check and update the lock file to determine whether to continue or terminate keep-alive;
[0079] Specifically, the software update program creates an update lock file before replacing the application executable, data collection service files, and dependency files, and deletes the update lock file after the update process is completed normally. The update program rewrites the update lock file every 60 seconds to keep the file modification time within the valid update window. The keep-alive executable determines whether it is still in the update process based on the update lock modification time.
[0080] Migrate keep-alive scheduled tasks based on the current application execution path and headless command-line arguments;
[0081] Specifically, the system queries the registered keep-alive scheduled tasks in the current task namespace and compares the actual execution path, script call information, and command-line arguments in the scheduled tasks with the current running status. If an old execution path, external script call, or missing `--guard-collector` parameter exists, the corresponding task is deleted and rebuilt as a scheduled task that directly calls the current application's execution body without a headless entry point.
[0082] Read the service registration file, perform a level 2 health check based on the current operating baseline identifier, and generate a data collection service start request;
[0083] Specifically, the first-level check queries the operating system process status based on the process identifier stored in the service registration file. The second-level check initiates a request with an authentication token to the health check endpoint of the data collection service via the local loopback communication port and verifies the returned capability declaration. If a process exists but the local health request continues to fail, the system uses a consecutive failure count to determine whether it belongs to an abnormal state that needs to be reclaimed.
[0084] Based on the current operating baseline identifier, the collection service initiation request is processed by single-flight merging, retry, and start-up grace period;
[0085] Specifically, a unique start-up key is generated based on the current operating baseline identifier. Concurrent data acquisition service start-up requests corresponding to the same start-up key share the same start-up state. Only one request actually executes process creation, while the remaining requests wait for and reuse the results of the actual start-up request. When a start-up fails, retrying is performed at linearly increasing intervals according to the preset maximum number of retries. After a new process is successfully created, a 5-second startup grace period is entered.
[0086] When the data collection service starts, it allocates a local loopback communication port and writes the process identifier, local loopback communication port, authentication token, and current running baseline identifier into the service registration file.
[0087] Specifically, the data collection service binds port number 0 on 127.0.0.1, and the operating system allocates an unused port, which is then read as the local loopback communication port. The data collection service obtains its own process identifier and generates a 128-bit authentication token. This information, along with the current running baseline identifier, is written to the service registration file, enabling the next keep-alive request to locate the corresponding process and health check endpoint.
[0088] Example 2, the specific steps for forming keep-alive execution eligibility based on shared heartbeat files and current running baseline identifier debouncing are as follows:
[0089] Specifically, a unique shared heartbeat file is set in the data directory of the collector-prod task namespace. Login triggers, periodic scheduled task triggers, and manual triggers all access the shared heartbeat file, and debouncing status is not maintained separately according to the trigger source.
[0090] Associate keep-alive requests triggered by login, periodic scheduled tasks, and manual triggers with the same shared heartbeat file, read the modification time and heartbeat baseline identifier of the shared heartbeat file, and obtain the current time.
[0091] Specifically, the keep-alive executor first requests exclusive access to the shared heartbeat file, with a maximum waiting time of 1 second. Upon successful request, it reads the heartbeat baseline identifier and file modification time; if exclusive access is not obtained within 1 second, the current request is considered concurrent with other ongoing keep-alive requests, and the current request ends immediately.
[0092] The current time used to compare the modification time of the shared heartbeat file with the file system modification time uses the same UTC wall clock reference. In practice, the file system modification time is converted to a Unix timestamp, and the current system UTC time is converted to the same timestamp before calculating the difference.
[0093] When the heartbeat baseline identifier is consistent with the current running baseline identifier, calculate the time interval between the current time and the modified time, read the anti-shake window from the local monitoring configuration, and end the keep-alive request if the time interval is less than the anti-shake window; otherwise, update the modified time and form keep-alive execution qualification.
[0094] Specifically, the debouncing window is 50 seconds. When the calculated time interval is 20 seconds, the request is within the debouncing window and terminates immediately; when the time interval is 60 seconds, the modification time of the shared heartbeat file is updated to the current UTC time and execution continues. If the system clock is manually adjusted, causing the current time to be earlier than the file modification time, the time interval is treated as 0 seconds, so the request will not incorrectly bypass the debouncing window due to a negative time interval.
[0095] The update operation of the heartbeat file modification time and the write operation of the heartbeat baseline identifier are both completed before the exclusive file lock is released. After the write is completed, the file buffer is flushed and the file handle is closed so that subsequent concurrent keep-alive requests can read the complete new state.
[0096] When the heartbeat baseline identifier is inconsistent with the current operating baseline identifier, the current operating baseline identifier is written to the shared heartbeat file as the heartbeat baseline identifier, the modification time is updated, and the keep-alive execution qualification is formed.
[0097] Specifically, any change to the current application execution path, task namespace, or expected capability declaration will alter the current runtime baseline identifier. Therefore, the heartbeat state saved in the old version will not suppress the first keep-alive request for the new runtime baseline. After writing the new heartbeat baseline identifier and modification time, the exclusive lock on the shared heartbeat file is released, so that subsequent requests for the same runtime baseline are again subject to the 50-second debouncing window.
[0098] Example 3, the specific steps for checking and updating the lock file to determine whether to continue or terminate keep-alive are as follows:
[0099] Specifically, the update lock file is set in the data directory corresponding to the current task namespace, and is created, refreshed, and deleted by the update program during normal software update.
[0100] After obtaining the qualification to keep alive, check the update lock file. When the software update starts, create the update lock file and record the lock modification time. When it is completed, delete the update lock file.
[0101] Specifically, the updater creates an update lock file before stopping the old data collection service and replacing files. For update tasks lasting more than 60 seconds, the updater rewrites the update lock file and refreshes the file modification time every 60 seconds; after completing all file replacements, version verification, and new file integrity checks, the update lock file is deleted.
[0102] If the lock file exists, read the lock modification time and check time, read the update window from the local monitoring configuration, and calculate the lock duration by comparing the check time and lock modification time.
[0103] Specifically, the update window is set to 900 seconds, and both the check time and lock modification time use the Unix timestamp corresponding to the UTC wall clock. The lock duration is the check time minus the lock modification time. Since the modification time is refreshed every 60 seconds during a normal update process, the lock duration for a normally continuously running update process usually does not exceed 60 seconds, which is significantly less than 900 seconds.
[0104] If the lock duration is less than the update window, terminate the current keep-alive operation. If the update lock file does not exist, continue the keep-alive operation. If the update lock file exists and the lock duration is not less than the update window, continue the keep-alive operation.
[0105] Specifically, if an update lock exists and its duration is 300 seconds, the update is still considered to be in progress, and the keep-alive operation ends. When the lock duration reaches 900 seconds, it indicates that the update lock has not been refreshed by the update program for at least 900 consecutive seconds. This implementation classifies it as an abnormal residual update lock, allows it to continue to be kept alive, and deletes the abnormal residual update lock after obtaining exclusive access to the update lock file. By combining a 60-second refresh cycle and a 900-second update window, it is possible to distinguish between software updates that have been running normally for a long time and lock files left behind after the update program has abnormally exited.
[0106] Example 4: Reading local monitoring configuration, determining whether to continue keep-alive, and if so, obtaining the task namespace, expected capability declaration, current application execution path, and generating the current running baseline identifier are specifically as follows:
[0107] Read the development mode flag, task namespace identifier, and expected capability declaration from the local monitoring configuration;
[0108] Specifically, the `devMode` field in the local monitoring configuration is a boolean value, while the `namespace` and `expectedCapability` fields are non-empty strings. In this implementation, the corresponding values are `false`, `collector-prod`, and `collector-v2`, respectively. When reading the configuration, the above fields are type-checked; if reading any required field fails, the keep-alive operation ends.
[0109] The development mode flag indicates that the current keep-alive operation ends when development mode is activated.
[0110] Specifically, when devMode is set to true, the headless entry point does not perform production service health checks, process recycling, collection service startup, and production plan task migration, and directly terminates the current keep-alive operation, thereby avoiding changes to the running state in the production namespace by the development runtime environment.
[0111] When the development mode tag indicates the production mode, the task namespace is determined based on the task namespace identifier, the current application execution path is obtained, and serialization is performed in the order of task namespace, current application execution path, and expected capability declaration. A digest is calculated on the serialization result to obtain the current runtime baseline identifier.
[0112] Specifically, the current runtime baseline identifier is generated according to the aforementioned length prefix serialization rule. First, the collector-prod, the normalized absolute path of the current application execution body, and the collector-v2 are encoded into UTF-8 byte data. A 4-byte network byte order length is added before each field, and then the three fields are concatenated sequentially. After concatenation, a standard SHA-256 digest operation is performed, converting the 256-bit result into a 64-bit hexadecimal string. No random numbers are involved in the entire calculation process, therefore, the same input yields a completely identical current runtime baseline identifier.
[0113] Example 5, the steps for reading the service registration file, performing a level-two health check according to the current operating baseline identifier, and generating a data collection service start request are as follows:
[0114] Specifically, the service registration file is stored as a UTF-8 encoded JSON file and includes at least the process identifier, local loopback communication port, authentication token, and registered runtime baseline identifier. This implementation further writes the consecutive failure count and startup time into the same service registration file to ensure that consecutive keep-alive ticks executed by different headless application processes can share the failure state.
[0115] Table 2 Service Registration File Field Settings
[0116] Fields Example value Data types and generation methods How to use Process ID 18436 Positive integer; the data collection service reads its own operating system process ID. Determine if the process exists Local loopback communication port 49172 Integers between 1 and 65535, read from the bound port number 0. Establish local health connection Authentication token A hexadecimal string of 128 random data. 16-byte random data generated by the operating system's cryptographically secure random source Verify the source of the health request Registered operating benchmark identifier 64-bit hexadecimal string The current operating baseline identifier is written directly. Determine if the service is consistent with the current operating environment. Continuous failure count 0 Non-negative integers, initialized to 0 upon initial registration. A cumulative number of failed health checkups Startup time UTC timestamp Record when process is successfully created Calculate the startup grace period
[0117] As can be seen from Table 2, each field in the service registration file has a definite data source, data type, and usage location. The keep-alive executor can determine the process identity, IPC address, authentication information, running version relationship, and continuous health status based on a complete service registration record.
[0118] Check the service registration file. If the service registration file does not exist, generate a collection service start request and end the secondary health check. If the service registration file exists, read the process identifier, local loopback communication port, authentication token, registered running baseline identifier, and obtain the consecutive failure count.
[0119] Specifically, if the service registration file does not exist, it means that there is currently no registered collection service that can be discovered by the guardian logic, and a collection service start request is directly generated. If the service registration file exists, an integrity check is performed on the process identifier, local loopback communication port, authentication token, registered running baseline identifier, and consecutive failure count fields. If any field is missing or the data type is incorrect, the registration record is considered an invalid registration record, and a collection service start request is generated.
[0120] The consecutive failure count is set to 0 when the service registration file is first created. When updating the consecutive failure count in subsequent updates, the original file is not overwritten directly. Instead, it is updated using a temporary file with atomic replacement, just like in the service registration process, thus avoiding concurrent reads that obtain partial write status.
[0121] The system determines whether the data collection service process is alive based on the process identifier. If the data collection service process does not exist, a request to start the data collection service is generated.
[0122] Specifically, the corresponding process is queried by process identifier through the operating system process query interface. To reduce the risk of misjudgment caused by the operating system reallocating the process ID, this implementation also verifies whether the executable file path of the queried process matches the current data collection service execution path; if the process ID does not exist or the execution path does not match, it is treated as if the data collection service process does not exist, and a data collection service start request is generated.
[0123] If the data collection service process is alive and the registered running baseline identifier is inconsistent with the current running baseline identifier, the data collection service process will be terminated and a data collection service restart request will be generated.
[0124] Specifically, this state indicates that the current process belongs to the old execution path, old task namespace, or old capability requirements. The keep-alive execution first sends a normal exit request to the acquisition service and waits for 3 seconds. If the acquisition service exits normally within 3 seconds, it directly enters the restart process; if it is still alive after 3 seconds, it terminates the acquisition service process through the operating system process termination interface, and generates a new acquisition service restart request after confirming that the original process no longer exists.
[0125] When the data collection service process is alive and the registered running baseline identifier is consistent with the current running baseline identifier, a health request is initiated to the local loopback health check endpoint based on the local loopback communication port and the authentication token. If the health request response is successful and the returned capability statement is consistent with the expected capability statement, the level 2 health check is determined to be passed; otherwise, the level 2 health check is determined to be failed.
[0126] Specifically, the health check endpoint only listens on 127.0.0.1, and the health request timeout is set to 1 second. The keep-alive execution entity writes the authentication token to the local authentication field in the request header, and the collection service compares the authentication token in the request with the authentication token saved at startup. If the authentication matches, it returns a health status and capability declaration `collector-v2`. If the connection establishment fails, a complete response is not obtained within 1 second, authentication fails, the response format is incorrect, or the returned capability declaration is not equal to `collector-v2`, the level 2 health check is considered to have failed.
[0127] When the Level 2 health check is passed, the consecutive failure count is cleared to zero. When it fails, the consecutive failure count is increased and the consecutive failure threshold is read. When the consecutive failure count reaches the consecutive failure threshold, the data collection service process is terminated and a data collection service restart request is generated. If the threshold is not reached, the data collection service process is retained.
[0128] Specifically, the consecutive failure threshold is set to 5 times. The initial value of the consecutive failure count is 0. Each time a level 2 health check fails, the count is incremented by 1 and atomically written back to the service registration file. When any level 2 health check passes, the count is immediately written back to 0. For example, if the first four consecutive health checks fail, the consecutive failure count becomes 1, 2, 3, and 4 respectively, and the data collection service continues to operate. When the fifth consecutive check fails, the consecutive failure count becomes 5, reaching the consecutive failure threshold. The data collection service process is then reclaimed according to the aforementioned normal exit waiting 3 seconds method and, if necessary, forced termination, and a new data collection service restart request is generated.
[0129] Example 6, the specific steps for entering the headless entry point with headless command-line parameters and executing the keep-alive request before the single-instance lock request in the graphical interface are as follows:
[0130] After the application process starts, it parses command-line arguments, and enters the headless entry point when the command-line arguments match the headless command-line arguments.
[0131] Specifically, in the control flow of the application startup entry point, command-line parameter parsing is completed first, followed by the execution of a graphical interface single-instance lock request. Upon detecting `--guard-collector`, the startup type is set to headless keep-alive type, and the keep-alive execution function is entered directly.
[0132] Once the application is ready, a keep-alive request is executed through a headless entry point. After the keep-alive request is completed, the application process exits, and the graphical interface single-instance lock request and graphical interface creation are skipped.
[0133] Specifically, "application ready" indicates that the underlying environment upon which runtime, logging, local file access, process querying, and local IPC access depend has been initialized. Debouncing exit, update lock exit, development mode exit, completion of data collection service health confirmation, and completion of the data collection service startup process all represent the end state of a keep-alive request. Upon reaching the corresponding end state, the headless application process voluntarily exits.
[0134] Example 7, the specific steps for migrating keep-alive scheduled tasks based on the current application execution path and headless command-line parameters are as follows:
[0135] Query the keep-alive scheduled tasks in the task namespace and extract the execution body path, script call information, and command line parameters from the execution commands of the keep-alive scheduled tasks;
[0136] Specifically, in the Windows implementation environment, the Program and Arguments fields of the scheduled task action are read, and the Program field is normalized to an absolute path as the execution body path. If the Program field directly points to wscript, cscript, cmd, or PowerShell, and the Arguments field references a vbs, bat, cmd, or ps1 file, then external script call information is confirmed to exist.
[0137] If at least one of the following conditions is met: the execution path is inconsistent with the current application execution path, the script call information points to an external script, or the command line parameters do not include headless command line parameters, then the keep-alive scheduled task needs to be migrated.
[0138] Specifically, migration occurs when any one of the three conditions is met. Before comparing execution paths, the same path normalization rules as those used when generating the runtime baseline identifier are applied to avoid erroneous migrations caused solely by differences in directory separators or letter case.
[0139] Delete the keep-alive scheduled tasks that need to be migrated, and reconstruct the keep-alive scheduled tasks that call the headless entry point according to the current application execution path, headless command line parameters, and task namespace.
[0140] Specifically, the new task uses the current application execution path as the Program field, --guard-collector as the Arguments field, and includes collector-prod in the task name. The trigger period for periodic tasks is set to 60 seconds, while retaining login trigger conditions. Task queries, deletions, and creations are all limited to the namespace corresponding to collector-prod, avoiding handling scheduled tasks from development environments or other product instances.
[0141] Example 8, the specific steps for performing single-flight merging, retry, and start-up grace processing on the data acquisition service launch request based on the current operating baseline identifier are as follows:
[0142] Generate a pull-up key based on the current operating baseline identifier, query the shared pull-up status corresponding to the pull-up key, create a shared pull-up status and trigger the process to pull up if it does not exist, and merge the collection service pull-up requests with the same pull-up key and reuse the pull-up results;
[0143] Specifically, this implementation uses a 64-bit hexadecimal current running baseline identifier as the pull-up key, and generates a unique shared pull-up status file in the shared directory of the task namespace according to the pull-up key. When creating the status file, the exclusive creation semantics provided by the operating system are used. If the file already exists, the creation operation fails. Therefore, when multiple processes are executed concurrently, only one request can become the actual pull-up request.
[0144] The shared start-up status file records at least the process ID, creation time, and running status corresponding to the actual start-up request. Requests that do not qualify for actual start-up check the shared start-up status every 100 milliseconds, with a maximum wait time of 30 seconds. If the shared start-up status is found to be released during the waiting period, the secondary health check is immediately re-executed. If the health check passes, the already started data collection service process is reused.
[0145] If the actual start-up request process recorded in the shared start-up state no longer exists during the waiting process, the shared start-up state is determined to be an abnormal residual state. After obtaining exclusive file access rights, the state is deleted and the start-up qualification is recompeted for. If the actual start-up request process still exists but the waiting time reaches 30 seconds, the waiting request ends the current start-up process and records the solo wait timeout, without waiting indefinitely for the shared state.
[0146] When the process fails to start, the maximum number of retries and the baseline waiting time are read from the local monitoring configuration. The process is retried according to the maximum number of retries. The waiting time formula is: Tk=kT0, where Tk represents the waiting time before the kth retry, k represents a dimensionless integer starting from 1 and not greater than the maximum number of retries, and T0 represents the baseline waiting time.
[0147] Specifically, a linearly increasing waiting strategy is adopted, with the following formula: ,in, Indicates the first The waiting time before the next retry begins, in seconds. This represents the current retry number, a dimensionless positive integer ranging from 1 to the maximum number of retries. This represents the baseline waiting time, in seconds. In this implementation, the maximum number of retries is set to 3, and the baseline waiting time is set to 1 second. Therefore, the waiting times before the 1st, 2nd, and 3rd retries are 1 second, 2 seconds, and 3 seconds, respectively.
[0148] Before each retry, a level 2 health check is performed. If the level 2 health check passes, subsequent retrying is terminated and the data collection service process is reused.
[0149] Specifically, after each waiting period, the service registration file is reread, and a complete level-two health check is performed as described in Example 5. If other concurrent startup processes have already successfully registered the health collection service corresponding to the same current running baseline identifier, the remaining retries are immediately terminated, and no new process creation is performed.
[0150] After the new data collection service process is successfully started, the start time is recorded and the start grace period is read from the local monitoring configuration. During the start grace period from the start time, the consecutive failure count is not increased. When the level 2 health check is passed, the start grace period ends early. After the expiration, the consecutive failure count is restored and updated according to the level 2 health check results.
[0151] Specifically, in this implementation, the startup grace period is 5 seconds. The UTC system time at which the data collection service process is successfully created is used as the startup time. Within the following 5 seconds, the data collection service is allowed to complete configuration reading, local loopback port binding, health endpoint initialization, and service registration file writing. Health check failures during this 5-second period do not increment the consecutive failure count. If the data collection service completes registration and passes the secondary health check within the second second after startup, startup is immediately considered successful, without needing to wait the remaining 3 seconds. If the secondary health check fails after the 5-second period, the consecutive failure count resumes from the next valid health check after the grace period expires.
[0152] When the process restart process ends, record the restart result and release the shared restart state.
[0153] Specifically, when a process is started and passes the level 2 health check, the start-up result is recorded as successful; if the maximum number of retries (3) fails to establish a health collection service, it is recorded as a failure. After the result record is written, the shared start-up status file corresponding to the start-up key is deleted. Other pending keep-alive requests then reread the service registration file to determine the actual result, thus avoiding relying solely on the success flag in the status file to judge service health.
[0154] Example 9: The specific steps for allocating a local loopback communication port and writing the process identifier, local loopback communication port, authentication token, and current running baseline identifier into the service registration file when the data collection service starts are as follows:
[0155] After the data collection service starts, it binds port number 0 to the local loopback address, and the operating system allocates a local loopback communication port from the unused ports.
[0156] Specifically, the data collection service creates a TCP listening socket, limits the listening address to the local IPv4 loopback address 127.0.0.1, and sets the requested port to 0. After the operating system completes the bind operation, it reads the actual allocated port through the socket address lookup interface corresponding to getsockname. The actual port is a currently valid port within the range of 1 to 65535, and is used as the local loopback communication port. The health check does not directly search for the data collection service through a fixed port, but instead reads the actual allocated port from the service registration file.
[0157] Obtain the process identifier of the data collection service and generate an authentication token. Determine the current running benchmark identifier as the registered running benchmark identifier, and form service registration information including the process identifier, local loopback communication port, authentication token and registered running benchmark identifier.
[0158] Specifically, the process identifier is obtained through the operating system's current process identifier query interface. The authentication token is generated at once using a cryptographically secure random source from the operating system, consisting of 16 bytes (128 bits) of random data, which is then converted into a 32-bit hexadecimal string for storage. The authentication token is not generated using predictable data such as timestamps, process identifiers, or port numbers. The health check request carries this token. Upon receiving the request, the collection service performs a complete string comparison; only if a match is found will the health status and capability declaration be returned.
[0159] The current running baseline identifier is passed to the new collection service by the actual execution of the keep-alive process. The new collection service saves the received current running baseline identifier as a registered running baseline identifier without recalculating it based on the path within the collection service, so as to ensure that the keep-alive request that initiates the start-up uses a completely consistent running baseline with the service being started.
[0160] The service registration information is written to a temporary registration file, and the temporary registration file is then atomically replaced after the temporary registration file is written.
[0161] Specifically, the temporary registration file and the official service registration file reside in the same file system directory. The acquisition service first writes the process identifier, local loopback communication port, authentication token, registered runtime baseline identifier, consecutive failure count (value 0), and startup time completely into the temporary registration file. It then flushes the file buffer and closes the file handle. Next, it invokes the same-volume atomic replacement capability provided by the operating system to replace the official service registration file with the temporary registration file. In a Windows environment, this can be achieved through MoveFileEx or an equivalent file replacement interface that possesses the semantics of replacing existing files, ensuring that the reader sees either the complete file before or after the replacement, and does not read intermediate states where only some fields are written.
[0162] When the consecutive failure count changes, the same atomic update method is used: read the current complete service registration information, modify the consecutive failure count field, write the modified complete content to a temporary file in the same directory, refresh and close the file, and then atomically replace the official service registration file. Before updating, a short-term exclusive access right to the corresponding service registration file is obtained to avoid two concurrent keep-alive executors simultaneously performing overwrite writes based on the same old count.
[0163] In summary, in a complete execution instance, after a user login generates a keep-alive request, the headless entry point enters the keep-alive process before the graphical interface single-instance lock is requested. It reads the local monitoring configuration and generates the current running baseline identifier according to the defined serialization rules. After the first keep-alive request obtains exclusive access to the shared heartbeat file, it gains keep-alive execution qualification and continues to perform planned task checks if no valid update lock exists. If the service registration file does not exist, a collection service start request is generated. The first request obtains single-flight execution qualification via the start button and starts the collection service. The collection service binds a dynamic port to 127.0.0.1, generates a 128-bit authentication token, and writes the complete service registration information through atomic replacement.
[0164] For example, if a manual trigger occurs again 10 seconds after login, the corresponding keep-alive request will end because the current running baseline identifier matches the heartbeat baseline identifier, and 10 seconds is less than the 50-second anti-bounce window. The data collection service will not be restarted repeatedly. If a software update begins, the update program creates an update lock and refreshes the modification time every 60 seconds. If the periodic keep-alive detects that the lock duration is less than 900 seconds, it will proactively end and will not participate in the file replacement process. If the update program exits abnormally and does not refresh the update lock for 900 consecutive seconds, subsequent keep-alive processes will treat the lock as an abnormal residual state, clean up the invalid lock, and restore keep-alive.
[0165] When the data collection service process identifier still exists, but five consecutive health requests fail to receive a valid response within a 1-second timeout period, the consecutive failure count increases from 0 to 5. Once the consecutive failure threshold is reached, the data collection service is given a 3-second normal exit period. If it still fails to exit after 3 seconds, the process terminates, and a data collection service restart request is generated. When multiple trigger requests simultaneously generate restart requests, only one request with the same current running baseline identifier is allowed to actually restart. The remaining requests wait for the shared state at 100-millisecond intervals, with a maximum wait of 30 seconds. If an actual restart fails, the first, second, and third retries wait 1 second, 2 seconds, and 3 seconds respectively. After a new data collection service is successfully created, a 5-second startup grace period is introduced to prevent immediate termination due to temporary inability to respond to health checks during the initialization phase.
[0166] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention in any other way. Any person skilled in the art may make changes or modifications to the above-disclosed technical content to create equivalent embodiments that can be applied to other fields. However, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the protection scope of the present invention.
Claims
1. A method for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion, characterized in that, Responding to a keep-alive request triggered by multiple sources includes the following steps: Enter the headless entry point with headless command line parameters, and execute the keep-alive request before the single instance lock is requested in the graphical interface; Read the local monitoring configuration to determine whether to continue keeping the application alive. If to continue, obtain the task namespace, expected capability declaration, current application execution path, and generate the current running baseline identifier. Based on the shared heartbeat file and the current running baseline identifier debouncing, a keep-alive execution qualification is formed; Check and update the lock file to determine whether to continue or terminate keep-alive; Migrate keep-alive scheduled tasks based on the current application execution path and the headless command line parameters; Read the service registration file, perform a level 2 health check according to the current operating baseline identifier, and generate a data collection service start request; Based on the current operating baseline identifier, the collection service launch request is processed by single-flight merging, retry, and start-up grace period; When the data collection service starts, a local loopback communication port is allocated, and the process identifier, the local loopback communication port, the authentication token, and the current running baseline identifier are written into the service registration file.
2. The method for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion as described in claim 1, characterized in that, The specific steps for establishing keep-alive execution eligibility based on the shared heartbeat file and the current running baseline identifier debouncing are as follows: The keep-alive requests generated by login triggers, periodic scheduled task triggers, and manual triggers are associated with the same shared heartbeat file. The modification time and heartbeat baseline identifier of the shared heartbeat file are read, and the current time is obtained. When the heartbeat baseline identifier is consistent with the current running baseline identifier, the time interval between the current time and the modified time is calculated, and the anti-shake window is read from the local monitoring configuration. If the time interval is less than the anti-shake window, the keep-alive request is terminated. If the time interval is not less than the anti-shake window, the modified time is updated and the keep-alive execution qualification is formed. When the heartbeat baseline identifier is inconsistent with the current running baseline identifier, the current running baseline identifier is written as the heartbeat baseline identifier into the shared heartbeat file, the modification time is updated, and the keep-alive execution qualification is formed.
3. The method for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion as described in claim 1, characterized in that, The specific steps to check and update the lock file to determine whether to continue or terminate keep-alive are as follows: After the keep-alive execution qualification is established, the update lock file is checked. When the software update starts, the update lock file is created and the lock modification time is recorded. When the update is completed, the update lock file is deleted. If the update lock file exists, read the lock modification time and check time, read the update window from the local monitoring configuration, and calculate the lock duration between the check time and the lock modification time; The keep-alive operation is terminated when the lock duration is less than the update window; the keep-alive operation continues when the update lock file does not exist; and the keep-alive operation continues when the update lock file exists and the lock duration is not less than the update window.
4. The method for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion as described in claim 1, characterized in that, The steps for reading local monitoring configuration, determining whether to continue keep-alive, and obtaining the task namespace, expected capability declaration, current application execution path, and generating the current runtime baseline identifier are as follows: Read the development mode flag, task namespace identifier, and expected capability declaration from the local monitoring configuration; The development mode marker indicates that the current keep-alive operation ends when the development mode is activated. When the development mode marker indicates the production mode, the task namespace is determined based on the task namespace identifier, the current application execution path is obtained, and serialization is performed in the order of the task namespace, the current application execution path, and the expected capability declaration. A digest is calculated on the serialization result to obtain the current running baseline identifier.
5. The method for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion as described in claim 1, characterized in that, The specific steps for reading the service registration file, performing a level-two health check based on the current operating baseline identifier, and generating a data collection service start request are as follows: The service registration file is checked. If the service registration file does not exist, the collection service start request is generated and the secondary health check is terminated. If the service registration file exists, the process identifier, local loopback communication port, authentication token, registered running baseline identifier are read, and the consecutive failure count is obtained. The process identifier is used to determine whether the data collection service process is alive. If the data collection service process does not exist, a data collection service start-up request is generated. When the data collection service process is alive and the registered running baseline identifier is inconsistent with the current running baseline identifier, the data collection service process is terminated and the data collection service restart request is generated. When the data collection service process is alive and the registered running baseline identifier is consistent with the current running baseline identifier, a health request is initiated to the local loopback health check endpoint based on the local loopback communication port and the authentication token. If the health request response is successful and the returned capability statement is consistent with the expected capability statement, the secondary health check is determined to have passed; otherwise, the secondary health check is determined to have failed. When the Level 2 health check passes, the consecutive failure count is reset to zero; when it fails, the consecutive failure count is incremented and the consecutive failure threshold is read. When the consecutive failure count reaches the consecutive failure threshold, the data collection service process is terminated and a data collection service restart request is generated; otherwise, the data collection service process is retained.
6. The method for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion as described in claim 1, characterized in that, The specific steps for entering the headless entry point with headless command-line parameters and executing the keep-alive request before the single-instance lock request in the graphical interface are as follows: After the application process starts, the command line parameters are parsed, and the headless entry point is entered when the command line parameters match the headless command line parameters. Once the application is ready, the keep-alive request is executed through the headless entry point. After the keep-alive request is completed, the application process exits and skips the graphical interface single-instance lock application and graphical interface creation.
7. The method for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion as described in claim 1, characterized in that, The specific steps for migrating keep-alive scheduled tasks based on the current application execution path and the headless command-line parameters are as follows: Query the keep-alive scheduled tasks in the task namespace, and extract the execution body path, script call information, and command line parameters from the execution commands of the keep-alive scheduled tasks; When at least one of the following is true: the execution path is inconsistent with the current application execution path, the script call information points to an external script, or the command line parameters do not include the headless command line parameters, the keep-alive scheduled task needs to be migrated. Delete the keep-alive scheduled task that needs to be migrated, and reconstruct the keep-alive scheduled task that calls the headless entry point according to the current application execution path, the headless command line parameters, and the task namespace.
8. The method for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion as described in claim 5, characterized in that, The specific steps for performing single-flight merging, retry, and start-up grace processing on the collection service launch request based on the current operating baseline identifier are as follows: A start-up key is generated based on the current running baseline identifier. The shared start-up status corresponding to the start-up key is queried. If it does not exist, the shared start-up status is created and the process is started. If it exists, the collection service start-up requests with the same start-up key are merged and the start-up results are reused. When the process fails to start, the maximum number of retries and the baseline waiting time are read from the local monitoring configuration, and the process is retried according to the maximum number of retries. The waiting time formula is: ,in Indicates the first Waiting time before the next retry This represents a dimensionless integer starting from 1 and not greater than the maximum number of retries. This represents the baseline waiting time; Before each retry, the secondary health check is performed. If the secondary health check passes, subsequent retries are terminated and the data collection service process is reused. After the new data collection service process is successfully started, the start time is recorded and the start grace period is read from the local monitoring configuration. The consecutive failure count is not increased during the start grace period starting from the start time. The start grace period ends early when the secondary health check is passed. After the expiration, the consecutive failure count is restored and updated according to the results of the secondary health check. When the process restart process ends, the restart result is recorded and the shared restart state is released.
9. The method for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion as described in claim 5, characterized in that, The specific steps for allocating a local loopback communication port and writing the process identifier, the local loopback communication port, the authentication token, and the current running baseline identifier into the service registration file when the data collection service starts are as follows: After the data collection service is started, it binds port number 0 to the local loopback address, and the operating system allocates the local loopback communication port from the unused ports. Obtain the process identifier of the collection service and generate the authentication token, determine the current running baseline identifier as the registered running baseline identifier, and form service registration information including the process identifier, the local loopback communication port, the authentication token and the registered running baseline identifier; The service registration information is written to a temporary registration file, and the temporary registration file is then atomically replaced after the temporary registration file is written.
10. The system for keeping a resident data acquisition process alive based on anti-jitter and update mutual exclusion as described in any one of claims 1-9, characterized in that, include: Headless Entry Module: Enters the headless entry point with headless command line parameters and executes the keep-alive request before the single-instance lock is requested in the graphical interface; Configuration determination module: Reads local monitoring configuration, determines whether to continue keeping the application alive, and if so, obtains the task namespace, expected capability declaration, current application execution path and generates the current running baseline identifier; Anti-shake qualification module: Based on the shared heartbeat file and the current running baseline identifier, anti-shake is used to form keep-alive execution qualification; Update mutex module: Check the update lock file to determine whether to continue or terminate keep-alive; Task migration module: Migrate keep-alive scheduled tasks based on the current application execution path and the headless command line parameters; Health check module: Reads the service registration file, performs a secondary health check according to the current operating baseline identifier, and generates a data collection service start request; The start-up control module performs single-flight merging, retry, and start-up grace period processing on the acquisition service start-up request based on the current operating baseline identifier. Service registration module: When the collection service starts, it allocates a local loopback communication port and writes the process identifier, the local loopback communication port, the authentication token, and the current running baseline identifier into the service registration file.
