Accurate timing and charging method and device for accelerator

By using Redis sorted sets and blocking detection for billing, the concurrency blocking and billing error problems in traditional billing strategies are solved, achieving high concurrency, low latency and high accuracy billing processing, meeting the billing needs of the gaming industry.

CN122053266APending Publication Date: 2026-05-15CHENGDU JUNYUN TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202610518297.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-04-20
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Traditional network billing strategies are prone to blocking, duplicate recording, high resource consumption, and insufficient timing accuracy in high-concurrency scenarios, resulting in billing delays and large errors, which cannot meet the accurate billing needs of the gaming industry.

Method used

We employ an asynchronous heartbeat processing method based on Redis sorted sets, a blocking heartbeat expiration detection method, and a minute-level precision timekeeping and billing method. The Redis sorted set is updated through client heartbeats, heartbeat messages are processed asynchronously by an independent consumer thread, and a daemon process detects heartbeat expiration every second. The billing timer is terminated when the client goes offline or stops, thus enabling minute-level precision billing.

Benefits of technology

It achieves low-latency billing processing under high concurrency, reduces resource consumption, improves billing accuracy, reduces user disputes, and ensures billing accuracy within minutes, meeting the precise billing needs of the gaming industry.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122053266A_ABST
    Figure CN122053266A_ABST
Patent Text Reader

Abstract

The invention provides a precise timing and charging method and device for an accelerator, and the method comprises the steps: generating a message queue from a heartbeat to a server through a client based on a preset second-level fixed interval, asynchronously processing the heartbeat through an independent consumption thread of the server, and updating an ordered set of Redis, wherein the Score fields in the ordered set are assigned as timestamps, and repeated client records are eliminated through the automatic duplicate removal characteristic of the ordered set; a daemon process is started based on the server side, heartbeat expiration detection is executed per second, and the heartbeat expiration detection adopts a mode of obtaining the oldest heartbeat in a blocking mode; and when the condition that the client is offline or the user actively stops is detected, the server immediately terminates the charging timer, and performs minute-level precision timing and charging in combination with the timestamps stored in the ordered set. In the timing and charging process, the acceleration duration and the member consumption duration have the same minute-level error.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of network accelerator billing technology, and in particular to a precise time-based billing method for accelerators. This application also relates to a precise time-based billing device for accelerators, a computing device, and a computer-readable storage medium. Background Technology

[0002] As a core tool for optimizing network links and reducing access latency, network accelerators directly impact user experience and operator revenue through accurate billing. Traditional network billing strategies primarily employ the 3A protocol billing system for authorization and billing. This method has several drawbacks: First, heartbeat message processing uses a synchronous mode, which is prone to blocking in high-concurrency scenarios, leading to delayed updates of timing data. Second, client heartbeats are prone to duplicate records, interfering with billing accuracy. Third, heartbeat expiration detection often uses polling, which not only consumes significant CPU resources but also suffers from untimely detection. Fourth, offline judgment scenarios are limited, making it susceptible to misbilling or missed billing due to network fluctuations or device malfunctions. Fifth, insufficient timing accuracy fails to precisely match actual user usage time, leading to user disputes. Therefore, traditional heartbeat maintenance strategies, relying on TCP liveness, timed polling, or passive timeout, suffer from high resource consumption, large billing errors, and poor scalability. Their real-time and scalability are relatively poor, failing to meet the diverse and accurate billing strategies required by the gaming industry. Summary of the Invention

[0003] In view of this, embodiments of this application provide a precise timing and billing method for accelerators to address the technical deficiencies in the prior art. Embodiments of this application also provide a precise timing and billing device for accelerators, a computing device, and a computer-readable storage medium.

[0004] According to a first aspect of the embodiments of this application, a precise timing and billing method for accelerators is provided, comprising: Based on a preset fixed interval of seconds, a heartbeat is sent from the client to the message queue on the server. The heartbeat is then processed asynchronously by an independent consumer thread on the server, updating the sorted set in Redis. The Score field in the sorted set is assigned a timestamp, and duplicate client records are eliminated through the automatic deduplication feature of the sorted set. The server starts a daemon process that performs a heartbeat expiration check every second. The heartbeat expiration check uses a blocking method to obtain the oldest heartbeat. When the client is detected to be offline or the user actively stops the service, the server immediately terminates the billing timer and performs minute-level precision billing by combining the timestamps stored in the ordered set.

[0005] Optionally, updating the sorted set of Redis includes: The server uses the ZADD command to write the client's unique identifier as Member and the timestamp as Score into the ordered set based on the client's unique identifier in the heartbeat. If the client already exists in the ordered set, its original Score is automatically overwritten with the latest timestamp.

[0006] Optionally, the heartbeat expiration detection employs a blocking method to obtain the oldest heartbeat, including: The daemon process obtains the oldest heartbeat with the smallest score in the ordered set using the ZRANGE command. If the ordered set is empty, the daemon process enters a blocked waiting state until new heartbeat data is written into the ordered set and it is then awakened.

[0007] Optionally, the heartbeat delay detection includes: Calculate the difference between the current system time's millisecond-level timestamp and the preset timeout threshold, and use it as the expiration determination threshold; The score of the oldest heartbeat is compared with the expiration threshold. If the score is less than or equal to the expiration threshold, the corresponding client heartbeat is determined to have expired.

[0008] Optionally, after determining the corresponding client's heartbeat period, the method further includes: The daemon process removes the client from the ordered set using the ZREM command and generates a client offline event, which is then pushed to the billing core module.

[0009] Optionally, the detection of client offline includes at least one of the following: the daemon process determines that the client's heartbeat has expired, the server receives an offline command actively sent by the client, or the network connection between the server and the client is abnormally disconnected.

[0010] Optionally, the step of combining the timestamps stored in the ordered set to perform minute-level precision timekeeping and billing includes: Extract the first online timestamp and the last heartbeat timestamp of the client from the ordered set. The first online timestamp is extracted from the ordered set and stored in the billing log database by the server when it first receives the heartbeat of the client. The last heartbeat timestamp is the latest Score value of the client in the ordered set. The time difference between the first online timestamp and the last heartbeat timestamp is calculated and converted into duration, and the duration is billed and accounted for with minute-level precision.

[0011] According to a second aspect of the embodiments of this application, a precise timing and billing device for accelerators is provided, comprising: The first module is configured to send heartbeats from the client to the message queue on the server at a preset fixed interval of seconds, and to process the heartbeats asynchronously through an independent consumer thread on the server, updating the sorted set in Redis. The Score field in the sorted set is assigned a timestamp, and duplicate client records are eliminated through the automatic deduplication feature of the sorted set. The second module is configured to start a daemon process based on the server and perform a heartbeat expiration detection every second. The heartbeat expiration detection adopts a blocking method to obtain the oldest heartbeat. The third module is configured to immediately terminate the billing timer when the client is detected to be offline or the user actively stops the transaction, and perform timekeeping and billing with minute-level precision by combining the timestamps stored in the ordered set.

[0012] According to a third aspect of the embodiments of this application, a computing device is provided, comprising: Memory and processor; The memory is used to store computer-executable instructions, and the processor executes the computer-executable instructions to implement the steps of the precise timing and billing method for the accelerator.

[0013] According to a fourth aspect of the present application, a computer-readable storage medium is provided that stores computer-executable instructions, which, when executed by a processor, implement the steps of the precise timing and billing method for accelerators.

[0014] According to a fifth aspect of the present application, a chip is provided that stores a computer program, which, when executed by the chip, implements the steps of the precise timing and billing method for the accelerometer.

[0015] The precise timing and billing method for accelerators provided in this application is based on a preset fixed interval at the second level. Heartbeats are sent from the client to the server's message queue, and the server's independent consumption thread asynchronously processes these heartbeats, updating a sorted set in Redis. The Score field in this sorted set is assigned a timestamp, and the automatic deduplication feature of the sorted set eliminates duplicate client records. A daemon process is started on the server, performing heartbeat expiration checks every second. These heartbeat expiration checks use a blocking method to retrieve the oldest heartbeat. When the client is detected to be offline or the user actively stops the process, the server immediately terminates the billing timer and, combined with the timestamp stored in the sorted set, performs timing and billing with minute-level precision. This ensures strong consistency between acceleration duration and membership consumption duration with minute-level error during the timing and billing process. Attached Figure Description

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

[0017] Figure 1 This is a flowchart of a precise timing and billing method for accelerators provided in an embodiment of this application; Figure 2 This is a schematic diagram of the structure of a precise timing and billing device for an accelerator provided in one embodiment of this application; Figure 3 This is a structural block diagram of a computing device provided in one embodiment of this application. Detailed Implementation

[0018] Many specific details are set forth in the following description to provide a full understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this application; therefore, this application is not limited to the specific embodiments disclosed below.

[0019] The terminology used in one or more embodiments of this application is for the purpose of describing particular embodiments only and is not intended to limit the scope of one or more embodiments of this application. The singular forms “a,” “the,” and “the” used in one or more embodiments of this application and in the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” used in one or more embodiments of this application refers to and includes any or all possible combinations of one or more associated listed items.

[0020] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this application, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this application, and similarly, second may also be referred to as first.

[0021] This application provides a precise timing and billing method for accelerators. This application also relates to a precise timing and billing device for accelerators, a computing device, and a computer-readable storage medium, which will be described in detail in the following embodiments.

[0022] Figure 1 A flowchart illustrating a precise timing and billing method for accelerators according to an embodiment of this application is shown, specifically including the following steps: Step S102: Based on a preset fixed interval of seconds, a heartbeat is sent from the client to the message queue of the server, and the heartbeat is processed asynchronously by the independent consumer thread of the server to update the sorted set of Redis. The Score field in the sorted set is assigned a timestamp. The automatic deduplication feature of the sorted set is used to eliminate duplicate client records. Step S104: Start a daemon process based on the server and perform heartbeat expiration detection every second. The heartbeat expiration detection adopts a blocking method to obtain the oldest heartbeat. Step S106: When the client is detected to be offline or the user actively stops the service, the server immediately terminates the billing timer and performs minute-level precision billing by combining the timestamps stored in the ordered set.

[0023] The selection of the fixed second interval is dynamically configured according to the accelerator package. Different precisions are used for users with different evaluation levels. For example, VIP users use a 1-second interval precision, while ordinary users use a 3-5 second interval precision. Preferably, the range is 0.5-5 seconds. The specific value is determined by the actual use scenario and is not limited in this embodiment. The server-side message queue uses RabbitMQ or Kafka, which supports high-concurrency message caching and retry mechanisms. When the client sends a heartbeat to the server-side message queue, the heartbeat message contains core fields such as the client's unique identifier, the current timestamp, and the network link status. The asynchronous processing of independent consumer threads can be understood as the server deploying multiple independent consumer threads. The thread pool uses a fair lock mechanism to avoid starvation and asynchronously pulls heartbeat messages from the message queue without requiring the client to wait for a response, reducing end-to-end latency. At the same time, the thread isolation mechanism prevents a single heartbeat processing failure from affecting the overall service. The number of multiple independent consumer threads on the server is dynamically expanded according to the concurrency.

[0024] Furthermore, during the update and deduplication process of Redis sorted sets, a Redis cluster deployment is used, employing master-slave replication combined with sentinel mode to ensure high availability. The Member field of the sorted set ZSet serves as a unique identifier for the client, generated by a combination of MAC address, device ID, and user account, and is globally unique. The Score field is assigned a millisecond-level timestamp, which is based on the NTP service's synchronized clock to avoid time zone discrepancies. Leveraging the inherent uniqueness of ZSet's Member field, duplicate client records are automatically overwritten without additional deduplication logic. It also supports sorting by timestamp, providing a foundation for subsequent expiration detection.

[0025] In addition, the second-level associated blocking expiration detection of the daemon process can be understood as the server starting an independent daemon process, which is separated from the main thread to avoid business interference. It triggers a heartbeat expiration detection once per second, and adopts a blocking mode to obtain the oldest heartbeat instead of a polling mechanism to reduce the occupation of invalid resources. The daemon process has the ability to recover from failures and will automatically restart within 1 second after abnormal exit.

[0026] In offline and actively stopped scenarios, billing and settlement can be understood as the server monitoring the client's status in real time. When the billing termination condition is triggered, the billing timer is stopped immediately. Based on the timestamp data stored in ZSet, the actual usage time of the user is calculated, and billing is completed with minute-level precision. It supports various billing rule configurations such as billing for less than one minute as one minute and rounding.

[0027] By employing the aforementioned technical means, combining asynchronous processing with message queues, the system supports tens of thousands of concurrent heartbeats with end-to-end latency controlled within 100ms. This avoids timing delays caused by synchronous blocking, decouples message queue reporting and processing, prevents request blocking, supports horizontal scaling, and enables low-complexity detection of timeout clients through blocking retrieval of the oldest heartbeat, significantly reducing resource consumption. Redis ZSet's automatic deduplication and timestamp sorting naturally achieve heartbeat timeliness-based exclusion, preventing invalid data accumulation, simplifying data processing logic, ensuring the uniqueness and orderliness of client status data, and reducing storage and computational overhead. Blocking detection replaces polling, reducing CPU resource utilization, and second-level detection accuracy ensures timely detection of offline states. Multi-scenario status monitoring and accurate timestamp calculation achieve minute-level billing accuracy with an error of ≤1 second, significantly improving billing accuracy and reducing user disputes.

[0028] Furthermore, in step S102 above, the process of updating the sorted set in Redis is implemented as follows in this embodiment: The server uses the ZADD command to write the client's unique identifier as Member and the timestamp as Score into the ordered set based on the client's unique identifier in the heartbeat. If the client already exists in the ordered set, its original Score is automatically overwritten with the latest timestamp.

[0029] Specifically, the ZADD command is used for atomic updates. After the server obtains the client's unique identifier from the heartbeat message, it calls the Redis ZADD command to set Member as the client's unique identifier and Score as the current millisecond-level timestamp. The command parameters do not include NX or XX options. NX indicates that it is added only if it does not exist, and XX indicates that it is updated only if it exists. The default implementation is an atomic operation that overwrites if it exists and adds if it does not exist, avoiding timestamp inconsistencies caused by concurrent updates.

[0030] Furthermore, to mitigate concurrency issues and address the problem of multiple threads simultaneously updating the same client heartbeat in high-concurrency scenarios, a Redis Lua script is introduced to encapsulate the ZADD command, ensuring the atomicity of update operations. The script includes timestamp validity checks, preventing older messages from overwriting newer ones by only updating the old timestamp. Additionally, a unique client identifier is generated using SHA256, derived from MAC address, device ID, user account, and a random salt value, with a length of 32 bits to prevent forgery and duplication. This identifier is also linked to user account and device information, supporting independent timekeeping and billing for multiple devices logged in by the same user, thus strengthening the client's unique identifier.

[0031] Therefore, atomic updates via the ZADD command eliminate the need for step-by-step judgment logic, improving update efficiency; Lua scripts ensure the atomicity of update operations in concurrent scenarios, increasing the accuracy of timestamp coverage and avoiding interference from old data; the enhanced client-specific identifier eliminates identifier duplication and forgery, providing an identity foundation for subsequent accurate billing and ensuring the continuity of timing data for the same client.

[0032] Furthermore, in step S104 above, the heartbeat expiration detection adopts a blocking method to obtain the oldest heartbeat. In this embodiment, the specific implementation method is as follows: The daemon process obtains the oldest heartbeat with the smallest score in the ordered set using the ZRANGE command. If the ordered set is empty, the daemon process enters a blocked waiting state until new heartbeat data is written into the ordered set and it is then awakened.

[0033] The ZRANGE command precisely retrieves the oldest heartbeat. The daemon process calls the Redis ZRANGE command, and through parameter settings, only retrieves the heartbeat record with the smallest Score (i.e., the earliest timestamp) in the ordered set, avoiding resource waste caused by batch retrieval and improving detection efficiency. If the ZRANGE command returns an empty set, indicating no heartbeat record, the daemon process blocks and waits using the Redis BLPOP command. The blocking timeout is set based on the user's actual usage needs, with a preferred value between 0.5 and 1 second to prevent infinite blocking. When a new heartbeat is written to the ordered set by the client, a custom message notification mechanism wakes up the daemon process, immediately executes the next round of detection, and prioritizes processing the newly written heartbeat record after waking up, ensuring timely detection and achieving intelligent blocking and waking up.

[0034] Furthermore, the daemon process's detection thread uses a long-lived connection mode to avoid latency caused by frequent connection establishment or disconnection. It also sets a higher thread priority than ordinary business threads to ensure that the detection task is not preempted, thus optimizing the detection thread. Blocking waiting replaces polling, reducing CPU resource usage during idle periods and significantly lowering server load. ZRANGE accurately retrieves the oldest single heartbeat, improving detection efficiency. The combination of blocking timeout and wake-up mechanisms ensures low-cost waiting when there is no heartbeat and immediate detection when a heartbeat is available, keeping detection latency within 1 second, balancing resource conservation and timely detection.

[0035] Furthermore, in step S104 above, the process of detecting a delayed heartbeat is specifically implemented as follows in this embodiment: Calculate the difference between the current system time's millisecond-level timestamp and a preset timeout threshold, and use this difference as the expiration determination threshold. Compare the score of the oldest heartbeat obtained with the expiration determination threshold. If the score is less than or equal to the expiration determination threshold, then the corresponding client's heartbeat is determined to have expired.

[0036] Specifically, through NTP service synchronization, the server obtains the current system's millisecond-level timestamp. At this time, the clock deviation is ≤50ms. The expiration judgment threshold is obtained by subtracting the preset timeout threshold from the obtained millisecond-level timestamp. The preset timeout threshold is dynamically adjusted through the configuration center, with a value range of 5-60 seconds, preferably 30 seconds, to realize the dynamic calculation of the expiration judgment threshold.

[0037] Furthermore, the timeout threshold is adjusted based on the client's network link quality. The server uses link packet loss rate and latency data from heartbeat messages to automatically increase the threshold for clients with low network quality (packet loss rate exceeding a preset threshold), avoiding misjudgments caused by network fluctuations. Conversely, the original threshold is maintained for clients with good network quality, ensuring timely offline detection and achieving dynamic threshold adaptation. In addition, the oldest heartbeat score obtained by ZRANGE is compared with the expiration judgment threshold. If the score is less than or equal to the expiration judgment threshold, the corresponding client's heartbeat is considered expired. A timestamp validity check is added during the comparison process to exclude abnormal timestamps such as future timestamps or null values, avoiding misjudgments.

[0038] The dynamic threshold adaptation strategy reduces the offline false positive rate, balancing network fluctuation scenarios with the need for accurate detection; NTP clock synchronization ensures that timestamp deviation is controlled within a preset range, with an expiration judgment error of ≤1 second; and the abnormal timestamp verification mechanism further improves the accuracy of judgment and avoids billing anomalies caused by illegal data.

[0039] Furthermore, after determining the corresponding client's heartbeat expiration time in the above steps, the following steps are also included: The daemon process removes the client from the ordered set using the ZREM command and generates a client offline event, which is then pushed to the billing core module.

[0040] The process involves the daemon process determining when a client's heartbeat has expired. It then invokes the Redis ZREM command to delete the corresponding record from the sorted set based on the client's unique identifier. This deletion operation is encapsulated in Lua scripts to ensure the atomicity of the expiration determination and record deletion, preventing data inconsistencies caused by the client sending a new heartbeat before deletion. After deletion, the daemon process pushes an offline event to the billing core module's dedicated message queue. The event includes the client's unique identifier, the last heartbeat timestamp, and the reason for expiration. An asynchronous push mode is used to avoid blocking the daemon process's detection flow. An ACK mechanism is added to ensure successful reception by the billing core module. If no ACK is received, the process retryes a preset number of times. Failed retryes are logged and an alarm is triggered. After the offline event is pushed, an operation log containing the timestamp, client information, deletion result, and push status is automatically recorded. This log is stored in the ClickHouse time-series database and retained for 90 days. It supports querying by client and time range, facilitating troubleshooting and billing dispute tracing.

[0041] In the above steps, atomic deletion ensures the cleanliness of ordered set data, avoids expired records from occupying storage resources, asynchronous push combined with ACK mechanism increases the success rate of offline event push, eliminates billing omissions, time-series log storage enables full-process traceability, improves fault diagnosis efficiency, and provides data support for billing disputes.

[0042] Furthermore, in step S106 above, the detection of client offline includes at least one of the following: the daemon process determines that the client's heartbeat has expired, the server receives an offline command actively sent by the client, and the network connection between the server and the client is abnormally disconnected.

[0043] The heartbeat expiration determination is handled by a daemon process, covering scenarios such as abnormal client power outages and silent disconnections. The detection of active offline commands is achieved when the client actively stops the accelerator, sending a digitally signed offline command containing the client's unique identifier and a stop timestamp. Specifically, the signature uses the RSA algorithm to prevent forgery. The server verifies the signature's validity; if successful, offline status is determined, and billing termination is immediately triggered. If the server and client fail to receive a predetermined number of consecutive probe messages within a preset time, an abnormal network connection is determined, combined with network layer link detection, such as ICMP message probing, to rule out false positives caused by server gateway failures. Furthermore, when multiple offline scenarios trigger simultaneously, they are handled in the following priority order: active offline command > abnormal network connection > heartbeat expiration, ensuring that the billing logic is consistent with the user's actual operation and avoiding duplicate billing.

[0044] Therefore, multi-scenario coverage ensures seamless offline judgment, covering the vast majority of client offline scenarios; digital signatures prevent the forgery of active offline instructions, avoiding users maliciously evading billing; and a priority judgment mechanism ensures the rationality of billing logic, further reducing user dispute rates. Furthermore, in step S106, the process of performing minute-level precision timing and billing by combining the timestamps stored in the ordered set is specifically implemented as follows in this embodiment: Extract the first online timestamp and the last heartbeat timestamp of the client from the ordered set. The first online timestamp is extracted from the ordered set and stored in the billing log database by the server when it first receives the client's heartbeat. The last heartbeat timestamp is the latest score value of the client in the ordered set. Calculate the time difference between the first online timestamp and the last heartbeat timestamp and convert it into duration. Calculate the billing and accounting for the duration with minute-level precision.

[0045] The initial online timestamp is generated by the server extracting the corresponding Score from the Redis sorted set when it first receives a heartbeat from the client, and storing it in the billing log database. The billing log database is stored in MySQL with partitioned tables, hashed by user ID to improve query efficiency. At the same time, it is associated with the session ID to ensure correspondence with subsequent heartbeat data. The final heartbeat timestamp is the latest Score value of the client in the sorted set. If the client actively stops, the stop timestamp in the offline command is taken, which has higher priority than the final heartbeat timestamp, to achieve accurate extraction of the first and last timestamps.

[0046] The difference between the initial online timestamp and the last heartbeat timestamp is then calculated and converted to a duration in seconds. If heartbeats are lost due to network fluctuations, they are supplemented using adjacent heartbeat timestamps, specifically calculated by interpolation at average intervals with an error ≤1 second. Duration is calculated with minute-level precision, supporting two rule configurations: one is billing for fractions of a minute as a full minute, and the other is billing for fractions of a minute based on actual duration, accurate to the second, suitable for users with corresponding plans. Based on the calculated duration, multiple modes are supported, including tiered billing by duration and plan deductions. After billing is completed, a billing statement is generated and pushed to the user and the financial system, while simultaneously updating the user's account balance.

[0047] Therefore, the first and last timestamp extraction and calibration mechanism ensures that the duration calculation error is ≤1 second, and the minute-level billing accuracy meets the standard; heartbeat loss interpolation completion further improves the accuracy of timing and avoids billing errors caused by missing data; multi-mode billing adaptation meets the needs of different packages and operations, improves billing transparency, and reduces the user reconciliation dispute rate; split table storage and efficient query ensure billing and accounting efficiency and support tens of thousands of users to settle at the same time.

[0048] For example, the client generates a globally unique SHA256 identifier based on MAC address, device ID, user account, and random salt value, with a heartbeat interval of 3 seconds. The server deploys a Redis cluster in a 3-master, 3-slave sentinel mode, creating an ordered set `accelerator_heartbeat`; deploys a RabbitMQ message queue, creating a heartbeat receiving queue `heartbeat_queue` and an offline event queue `offline_event_queue`; starts an NTP service to ensure clock synchronization; and deploys a daemon process and an independent consumer thread pool, with 20 core threads and a maximum of 50 threads. The heartbeat timeout threshold is configured to 30 seconds, and billing is based on a full minute for any fraction of a minute.

[0049] The process then proceeds to heartbeat sending and receiving, Redis sorted set updates, heartbeat expiration detection, expiration follow-up processing, active stop scenario handling, and billing calculation. Specifically, the heartbeat sending and receiving process is as follows: after the client starts the accelerator, it sends a heartbeat message to the server's RabbitMQ message queue `heartbeat_queue` every 3 seconds. The message contains the client's unique identifier, the current millisecond-level timestamp, and the packet loss rate. The server's independent consumer thread asynchronously pulls messages from the queue to avoid blocking. The Redis sorted set update process is as follows: the consumer thread calls the `ZADD` command, encapsulated in Lua scripts, to write the client's unique identifier as the Member and the current timestamp as the Score into the `accelerator_heartbeat` sorted set. If the client already exists, the old Score is automatically overwritten with the latest timestamp to ensure data uniqueness and timeliness. The heartbeat expiration detection process is as follows: the daemon process calls the `ZRANGE` command every second to obtain the oldest heartbeat. If the set is empty, it blocks and waits for 1 second using the `BLPOP` command. If the oldest heartbeat is obtained, the current timestamp and 30 are calculated. The difference between the second threshold and the threshold is used as the expiration threshold. The oldest heartbeat score is compared; if the score is less than or equal to the threshold, the record is considered expired. The subsequent processing involves the daemon process using a Lua script to call the ZREM command to delete expired client records, pushing an offline event to the offline_event_queue, including the client identifier, last heartbeat timestamp, and expiration reason, while simultaneously recording a time-series log. The billing core module consumes the offline event, triggering billing and settlement. For proactive shutdown scenarios, the user actively shuts down the accelerator, the client sends an offline command with an RSA signature, the server verifies the signature, determines offline, takes the stop timestamp from the command as the last timestamp, immediately terminates the billing timer, deletes the corresponding record in Redis, and pushes the offline event to the billing module. The billing calculation process involves the billing module extracting the client's first online timestamp from the billing log database, calculating the duration using the last timestamp, and if heartbeats are lost, interpolating the average interval between adjacent heartbeats to complete the calculation. The cost is calculated with minute-level precision, prioritizing deductions from the user's package duration, generating a bill, updating the account balance, and pushing it to the user and financial systems.

[0050] It constructs a complete process of second-level heartbeat asynchronous processing, Redis ordered set optimization, blocking expiration detection, multi-scenario offline judgment, and accurate duration calculation. It solves the problems of poor concurrency adaptation, data redundancy, detection lag, and insufficient accuracy in existing accelerator timekeeping and billing. It achieves high concurrency, high accuracy, and high reliability timekeeping and billing, taking into account both user experience and the accuracy of revenue for operators. It can be widely used in various network accelerators, cloud services, and other scenarios that require accurate timekeeping and billing.

[0051] Corresponding to the above method embodiments, this application also provides an embodiment of a precise timing and billing device for accelerators. Figure 2 A schematic diagram of a precise timing and billing device for accelerators according to an embodiment of this application is shown. Figure 2 As shown, the device includes: The first module 202 is configured to send heartbeats from the client to the message queue of the server based on a preset fixed interval of seconds, and to asynchronously process the heartbeats through an independent consumer thread on the server, updating the sorted set of Redis. The Score field in the sorted set is assigned a timestamp, and duplicate client records are eliminated through the automatic deduplication feature of the sorted set. The second module 204 is configured to start a daemon process based on the server and perform a heartbeat expiration detection every second, wherein the heartbeat expiration detection adopts a blocking method to obtain the oldest heartbeat; The third module 206 is configured to, when the client is detected to be offline or the user actively stops the transaction, immediately terminate the billing timer and perform minute-level precision timekeeping and billing by combining the timestamps stored in the ordered set.

[0052] In an optional embodiment, the first module 202 is further configured to: The server uses the ZADD command to write the client's unique identifier as Member and the timestamp as Score into the ordered set based on the client's unique identifier in the heartbeat. If the client already exists in the ordered set, its original Score is automatically overwritten with the latest timestamp.

[0053] In an optional embodiment, the second module 204 is further configured to: The daemon process obtains the oldest heartbeat with the smallest score in the ordered set using the ZRANGE command. If the ordered set is empty, the daemon process enters a blocked waiting state until new heartbeat data is written into the ordered set and it is then awakened.

[0054] In an optional embodiment, the second module 204 is further configured to: Calculate the difference between the current system time's millisecond-level timestamp and a preset timeout threshold, and use this difference as the expiration determination threshold. Compare the score of the oldest heartbeat obtained with the expiration determination threshold. If the score is less than or equal to the expiration determination threshold, then the corresponding client's heartbeat is determined to have expired.

[0055] In an optional embodiment, the precise timing and billing device for the accelerator further includes: The fourth module is configured so that the daemon process removes the client from the ordered set via the ZREM command and generates a client offline event to be pushed to the billing core module.

[0056] In an optional embodiment, the third module 206 is further configured to: The situations in which the client is detected to be offline include at least one of the following: the daemon process determines that the client's heartbeat has expired, the server receives an offline command actively sent by the client, or the network connection between the server and the client is abnormally disconnected.

[0057] In an optional embodiment, the third module 206 is further configured to: Extract the first online timestamp and the last heartbeat timestamp of the client from the ordered set. The first online timestamp is extracted from the ordered set and stored in the billing log database by the server when it first receives the client's heartbeat. The last heartbeat timestamp is the latest score value of the client in the ordered set. Calculate the time difference between the first online timestamp and the last heartbeat timestamp and convert it into duration. Calculate the billing and accounting for the duration with minute-level precision.

[0058] The precise timing and billing device for accelerators provided in this application, based on a preset fixed interval at the second level, receives heartbeats from the client and sends them to the server's message queue. The server's independent consumption thread asynchronously processes these heartbeats, updating a sorted set in Redis. The Score field in this sorted set is assigned a timestamp, and the automatic deduplication feature of the sorted set eliminates duplicate client records. A daemon process is started on the server, performing heartbeat expiration checks every second. These heartbeat expiration checks use a blocking method to retrieve the oldest heartbeat. When the client is detected to be offline or the user actively stops the process, the server immediately terminates the billing timer and, combined with the timestamp stored in the sorted set, performs timing and billing with minute-level precision. This ensures strong consistency between acceleration duration and consumed membership time with a minute-level error during the timing and billing process.

[0059] The above is an illustrative scheme of a precise timing and billing device for accelerators according to this embodiment. It should be noted that the technical solution of this precise timing and billing device for accelerators belongs to the same concept as the technical solution of the precise timing and billing method for accelerators described above. Details not described in detail in the technical solution of the precise timing and billing device for accelerators can be found in the description of the technical solution of the precise timing and billing method for accelerators described above. Furthermore, the components in the device embodiment should be understood as functional modules necessary to implement each step of the program flow or each step of the method; these functional modules are not actual functional divisions or separations. The device claim defined by such a set of functional modules should be understood as a functional module architecture that primarily implements the solution through the computer program described in the specification, and not as a physical device that primarily implements the solution through hardware.

[0060] Figure 3 A structural block diagram of a computing device 300 according to an embodiment of this application is shown. The components of the computing device 300 include, but are not limited to, a memory 310 and a processor 320. The processor 320 is connected to the memory 310 via a bus 330, and a database 350 is used to store data.

[0061] The computing device 300 also includes an access device 340, which enables the computing device 300 to communicate via one or more networks 360. Examples of these networks include a Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the Internet. The access device 340 may include one or more of any type of wired or wireless network interface (e.g., a Network Interface Card (NIC)), such as an IEEE 802.11 Wireless Local Area Network (WLAN) interface, a Wi-MAX interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, a Near Field Communication (NFC) interface, and so on.

[0062] In one embodiment of this application, the aforementioned components of the computing device 300 and Figure 3 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 3 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this application. Those skilled in the art can add or replace other components as needed.

[0063] The computing device 300 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or PCs. The computing device 300 can also be a mobile or stationary server.

[0064] The processor 320 is used to execute computer-executable instructions for the precise timing and billing method for the accelerator.

[0065] The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device and the technical solution of the precise timing and billing method for accelerators described above belong to the same concept. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solution of the precise timing and billing method for accelerators described above.

[0066] An embodiment of this application also provides a computer-readable storage medium storing computer instructions that, when executed by a processor, are used to implement the steps of the precise timing and billing method for the accelerator.

[0067] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium belongs to the same concept as the technical solution of the above-described precise timing and billing method for accelerators. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solution of the above-described precise timing and billing method for accelerators.

[0068] An embodiment of this application also provides a chip that stores a computer program, which, when executed by the chip, implements the steps of the precise timing and billing method for the accelerator.

[0069] The foregoing has described specific embodiments of this application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0070] The computer instructions include computer program code, which may be in the form of source code, object code, executable file, or certain intermediate forms. The computer-readable medium may include any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium may be appropriately added to or subtracted according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media may not include electrical carrier signals and telecommunication signals.

[0071] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0072] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0073] The preferred embodiments disclosed above are merely illustrative of this application. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the content of this application. These embodiments are selected and specifically described in this application to better explain the principles and practical applications of this application, thereby enabling those skilled in the art to better understand and utilize this application. This application is limited only by the claims and their full scope and equivalents.

Claims

1. A precise timing and billing method for accelerators, characterized in that, include: Based on a preset fixed interval of seconds, a heartbeat is sent from the client to the message queue on the server. The heartbeat is then processed asynchronously by an independent consumer thread on the server, updating the sorted set in Redis. The Score field in the sorted set is assigned a timestamp, and duplicate client records are eliminated through the automatic deduplication feature of the sorted set. The server starts a daemon process that performs a heartbeat expiration check every second. The heartbeat expiration check uses a blocking method to obtain the oldest heartbeat. When the client is detected to be offline or the user actively stops the service, the server immediately terminates the billing timer and performs minute-level precision billing by combining the timestamps stored in the ordered set.

2. The method according to claim 1, characterized in that, The updated Redis sorted set includes: The server uses the ZADD command to write the client's unique identifier as Member and the timestamp as Score into the ordered set based on the client's unique identifier in the heartbeat. If the client already exists in the ordered set, its original Score is automatically overwritten with the latest timestamp.

3. The method according to claim 1, characterized in that, The heartbeat expiration detection employs a blocking method to obtain the oldest heartbeat, including: The daemon process obtains the oldest heartbeat with the smallest score in the ordered set using the ZRANGE command. If the ordered set is empty, the daemon process enters a blocked waiting state until new heartbeat data is written into the ordered set and it is then awakened.

4. The method according to claim 3, characterized in that, The heartbeat detection includes: Calculate the difference between the current system time's millisecond-level timestamp and the preset timeout threshold, and use it as the expiration determination threshold; The score of the oldest heartbeat is compared with the expiration threshold. If the score is less than or equal to the expiration threshold, the corresponding client heartbeat is determined to have expired.

5. The method according to claim 4, characterized in that, After determining the corresponding client's heartbeat period, the process also includes: The daemon process removes the client from the ordered set using the ZREM command and generates a client offline event, which is then pushed to the billing core module.

6. The method according to claim 1, characterized in that, The situations in which the client is detected to be offline include at least one of the following: the daemon process determines that the client's heartbeat has expired, the server receives an offline command actively sent by the client, or the network connection between the server and the client is abnormally disconnected.

7. The method according to claim 1, characterized in that, The step of combining the timestamps stored in the ordered set to perform minute-level precision timekeeping and billing includes: Extract the first online timestamp and the last heartbeat timestamp of the client from the ordered set. The first online timestamp is extracted from the ordered set and stored in the billing log database by the server when it first receives the heartbeat of the client. The last heartbeat timestamp is the latest Score value of the client in the ordered set. The time difference between the first online timestamp and the last heartbeat timestamp is calculated and converted into duration, and the duration is billed and accounted for with minute-level precision.

8. A precise timing and billing device for accelerators, characterized in that, include: The first module is configured to send heartbeats from the client to the message queue on the server at a preset fixed interval of seconds, and to process the heartbeats asynchronously through an independent consumer thread on the server, updating the sorted set in Redis. The Score field in the sorted set is assigned a timestamp, and duplicate client records are eliminated through the automatic deduplication feature of the sorted set. The second module is configured to start a daemon process based on the server and perform a heartbeat expiration detection every second. The heartbeat expiration detection adopts a blocking method to obtain the oldest heartbeat. The third module is configured to immediately terminate the billing timer when the client is detected to be offline or the user actively stops the transaction, and perform timekeeping and billing with minute-level precision by combining the timestamps stored in the ordered set.

9. A computing device, characterized in that, include: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the steps of the precise timing and billing method for accelerators according to any one of claims 1 to 7.

10. A computer-readable storage medium storing computer instructions, characterized in that, When executed by the processor, this instruction implements the steps of the precise timing and billing method for accelerators as described in any one of claims 1 to 7.