Token gateway-based lease semaphore management method, device and equipment
By cleaning up and predicting leases in the token gateway and dynamically adjusting the concurrency limit, the problems of inconsistent admission judgment and resource utilization under node abnormalities in semaphore management are solved, thereby improving resource utilization and processing efficiency.
Patent Information
- Application Number
- CN202611612982.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-19
- Publication Date
- 2026-11-27
AI Technical Summary
In existing semaphore management methods, the admission judgment is inconsistent with the actual available capacity, and the ability to reclaim occupied resources and adjust control parameters is insufficient in abnormal node scenarios, resulting in discontinuous resource utilization, repeated request rejection and retries, and inability to alleviate processing pressure in a timely manner.
By cleaning up the expiring leases of the ordered set in the token gateway, counting the number of expiring leases in the future prediction window, and reducing them according to the reliability of release, the admission confidence level is determined by combining the shared prediction admission quota, and the concurrency limit is dynamically adjusted to avoid resource waste and anomaly handling.
It achieves consistency between admission criteria and actual available capacity, reduces the number of requests rejected in batches and retries, improves resource utilization, automatically adjusts the concurrency limit, and reduces the pressure caused by node anomalies.
Smart Images

Figure CN123185263A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data management, and more specifically to a method, apparatus, and device for managing leased semaphores based on a token gateway. Background Technology
[0002] In distributed systems, multiple request nodes typically need to coordinate concurrent access to shared resources. To prevent excessive consumption of shared resources, a concurrency limit is usually configured for the shared resources, and the current occupancy status is recorded using semaphores. Taking a token gateway accessing a large language model service as an example, the token gateway provides the large language model application programming interface (API) call capability to multiple clients and schedules client requests to the corresponding upstream services, each of which is configured with a maximum concurrency. After a request arrives at the token gateway, a concurrent slot is detected and occupied in the distributed coordination layer, and the slot is released after the request is processed. To handle the reclamation of occupied slots when a node stops abnormally, a lease and expiration time are usually recorded for each slot when it is occupied; the slot is considered invalid when the lease expires.
[0003] In related technologies, admission decisions are primarily based on the current number of slots occupied. When the number of slots occupied reaches the concurrency limit, new requests are directly rejected until a slot is released. Methods for maintaining the occupancy status include database row locks, counting methods, etc. Some solutions use ordered sets in the distributed coordination layer to store timestamped occupancy records, but these are only used for cleaning up expired records or for sliding window statistics of request counts. For long-running requests, they are typically managed with fixed lease durations, and are reclaimed upon expiration. Other solutions deploy independent watchdog components to monitor node status; if a node malfunctions, the watchdog triggers occupancy reclamation. However, in current semaphore management methods, admission decisions are based solely on the current number of slots occupied. When approaching the concurrency limit, even if leases are expiring and corresponding slots are free, new requests are still directly rejected. Requests repeatedly alternate between rejection and retry, preventing continuous utilization of processing resources. Secondly, after a node stops abnormally, its lease remains counted in the occupied quantity until its expiration, thus the concurrency limit is artificially occupied. Fixed lease durations may also incorrectly reclaim long-running requests, and relying on an external watchdog requires additional deployment and maintenance monitoring components. Thirdly, waiting requests are only awakened and re-performed admission checks after the slot is released, resulting in a waiting gap between release and the start of new request processing. Finally, the cleanup of expired occupancy records is treated as routine maintenance, and control parameters such as the concurrency limit remain unchanged, failing to alleviate processing pressure during abnormal periods in a timely manner. Therefore, a novel technical solution is urgently needed to overcome at least one of the above technical problems. Summary of the Invention
[0004] This application provides a method, apparatus, and device for managing leased semaphores based on a token gateway, which addresses the technical problems of inconsistencies between admission judgment and actual available capacity, insufficient capacity for reclaiming occupied semaphores in abnormal node scenarios, and inadequate control parameter adjustment capabilities in existing semaphore management methods.
[0005] In a first aspect, embodiments of this application provide a method for managing leased semaphores based on a token gateway, the method comprising: Obtain concurrent slot occupancy requests for the target upstream service; In response to the concurrent slot occupancy request, expired leases are cleared from the ordered set corresponding to the target upstream service to obtain the number of expired leases cleared in this cleanup. The members of the ordered set are lease identifiers, and the score of the members is the lease expiration time. The number of expiring leases in the ordered set whose expiration dates fall within a preset future prediction window is obtained. Based on the reliability of the release of the expiring leases, the number of expiring leases within the prediction window is reduced to obtain the revised expected release capacity; The shared predicted admission quota available for the current request is determined based on the difference between the revised expected release capacity and the predicted quota already occupied by other requesting access nodes. When the number of current leases in the ordered set reaches the concurrency limit, the admission confidence of the current request is determined based on the shared predicted admission quota and the excess amount by which the number of current leases exceeds the concurrency limit. If the number of current leases does not reach the concurrency limit, or if the number of current leases reaches the concurrency limit and the admission confidence level reaches the preset minimum admission confidence level threshold, then the current request is accepted and the lease corresponding to the current request is written into the ordered set; otherwise, the current request is rejected; wherein, the score of the written lease is the sum of the current time and the preset lease duration; After the current request is processed, the lease corresponding to the current request is deleted from the ordered set, and the concurrent slot occupied by the current request is released.
[0006] Secondly, embodiments of this application provide a token gateway-based lease semaphore management device, which is used to execute the token gateway-based lease semaphore management method described in any one of the first aspects. The device includes: The input / output module is configured to obtain concurrent slot occupancy requests for the target upstream service; The processing module is configured to respond to the concurrent slot occupancy request by clearing expired leases in the ordered set corresponding to the target upstream service, obtaining the number of expired leases to be cleared in this cleanup, where the members of the ordered set are lease identifiers and the scores of the members are lease expiration times; counting the expired leases in the ordered set whose expiration times fall within a future preset prediction window, obtaining the number of expired leases within the prediction window; reducing the number of expired leases within the prediction window according to the reliability of the release of the expired leases, obtaining a corrected estimated release capacity; determining the shared predicted admission quota available to the current request based on the difference between the corrected estimated release capacity and the predicted quota already occupied by other requesting access nodes; and in the ordered set... If the number of current leases in the set reaches the concurrency limit, the admission confidence of the current request is determined based on the shared predicted admission quota and the excess amount of the current leases exceeding the concurrency limit. If the number of current leases does not reach the concurrency limit, or if the number of current leases reaches the concurrency limit and the admission confidence reaches the preset minimum admission confidence threshold, the current request is accepted, and the lease corresponding to the current request is written into the ordered set. Otherwise, the current request is rejected. The score of the written lease is the sum of the current time and the preset lease duration. After the current request is processed, the lease corresponding to the current request is deleted from the ordered set, and the concurrent slot occupied by the current request is released.
[0007] Thirdly, embodiments of this application provide a computer-readable storage medium including instructions that, when executed on a computer, cause the computer to perform the token gateway-based leased semaphore management method as described in the first aspect.
[0008] Fourthly, embodiments of this application provide a computing device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the token gateway-based leased semaphore management method described in the first aspect.
[0009] Compared to existing technologies, in this embodiment, upon receiving concurrent slot occupancy requests for the target upstream service, the system first cleans up expired leases in the ordered set and counts the number of expired leases within a future preset prediction window. Then, the number of expired leases is reduced based on the reliability of their release, resulting in a revised estimated release capacity. This revised capacity is combined with a shared prediction admission threshold to determine the admission confidence level. Consequently, when approaching the concurrency limit, requests are accepted in a controlled manner according to the admission confidence level, ensuring that the admission judgment aligns with the actual available capacity. When approaching the concurrency limit, slots that are already or about to become idle can be utilized, reducing the likelihood of batch rejections and repeated retries, and ensuring continuous utilization of processing resources. Simultaneously, the number of expired leases obtained from the cleanup, along with the unit capacity cleanup ratio, the consecutive abnormal window count, lease source clustering, and expiration time clustering, are used to identify node anomalies. This automatically reduces the concurrency limit without deploying an external watchdog component and gradually restores it if no anomalies are observed during the observation period. Long-running requests can have their leases extended through renewal to prevent accidental reclaiming; even if renewal fails, the request is still allowed to complete. Based on the lease score distribution, the expected release time of the next slot is predicted and pre-inspection is completed in advance. After the slot is released, the pre-inspection results can be directly reused, shortening the waiting gap between release and the start of processing new requests. Therefore, this application's embodiment solves the problems of inconsistency between admission judgment and actual available capacity, insufficient occupancy reclamation and control parameter adjustment capabilities in existing semaphore management methods under abnormal node scenarios. Attached Figure Description
[0010] The objectives, features, and advantages of the embodiments of this application will become readily understood by referring to the accompanying drawings and the detailed description of the embodiments. Wherein: Figure 1 This is a system schematic diagram of a token gateway-based leased semaphore management method in an embodiment of this application; Figure 2 This is a flowchart illustrating a token-based gateway-based leased semaphore management method according to an embodiment of this application. Figure 3 This is a schematic diagram illustrating the principle of a token-based gateway-based leased semaphore management method according to an embodiment of this application. Figure 4 This is a schematic diagram of the structure of the token gateway-based leased semaphore management device according to an embodiment of this application; Figure 5 This is a schematic diagram of the structure of a computing device according to an embodiment of this application; Figure 6 This is a schematic diagram of a server structure in one embodiment of this application.
[0011] In the accompanying drawings, the same or corresponding reference numerals indicate the same or corresponding parts. Detailed Implementation
[0012] The terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or modules is not necessarily limited to those explicitly listed, but may include other steps or modules not explicitly listed or inherent to these processes, methods, products, or devices. The division of modules in the embodiments of this application is merely a logical division; in actual applications, there may be other division methods. For example, multiple modules may be combined or integrated into another system, or some features may be omitted or not performed. Additionally, the shown or discussed mutual coupling, direct coupling, or communication connection may be through some interface; indirect coupling between modules; and communication connections may be electrical or other similar forms, none of which are limited in the embodiments of this application. Furthermore, the modules or sub-modules described as separate components may or may not be physically separated, may or may not be physical modules, or may be distributed among multiple circuit modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiments of this application.
[0013] This application provides a method, apparatus, and device for managing leased semaphores based on a token gateway, applicable to request access scenarios for distributed high-concurrency services. In practical applications, the token gateway receives multiple client requests and schedules them to corresponding upstream services, such as a large language model API service, each configured with a maximum concurrency. The token gateway occupies concurrent slots in the distributed coordination layer in the form of leases, releasing the corresponding leases after request processing is complete. Specifically, in the request access scenario, multiple request access nodes receive client requests and schedule them to corresponding upstream services, each configured with a maximum concurrency. Request access nodes occupy concurrent slots in the distributed coordination layer in the form of leases, releasing the corresponding leases after request processing is complete. The distributed coordination layer can be a distributed cluster composed of multiple server nodes, where leases corresponding to each upstream service are stored in an ordered set, the members of the ordered set being lease identifiers, and the scores of the members representing lease expiration times.
[0014] In practical applications, the embodiments of this application can also be applied to traffic management scenarios of token gateways. Taking the token gateway accessing a large language model service as an example, the token gateway provides large language model API call capabilities to multiple clients. During the processing of each API request, a system resource needs to be leased, namely a concurrent slot of the target upstream service. After the request is completed, the concurrent slot is returned. The token gateway determines how many requests to allow, how long to set the lease for each resource, whether to renew the lease, and when to forcibly reclaim the resource based on semaphores.
[0015] In this embodiment, leasing is used to indicate that the occupation of a concurrent slot is time-limited. After a request is accepted, a concurrent slot is leased for the request, and the request holds the right to use the concurrent slot during the lease period. After the request is processed, the concurrent slot is returned. If the node corresponding to the request stops abnormally, and the concurrent slot is not returned upon completion, the corresponding lease expires after the lease period ends and is automatically reclaimed by the system in subsequent cleanup operations. The concurrent slot will not be permanently occupied due to node abnormality. Taking the token gateway accessing the large language model service as an example, each large language model API call request initiated by the client leases a concurrent slot from the target upstream service during processing and returns it after processing.
[0016] Semaphores are mechanisms for counting and synchronizing the availability of shared resources. In this embodiment, a semaphore describes the number of concurrent slots currently available for lease in the target upstream service, where the number of currently available slots is the difference between the concurrency limit and the current number of leases. The requesting access node determines, based on the semaphore, how many requests to allow, the lease duration to set for the requests, whether to renew the lease, and when to reclaim the lease. It can be understood that a semaphore describes how many concurrent slots are available for lease in the target upstream service. The state of the semaphore is maintained using an ordered set; writing a lease means leasing out a concurrent slot, and deleting a lease means returning a concurrent slot. The number of members in the ordered set reflects the number of concurrent slots currently leased.
[0017] The following embodiments use the example of a token gateway accessing a large language model service. This application's embodiments can also be applied to other scenarios where a gateway provides unified access and limits concurrent access, such as various traffic management scenarios that provide application programming interface services to clients; this application's embodiments do not limit these applications.
[0018] In existing technologies, admission decisions are primarily based on the current occupied quantity. When the occupied quantity reaches the concurrency limit, new requests are directly rejected until a slot is released. During periods when the occupied quantity is close to the concurrency limit, even if leases expire and corresponding slots become available, new requests are still directly rejected. Requests repeatedly alternate between rejection and retry, preventing continuous utilization of processing resources. After a node abnormally stops, its leases are still counted in the occupied quantity before expiration, resulting in the concurrency limit being artificially occupied. Fixed lease durations may also incorrectly reclaim long-running requests, and relying on external watchdogs requires additional deployment and maintenance of monitoring components.
[0019] Compared to existing technologies, in this embodiment, upon receiving a concurrent slot occupancy request for a target upstream service, the system first clears the expired leases in the ordered set corresponding to the target upstream service to obtain the number of expired leases cleared. Then, it counts the number of expired leases within a preset prediction window. Based on the reliability of the release of these expired leases, the number of expired leases within the prediction window is reduced to obtain a corrected estimated release capacity. This revised capacity is then combined with a shared prediction admission threshold to determine the admission confidence level. When the current number of leases has not reached the concurrency limit, or when the current number of leases has reached the concurrency limit and the admission confidence level reaches a preset minimum admission confidence threshold, the current request is accepted, and the lease corresponding to the current request is written into the ordered set. This allows the system to utilize actually idle slots when approaching the concurrency limit, reducing the likelihood of requests being rejected in batches and repeatedly retried. Finally, after the current request is processed, the corresponding lease is deleted, releasing the concurrent slot. Furthermore, this embodiment of the application can also identify node anomalies based on the number of expired leases obtained in each cleanup and adaptively adjust the concurrency limit, perform renewal for long-running requests, and perform pre-checks on candidate upstreams in advance based on the lease score distribution. Related implementation methods will be elaborated in subsequent embodiments.
[0020] In some implementations, the token-gateway-based leased semaphore management system of this application may include multiple request access nodes, a distributed coordination layer, and a candidate upstream set. Each request access node may be a computing device with request scheduling capabilities, such as a gateway node. The distributed coordination layer maintains a semaphore repository, which stores leases of each upstream service in an ordered set. Each lease is represented by a member and a score, where the member is a lease identifier, such as a Universally Unique Identifier (UUID), and the score is the lease's expiration time. Request access nodes execute semaphore-related operations on the ordered set through an atomic operation layer. This atomic operation layer encapsulates multi-step operations involving semaphores into scripts for execution, ensuring the atomicity of these operations. A predictive admission module determines the corrected expected release capacity and admission confidence level based on the number of expiring leases within the prediction window. A crash detection module determines whether a request access node has malfunctioned based on the number of expired leases obtained from each cleanup. A renewal management module updates the score of the corresponding lease when the request's runtime approaches the preset lease duration. The latency baseline pool is used to record latency statistics for each upstream service. The preheating ready queue predicts the capacity release time based on the latency statistics and the score distribution of each lease in the ordered set, and caches the pre-detection results of candidate upstream services. The above module division is only a logical division; the functions of the modules can be implemented by the request access node or the computing devices in the distributed coordination layer, and this application embodiment does not limit this.
[0021] Reference Figure 1 , Figure 1 This is a schematic diagram of a semaphore coordination and admission decision structure provided in an embodiment of this application. The specific modules are as follows: The semaphore store, as the core data structure, stores all currently active leases in an ordered set. Each lease consists of a member and a score. The member is a globally unique lease identifier, such as a Universally Unique Identifier (UUID), and the score is the absolute millisecond timestamp of the lease's expiration. The semaphore store supports dual Time To Live (TTL) protection: at the member level, the lease expiration time is represented by the score set when the lease is written; at the key level, a self-destruct time is set for the entire ordered set to prevent null keys from remaining in abnormal scenarios.
[0022] A predictive admission module is used to count the number of leases that will expire within a future prediction window each time a concurrent slot occupancy request is executed, in addition to clearing expired leases and checking the current number of leases. Further, the predictive admission module divides the expired leases within the prediction window into leases that have not yet entered the renewal trigger period and leases that have entered the renewal trigger period, assigning different release weights to each. Then, it reduces the original estimated release amount based on historical on-time release reliability to obtain a corrected estimated release capacity. Controlled admission parameters are generated only if the corrected estimated release capacity can cover the current excess. In another embodiment, the corrected estimated release capacity can be written into a predictive admission quota shared by multiple requesting access nodes. Quota checks and deductions are performed in the same atomic operation to avoid multiple requesting access nodes reusing the same estimated release capacity. After the prediction window ends, the quota is then recalculated and adjusted based on the actual release quantity.
[0023] The crash detection module is used to obtain the actual number of expired leases cleaned up each time a concurrent slot occupancy request is executed, and further calculates the unit capacity cleanup ratio, the number of consecutive anomalies, the lease source clustering, and the expiration time clustering. The unit capacity cleanup ratio is used to distinguish between normal reclamation of large-capacity upstream services and abnormally amplified cleanup of small-capacity upstream services. The number of consecutive anomalies is used to suppress false positives caused by single jitters. The lease source clustering is used to identify whether a large number of legacy leases are concentrated from the same request access node. The expiration time clustering is used to identify whether there is an abnormal pattern of intensive reclamation within a narrow time window. Only when the primary criterion and at least one auxiliary criterion simultaneously meet the threshold is it determined that the target upstream service has recently experienced a node anomaly. The primary criterion can be the product of the sliding window average cleanup count exceeding the baseline cleanup count and the preset crash detection threshold multiple. After triggering, the concurrency limit of the target upstream service enters a protective state, temporarily reduced according to a preset derating ratio. If no further anomalies are triggered within the preset observation window, it enters a recovery state and gradually recovers to the original concurrency limit according to a preset recovery cycle and preset recovery step size. If the abnormal conditions are met again during the recovery period, the system will immediately return to the protected state.
[0024] The renewal management module initiates a renewal before the request is completed when the request's runtime approaches the preset lease duration. The lease score is updated to the sum of the current time and the new preset lease duration. Renewal trigger conditions can be determined based on the ratio of the request's runtime to the current preset lease duration, or by whether the predicted remaining execution time exceeds the remaining lease time. To prevent the renewal mechanism from being used to indefinitely extend the lease period, the module can also set a single renewal duration limit, a maximum number of renewals per request, and a maximum total lease lifetime. When the number of current leases in the ordered set reaches the concurrency limit, or the renewal limit is reached, a timeout protection mode is entered: the original request is allowed to continue completing, but it no longer participates in new concurrency placeholder statistics, and no release notification is triggered upon completion, thus preventing the same request from repeatedly overdrawing concurrency capacity.
[0025] The atomic operation layer encapsulates all operations involving semaphores into scripts executed in the distributed coordination layer, such as Redis's Lua scripts, ensuring the atomicity of multi-step operations and eliminating race conditions. In one implementation, the server time or a unified time source of the distributed coordination layer is used as the current time reference, and expired lease cleanup, cleanup quantity acquisition, future window lease expiration statistics, current lease count statistics, shared predicted quota check and deduction, and new lease writing are completed sequentially in the same atomic operation. This avoids inconsistencies in judgment caused by local clock deviations of different request access nodes and concurrent write competition.
[0026] The circuit breaker state pool is used to store the concurrency protection state information of the target upstream service. This concurrency protection state information includes a status identifier for either the protected or recovered state, and the corresponding concurrency limit. For example... Figure 1 As shown, the circuit breaker state pool provides the concurrency protection status information to the crash detection module. The crash detection module combines the statistics of expired lease cleanup with the concurrency protection status information to determine the concurrency protection control operations for the target upstream service. These operations include lowering the concurrency limit when a node anomaly is detected, gradually restoring the concurrency limit if no node anomaly is detected again within a preset observation window, and lowering the concurrency limit again if a node anomaly is detected again during the recovery process. Operations involving semaphores are executed through the atomic operation layer.
[0027] The latency baseline pool records historical latency statistics for each upstream service and provides latency statistics for the target upstream service to the predictive admission module. The predictive admission module sets the prediction window length based on the latency statistics of the target upstream service and counts the number of leases expiring within the prediction window, providing a basis for subsequently determining the revised expected release capacity.
[0028] Figure 1In Redis, ZADD represents the operation of adding members or updating scores on a sorted set. When renewal is allowed, the renewal management module performs a ZADD operation through the atomic operation layer, updates the score of the member corresponding to the target lease, keeps the lease identifier unchanged, and updates the lease expiration time to the sum of the current time and the preset lease duration.
[0029] Figure 1 In this context, ZSET represents an ordered set, member represents a member within the ordered set, and score represents the score associated with each member. In this embodiment, member is the lease identifier, and score is the lease expiration time. ZCOUNT represents the operation of counting the number of members in the ordered set whose scores fall within a specified range. "ZCOUNT lookahead" means using the above statistical operation to obtain the number of leases that will expire within a future prediction window.
[0030] The above-mentioned division of modules is only a logical division. The functions of the modules can be implemented by the request access node or the computing device in the distributed coordination layer. This application embodiment does not limit this.
[0031] It should be noted that the computing devices involved in the embodiments of this application can be request access nodes, server nodes in the distributed coordination layer, etc. The servers involved in the embodiments of this application can be independent physical servers, server clusters or distributed systems composed of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
[0032] Figure 2 This is a flowchart illustrating a token-based lease semaphore management method provided in an embodiment of this application. This method can be executed by a token-based lease semaphore management device and can be applied to request access scenarios for distributed high-concurrency services. (Refer to...) Figure 2 The method includes steps 101-108: Step 101: Obtain concurrent slot occupancy requests for the target upstream service.
[0033] In distributed, high-concurrency service request access scenarios, the request access node can be a gateway node of a token gateway, used to receive client requests and schedule them to the corresponding upstream service. Taking the token gateway accessing a large language model service as an example, the token gateway manages multiple upstream services, each configured with a maximum concurrency level, i.e., a concurrency limit. After a request arrives at the token gateway, the token gateway needs to reserve a concurrent slot for the request at the upstream service. One concurrent slot corresponds to one lease, and the lease is released after the request is processed. After determining the target upstream service, the token gateway generates a concurrent slot reservation request for the target upstream service.
[0034] In this embodiment, the upstream service is a backend service that provides actual processing capabilities to the client. Taking the token gateway accessing the large language model service as an example, the upstream service can be the large language model API service deployed on the backend. The token gateway schedules client requests to the upstream service for processing. Each upstream service is configured with a maximum concurrency, i.e., a concurrency limit. The upstream service can process a maximum number of requests at any given time. The token gateway can manage multiple upstream services, for example, about 100 upstream services. The concurrency limit of each upstream service can be different, for example, ranging from 4 to 128. The target upstream service is the upstream service to which the current request is scheduled, i.e., the upstream service selected from the candidate upstreams that carries the processing of the current request. During the candidate selection phase, in addition to the target upstream service, there are other candidate upstreams that provide similar services. Each upstream service corresponds one-to-one with an ordered set storing its leases. The ordered set corresponding to the target upstream service stores all leases currently occupying the concurrent slots of the target upstream service.
[0035] In this embodiment, the concurrent slot occupancy request is used to request a concurrent slot at the target upstream service for the current request, that is, to request the writing of a lease in the ordered set corresponding to the target upstream service. The concurrent slot occupancy request can be generated by the request access node after determining the target upstream service, and at least associates the identifier of the target upstream service with the request identifier of the current request. The identifier of the target upstream service is used to locate the ordered set corresponding to the target upstream service; for example, the key of the ordered set can be composed of the identifier of the target upstream service and the concurrency control identifier. The request identifier is used to establish the correspondence between the current request and the subsequently written lease, so that the corresponding lease can be deleted according to the correspondence after the current request is processed. The lease identifier and lease expiration time used when writing the lease can be generated when initiating the occupancy request or during the write operation of the ordered set. The lease identifier can be a universally unique identifier (UUID), and the lease expiration time is, for example, the sum of the current time and the preset lease duration; this embodiment does not limit this. There are multiple ways to obtain the concurrent slot occupancy request. In one approach, the request access node receives a client request, determines the target upstream service through candidate selection, and then generates a concurrent slot allocation request for the current request. In another approach, after completing candidate selection, the scheduling component of the request access node passes the concurrent slot allocation request to the component performing admission processing. The admission processing component then retrieves the concurrent slot allocation request and performs subsequent cleanup, statistics, judgment, and write operations. If the current request is rejected, the request access node can regenerate a concurrent slot allocation request for the next candidate upstream service according to the candidate ranking and try again.
[0036] The requesting access node can retrieve the configuration and real-time status of multiple candidate upstreams in a batch. For example, in a batch read operation, the configuration and real-time status of all candidate upstreams are prefetched. Initial hard filtering is performed based on conditions such as availability and whether each candidate upstream is in an abnormal state. Then, the candidate upstreams are ranked according to multi-dimensional scores, such as combining historical round-trip latency, current load, and health status scores of each candidate upstream. The optimal candidate is selected as the target upstream service, and then concurrent slot occupancy requests are initiated for the target upstream service. The above candidate selection method is for illustrative purposes only and is not limited in this embodiment.
[0037] Please refer to Figure 3 , Figure 3This is a schematic diagram illustrating the coordination of scheduling execution and targeted preheating in an embodiment of this application. In this embodiment, the requesting access node involves a latency baseline pool, an atomic operation layer, a preheating ready queue, candidate matching and release notification, and a candidate upstream set during the scheduling execution and targeted preheating process. The latency baseline pool is used to record the latency statistics (latency_ewma) of each upstream service. The atomic operation layer is used to execute the acquire, release, and renew operations in a script manner. After the current request is processed, the request response is returned, the corresponding lease is released, and the candidate matching and release notification executes candidate matching and notifies waiting requests when the release occurs. Before release, the expected release time of the next slot is calculated based on the expiration score distribution of the current active leases, and then combined with the historical round-trip latency of the candidate upstream, the pre-check processing time, and the safety buffer time, the pre-check start time is deduced. When the pre-check start time arrives, the target candidate upstream is pre-checked, and the pre-check result is cached in the preheating ready queue. When the actual release occurs, if the pre-inspection result is still valid and the candidate status has not changed, the pre-inspection result is directly reused, and the waiting request is scheduled to the target candidate upstream in the candidate upstream set. This transforms the passive retrying after release into a serial waiting process and the active preparation before release into a parallel warm-up process.
[0038] A preheating ready queue is used to predict when capacity will be released in the future, based on latency statistics of each upstream service in the latency baseline pool and the expiration score distribution of current active leases. In one implementation, the expected release time of the next slot is first obtained, and then the pre-check start time is deduced by combining the historical round-trip latency of candidate upstreams, pre-check processing time, and safety buffer time. At or before the pre-check start time, a pre-check is performed on the target candidate upstream, and the pre-check results are cached in the local ready queue. The pre-check results include candidate reachability, the most recent authentication or quota pre-check conclusion, candidate sorting context, and the validity period of the pre-check results; if the candidate status changes, the pre-check results exceed the validity period, or the deviation between the actual release time and the expected release time exceeds a preset range, the pre-check results are invalidated and a new pre-check is performed. This achieves targeted preheating rather than broadcast wake-up, shortening the serial latency gap in the scheduling chain. It is worth noting that... Figure 3 The preheating ready queue is used to cache the pre-inspection results obtained from performing pre-inspection on the candidate upstream, so that they can be reused when the slot is released.
[0039] Figure 3 `latency_ewma` represents the exponentially weighted moving average of historical latency of upstream services, used to provide historical round-trip latency information for candidate upstream services. `Acquire`, `Release`, and `Renew` represent concurrent slot occupancy, lease release, and lease renewal operations, respectively. The preheating ready queue is a local ready queue used by the requesting access node to cache pre-detection results.
[0040] The delay baseline pool provides historical round-trip latency information for candidate upstreams to the preheating process. The preheating process determines the pre-check start time based on the lease expiration time and caches the pre-check results in the preheating ready queue. After the lease release is completed at the atomic operation layer, candidate matching and release notification are executed. If the pre-check result for the corresponding candidate upstream in the preheating ready queue is still valid, the pre-check result is reused, and concurrent slot occupancy requests are initiated for the matched candidate upstreams. The candidate upstream set includes upstream services for the requesting access node to select. After processing the request, the selected upstream service returns a request response to the client through the requesting access node.
[0041] Step 102: In response to the concurrent slot occupancy request, clear expired leases in the ordered set corresponding to the target upstream service to obtain the number of expired leases cleared in this cleanup.
[0042] Expired leases are leases whose scores do not exceed the current time, meaning their expiration time has arrived. Requesting access nodes delete members from the ordered set whose scores do not exceed the current time; the number of deleted members is the number of expired leases cleaned up in this cleanup. The current time is preferentially determined by the server-side time of the distributed coordination layer or a unified time source, rather than the local clocks of each requesting access node, to avoid inconsistencies in the cleanup scope caused by clock deviations between different requesting access nodes.
[0043] In this ordered set, each member is a lease identifier, and each member's score represents the lease expiration time. The ordered set is a collection structure consisting of multiple members, each associated with a score, arranged in order of score size. Members in the ordered set are the basic units constituting the set. Each member corresponds to a lease, i.e., an occupied concurrent slot. Each member carries two pieces of information: first, the lease identifier represented by the member, which is globally unique across multiple requesting access nodes, such as a Universally Unique Identifier (UUID), used to distinguish different leases; second, the score associated with the member, which represents the lease's expiration time. Members are arranged in the ordered set according to their scores, with members having smaller scores and earlier expiration times appearing earlier in the order.
[0044] In this embodiment, the ordered set can be a set type provided by the distributed coordination layer, such as a Sorted Set (ZSET) in Redis. In the ordered set corresponding to the target upstream service, each member corresponds to a lease currently occupying a concurrent slot on the target upstream service, i.e., an active lease. The member is a lease identifier, which is globally unique across multiple request access nodes, such as a Universally Unique Identifier (UUID), used to distinguish different leases. The member's score represents the lease expiration time, such as a Unix timestamp in milliseconds. Members are arranged in ascending order of score; the smaller the score, the earlier the expiration time, and the higher the corresponding lease's ranking in the ordered set.
[0045] The ordered set can be stored in a distributed coordination layer, which can be a distributed cluster consisting of multiple server nodes, such as a Redis cluster. Therefore, the content of the ordered set corresponding to the target upstream service is all leases currently occupying concurrent slots of the target upstream service, and the number of members in the ordered set corresponds to the current number of leases of the target upstream service. When writing a lease, a member is added to the ordered set. When a lease is cleaned up or the corresponding request is processed, the corresponding member is removed from the ordered set. Members are sorted by lease expiration time as a score, so that the cleanup of expired leases and the statistics of expired leases within the prediction window can both be completed on the ordered set through operations based on score ranges. The key of the ordered set corresponding to the target upstream service can be composed of the identifier of the target upstream service and the concurrency control identifier, for example, sku:concurr:{sid}, where sid is the identifier of the target upstream service. In addition to using member scores to represent lease expiration time, a key-level time-to-live (TTL) can be set for the ordered set, so that ordered sets without active leases for a long time are automatically destroyed, preventing null key residues in abnormal scenarios.
[0046] The cleanup operation, along with subsequent statistics, judgment, and write operations, can be completed within the same atomic operation. For example, each operation can be encapsulated into a script executed in the distributed coordination layer, allowing each step to be executed as a whole when multiple requesting nodes concurrently execute their occupancy requests. Through this step, expired leases are promptly reclaimed, and the number of expired leases cleaned up is retained as an implicit signal reflecting the system's health status for subsequent node anomaly detection.
[0047] As an optional embodiment, after obtaining the number of expired leases to be cleaned in step 102, the method further includes: performing an exponential moving average based on the number of expired leases corresponding to the current request and previous requests of the target upstream service, according to a preset smoothing factor, to obtain the average number of leases to be cleaned in the sliding window; and determining the ratio of the average number of leases to be cleaned in the sliding window to the maximum concurrency limit as the cleanup ratio per unit capacity.
[0048] The number of expired leases cleared in this cleanup is not only used for lease reclaiming but also serves as a basis for determining whether a requesting access node is malfunctioning. When a requesting access node abnormally stops, its leases are not normally deleted after the request is processed; instead, they gradually become expired leases after their expiration, and are reclaimed one by one by subsequent cleanup operations. When the number of leases cleared is consistently significantly higher than the normal operating level, it may indicate that a requesting access node is malfunctioning. To suppress false judgments caused by single fluctuations, the number of leases cleared in each cleanup operation can be smoothed out.
[0049] Optionally, to determine whether the number of cleanups is consistently significantly higher than the normal operating level, the average number of cleanups obtained through smoothing within a sliding window can be compared with a reference value for the normal operating level. The reference value can be the product of the baseline number of cleanups and a preset crash detection threshold multiple, for example, a preset crash detection threshold multiple of 3.0. When the average number of cleanups within a sliding window exceeds the reference value continuously across multiple consecutive statistical windows, the number of cleanups is determined to be consistently significantly higher than the normal operating level. The baseline number of cleanups, the preset crash detection threshold multiple, and the number of consecutive statistical windows can be configured according to the operating environment of the target upstream service.
[0050] Smoothing can be achieved using an exponential moving average. Specifically, the number of expired leases cleaned up in this round is multiplied by a preset smoothing factor to obtain the first product. The average number of leases cleaned up in the previous timeframe is multiplied by the result of subtracting the preset smoothing factor to obtain the second product. The first and second products are then added together to obtain the current average number of leases cleaned up in the current timeframe. The preset smoothing factor can be set to 0.3. The cleanup ratio per unit capacity is the ratio of the average number of leases cleaned up in the current timeframe to the concurrency limit. Using the concurrency limit as the denominator helps distinguish between normal batch reclamation of large-capacity upstream services and abnormally amplified cleanup phenomena of small-capacity upstream services, making the cleanup quantities comparable across different upstream services.
[0051] For example, the average number of cleanups in a sliding window can be expressed by the following formula, where the smoothing process is the Exponentially Weighted Moving Average (EWMA): ;in This is the crash detection smoothing factor (default 0.3). The crash detection smoothing factor controls the proportion of the current cleanup count and the historical average count in the average cleanup count of the sliding window. The larger the value, the faster the average number of cleanups per sliding window responds to the current number of cleanups. The smaller the value, the more stable the average cleanup count within the sliding window. The crash detection smoothing factor can be determined based on the fluctuation range of the cleanup count of the target upstream service and adjusted downwards when there are many false positives.
[0052] Understandable The number of expired leases to be cleaned up in this cleanup, i.e., the number of members whose scores are deleted from the ordered set in step 102 do not exceed the number of members at the current moment, is returned in real time by the cleanup operation of each concurrent slot occupancy request, and serves as the input for the average number of cleanups in the sliding window. The average number of slide window cleanups after this update is obtained by summing the results of the number of expired leases cleaned up in this update (weighted by the crash detection smoothing factor) and the average number of slide window cleanups from the previous time step (weighted by one minus the crash detection smoothing factor). It is used to compare with the baseline number of cleanups to determine whether the number of cleanups is significantly higher than the normal operating level, and is also used to calculate the cleanup ratio per unit capacity. The sliding window average cleanup count is the average cleanup count saved after the last concurrent slot occupancy request was executed. During the initial calculation, the sliding window average cleanup count can be taken as the number of expired leases obtained from the first cleanup, or as the average value obtained from historical cleanup counts during the normal operation period of the target upstream service; this embodiment does not limit this. The sliding window average cleanup count is updated on a rolling basis after each cleanup operation. Fluctuations in the number of cleanups in a single instance are diluted by a smoothing factor. The sliding window average cleanup count only increases significantly when the number of cleanups remains consistently high in multiple consecutive occupancy requests, thereby reducing misjudgments caused by single-instance jitter.
[0053] The unit capacity cleaning ratio can be expressed by the following formula: ;in, This refers to the number of expired leases cleared in this cleanup. The concurrency limit for the target upstream service is defined by the configuration of the target upstream service. Taking the larger value between the concurrency limit and 1 in the denominator avoids the calculation being meaningless when the concurrency limit is zero. The unit capacity cleanup ratio, which is the ratio of the average number of cleanups to the concurrency limit, is dimensionless. It is used to distinguish between normal batch cleanup of large-capacity upstream services and abnormally amplified cleanup phenomena of small-capacity upstream services, making the cleanup quantities comparable across different upstream services. The unit capacity cleanup ratio serves as an auxiliary component of the anomaly scoring, reflecting the degree of deviation of the cleanup scale relative to the upstream service capacity.
[0054] The composite anomaly criterion can be expressed by the following formula, which calculates the anomaly score by weighting and summing the components: .
[0055] in, to The preset weights for each component satisfy... The ratio of the average number of cleanups in the sliding window to the baseline number of cleanups is the primary component, while the cleanup ratio per unit capacity, the count of consecutive abnormal windows, and the clustering of lease sources and expiration times are secondary components. The weights corresponding to the primary components can be set higher than those corresponding to the secondary components, and each weight can be determined based on the corresponding component's ability to distinguish node anomalies. When anomaly scoring... When the preset anomaly detection threshold is reached, the request access node corresponding to the target upstream service is determined to have experienced a node anomaly. (Continuous anomaly window count) This is the number of statistical windows that continuously meet abnormal conditions, used to suppress single-instance jitter. The preset abnormal judgment threshold can be configured according to the operating environment.
[0056] It is worth noting that, The average number of cleanups per sliding window. The baseline cleanup count represents the normal level of a single cleanup operation under normal operating conditions. It can be taken as the statistical value of the historical cleanup count during the normal operating period of the target upstream service and can be updated periodically according to changes in operating status. The ratio of the sliding window average cleanup count to the baseline cleanup count is the principal component, used to measure the deviation of the cleanup count from the normal level. It can be understood that the baseline cleanup count is a reference value for the single cleanup count under normal operating conditions, determined based on the historical cleanup count statistics during the normal operating period of the target upstream service, and the baseline cleanup count is greater than zero. When the statistical value of the historical cleanup count is zero, a preset positive baseline lower limit is used as the baseline cleanup count. When the statistical value of the historical cleanup count is greater than zero, the larger value between the statistical value and the positive baseline lower limit is used as the baseline cleanup count to avoid the ratio of the sliding window average cleanup count to the baseline cleanup count being divided by zero and to suppress abnormally amplified ratios caused by excessively small baseline cleanup counts.
[0057] This refers to the cleanup ratio per unit capacity. This is the consecutive abnormal window count, which is the number of statistical windows that continuously meet the abnormal conditions. It is used to suppress single jitters, and its judgment threshold can be configured according to the operating environment. The lease source clustering degree indicates whether the leases being cleared are concentrated from the same requesting access node. It can be determined based on the proportion of leases from the same requesting access node in this clearing, and is used to identify whether a large number of legacy leases have the same source. The expiration time clustering degree indicates whether the expiration times of the leases being cleared are concentrated within a preset time window. It can be determined based on the distribution concentration of the expiration times of the leases being cleared, and is used to identify abnormal patterns of concentrated clearing within a short period. For example, a clustering statistical window length Δexp > 0 can be preset. For each expired lease in this clearing, the expiration time is used as the starting point of the window. The number of leases whose expiration times fall within a left-closed, right-open window of length Δexp is counted. The ratio of the maximum count to the total number of expired leases cleared in this clearing is taken as the expiration time clustering degree. If expired leases are not cleared, Take 0. The value range is [0, 1]. The larger the value, the more concentrated the expiration time. It is worth noting that each component can be normalized to the same value range to participate in the weighting, but this application does not limit this.
[0058] After a node anomaly is detected, the concurrency limit of the target upstream service enters a protected state. The reduced concurrency limit can be expressed by the following formula:
[0059] in, This is the percentage reduction (default 0.3). Minimum capacity for safety (default is 1). The derating ratio controls the extent to which the concurrency limit is reduced in protected mode, and can be determined based on the upstream service's tolerance for overload; the less redundant the upstream service's processing capacity, the larger the derating ratio can be.
[0060] Slope restoration: After each restoration cycle If no exception is triggered again, the concurrency limit will be reduced. Increase recovery step size Until it recovers to the original concurrency limit. For example, the recovery period can be set to 30 seconds, and the recovery step size to 1. The recovery period and recovery step size together determine the recovery speed of the concurrency limit, which can be adjusted according to the capacity and stability requirements of the upstream service. The shorter the recovery period and the larger the recovery step size, the faster the recovery.
[0061] Further optionally, in the above embodiments, after determining the ratio of the average number of sliding window cleanups to the concurrency limit as the unit capacity cleanup ratio, the method further includes: determining whether the request access node corresponding to the target upstream service is abnormal based on the average number of sliding window cleanups, the unit capacity cleanup ratio, the consecutive abnormal window count, the lease source clustering degree, and the expiration time clustering degree; determining that a node abnormality has occurred when the average number of sliding window cleanups exceeds the product of the baseline cleanup number and the preset crash detection threshold multiple, and at least one of the unit capacity cleanup ratio, the consecutive abnormal window count, the lease source clustering degree, and the expiration time clustering degree exceeds the corresponding preset threshold; when a node abnormality is determined to have occurred, reducing the concurrency limit by a preset reduction ratio, wherein the reduced concurrency limit is not lower than the preset minimum safe capacity; when no node abnormality is determined to have occurred again within a preset observation window, gradually increasing the concurrency limit by a preset recovery period and a preset recovery step size; when a node abnormality is determined to have occurred again during the process of increasing the concurrency limit, stopping the increase, and reducing the concurrency limit again by the preset reduction ratio.
[0062] When determining whether a requesting access node has experienced an anomaly, a composite criterion combining a primary criterion and auxiliary criters is used. The primary criterion is that the average number of cleanups in the sliding window exceeds the product of the baseline cleanup number and a preset crash detection threshold multiple. The preset crash detection threshold multiple can be 3.0. The baseline cleanup number is the normal level of a single cleanup under normal operating conditions, such as being less than 5% of the concurrency limit. Auxiliary criteria include at least one of the following: unit capacity cleanup ratio, consecutive abnormal window count, lease source clustering, and expiration time clustering, all exceeding the corresponding preset threshold. The consecutive abnormal window count is the number of statistical windows that consecutively meet the abnormal conditions, used to suppress single-time jitter. Lease source clustering indicates whether the cleaned leases are concentrated from the same requesting access node, used to identify whether a large number of legacy leases share the same origin. Expiration time clustering indicates whether the expiration times of the cleaned leases are concentrated within a narrow time window, used to identify abnormal patterns of intensive recycling within a short period of time. When the primary criterion and at least one auxiliary criterion are simultaneously satisfied, it is determined that the requesting access node corresponding to the target upstream service has recently experienced a node anomaly.
[0063] Upon detecting a node anomaly, the concurrency limit of the target upstream service enters a protected state. The concurrency limit is reduced by a preset derating percentage, which can be 0.3. The reduced concurrency limit is not lower than a preset minimum safe capacity, which can be 1. The principle behind reducing the concurrency limit is that requests corresponding to legacy leases may still be running, and the number of leases in the ordered set may temporarily differ from the actual number of requests. Therefore, a safety capacity needs to be reserved to prevent new access from overloading the upstream service.
[0064] If no node anomaly is detected again within the preset observation window, the system enters recovery mode and gradually increases the concurrency limit according to the preset recovery cycle and preset recovery step size. For example, if no anomaly is triggered again after 30 seconds, the concurrency limit is increased by 1. If a node anomaly is detected again during the process of increasing the concurrency limit, the increase stops, and the concurrency limit is reduced again according to the preset derating ratio, before re-entering protection mode.
[0065] For example, if the concurrency limit of a target upstream service is 64, and a requesting node stops abnormally, its 10 to 30 leases will expire successively within a preset lease duration, such as 125 seconds. Subsequent requests will clean up 1 to 5 legacy leases each time during the cleanup operation. If this cleanup occurs for three consecutive statistical windows, and the cleanup ratio per unit capacity, the clustering degree of lease sources, and the clustering degree of expiration times simultaneously meet the abnormal conditions, then a node abnormality is determined, and the concurrency limit is reduced from 64 to 45. If no abnormality is triggered again after 30 seconds, the concurrency is gradually restored in steps of 1 until it returns to 64. The above values are for illustrative purposes only and do not constitute a limitation on the embodiments of this application.
[0066] Step 103: Count the number of leases in the ordered set whose expiration time falls within a future preset prediction window, and obtain the number of leases that expire within the prediction window.
[0067] The prediction window is a pre-defined time interval in the future, such as a time window starting from the current moment and lasting from 1000 milliseconds to 5000 milliseconds. Leases whose expiration times fall within this pre-defined prediction window are those with a fraction greater than the current moment but not exceeding the sum of the current moment and the prediction window length. These leases have not yet expired but will expire within the prediction window, and the corresponding slots will soon be released.
[0068] The statistical method involves counting members in the ordered set whose scores fall within the aforementioned interval to obtain the number of expiring leases within the prediction window. The number of expiring leases within the prediction window represents the number of slots that will naturally be released within the future prediction window, serving as the data basis for subsequent forward-looking access decisions. Unlike methods that rely solely on the current occupied capacity, the number of expiring leases within the prediction window provides a trend in available capacity changes over a future period.
[0069] For example, the number of expiring leases within the prediction window in step 103 can be represented by the following formula: .in, The key of the ordered set corresponding to the upstream service of the target. For the current moment, This is the length of the prediction window. The length of the prediction window can be determined based on the average request processing time of the target upstream service and the scheduling sensitivity requirements, and can be adjusted according to the prediction hit rate, for example, by taking 2000 milliseconds.
[0070] Dividing leases expiring within the future renewal window into "leases not yet in the renewal window" and "leases already in the renewal window" can be represented as follows: ;in, To predict the number of leases due within the prediction window, step 103 is used to count the number of members in the ordered set whose scores are greater than the current time and do not exceed the sum of the current time and the prediction window length. This refers to the number of leases that have not yet entered the renewal triggering period. In other words, it refers to the number of leases whose corresponding request runtime to the preset lease duration has not reached the preset renewal triggering ratio. The requests corresponding to these leases still have room before the renewal triggering, and the probability of them being released on time is relatively high. The number of leases that have entered the renewal trigger interval refers to the number of leases whose requested runtime ratio to the preset lease duration reaches the preset renewal trigger ratio. Requests corresponding to these leases may initiate renewals to continue occupying slots, and the probability of timely release is low. Dividing the number of expiring leases within the prediction window into two parts based on whether they have entered the renewal trigger interval provides a basis for subsequently weighting and correcting the estimated releaseable capacity according to the release reliability.
[0071] The revised projected release capacity can be expressed as: ;in, The first release weight is used to weight the number of leases that have not entered the renewal trigger interval, for example, 1.0. For the second release weight, the second release weight Less than For example, a value of 0.4 is used to indicate that leases that have entered the renewal trigger period are less reliable and should not be fully considered as being released on time. The reliability of on-time release in history can be determined based on the proportion of leases that actually expire on time within the historical forecast window, for example, by taking 0.85.
[0072] The shared predicted credit limit can be expressed using the following formula: ;in, The revised projected release capacity is obtained by multiplying the sum of the first and second weighted lease numbers by the historical on-time release reliability. The reason for rounding down is that concurrent slots are in integer units. The allocatable predicted capacity is obtained by rounding down the revised projected release capacity. The predicted quota already occupied by other requesting access nodes, i.e., the released capacity already pre-drawn by other requesting access nodes within the same prediction window, is the quota that each requesting access node completes quota checking and deduction in the same atomic operation. The deducted quota is then accumulated to form the total quota. . The shared predicted admission quota is the currently available quota for the current request, calculated as the difference between the adjusted estimated release capacity (rounded down) and the already occupied predicted quota. The larger of this difference and zero is taken to ensure the shared predicted admission quota is not negative. The shared predicted admission quota is used to calculate the admission confidence level under full load conditions, preventing multiple requesting nodes from repeatedly overdrawing the same future estimated release capacity.
[0073] Admission confidence level ( When the capacity is full or exceeded, the following formula is used: ;in, The admission confidence level, ranging from 0 to 1, represents the reliability of accepting the current request when the current number of leases reaches the concurrency limit. To share the predicted access quota, i.e. the predicted quota currently available for the request. This represents the current number of leases, i.e., the number of currently active leases in the ordered set. The maximum number of concurrent connections for the upstream service of the target. +1 represents the baseline excess quantity, which is the number of current leases exceeding the concurrency limit plus one. The "one" here indicates that the current request itself constitutes one share of the excess. The denominator is the larger of the baseline excess quantity and 1, ensuring the ratio is meaningful. The ratio of the shared predicted admission limit to the baseline excess quantity is the admission confidence level; a ratio exceeding 1 is counted as 1. The more the current leases exceed the concurrency limit, the larger the baseline excess quantity, and the lower the admission confidence level. This allows multiple excess requests to distribute the limited predicted capacity according to their confidence levels, rather than accepting or rejecting all of them.
[0074] like Then, based on probability Admission is permitted; otherwise, strict rejection is required. This is the minimum admission confidence threshold, used to control the proportion of controlled releases under full load conditions. For example, a threshold of 0.6 is used. The higher the minimum admission confidence threshold, the more conservative the controlled admissions. The shared predicted quota is used in the calculation of the above admission confidence. This can prevent multiple gateway nodes from repeatedly overdrawing the same expected future release capacity.
[0075] Step 104: Based on the reliability of the release of the expiring leases, reduce the number of expiring leases in the prediction window to obtain the corrected expected release capacity.
[0076] Requests corresponding to leases expiring within the forecast window are still running. Some of these requests have already reached their preset lease duration and may initiate renewals to continue occupying slots, potentially preventing timely release upon expiration. Treating all expiring leases within the forecast window as upcoming capacity could overestimate the actual release capacity, leading to over-release at the concurrency limit. Therefore, the number of expiring leases within the forecast window is reduced based on the reliability of their release.
[0077] The reliability of release is jointly reflected by whether the request corresponding to the expiring lease has entered the renewal trigger period and the historical on-time release reliability of the upstream service. Leases that have entered the renewal trigger period are more likely to be renewed, have lower release reliability, and experience greater reduction. Leases that have not entered the renewal trigger period have higher release reliability and experience less reduction. The specific reduction method will be explained in the subsequent optional embodiments. The historical on-time release reliability can be determined based on the proportion of expiring leases that are actually released on time within the historical prediction window, for example, a value between 0.6 and 0.95.
[0078] As an optional embodiment, in step 104, the number of expiring leases within the prediction window is reduced according to the release reliability of the expiring leases to obtain the revised estimated release capacity. This includes: determining the ratio of the runtime of the request corresponding to each expiring lease to the preset lease duration; classifying leases whose ratio reaches a preset renewal trigger ratio as leases that have entered the renewal trigger interval, and classifying leases whose ratio does not reach the preset renewal trigger ratio as leases that have not entered the renewal trigger interval; multiplying the number of leases that have not entered the renewal trigger interval by a first release weight to obtain a first weighted lease number; multiplying the number of leases that have entered the renewal trigger interval by a second release weight to obtain a second weighted lease number; adding the first weighted lease number and the second weighted lease number, and multiplying the result by the historical on-time release reliability to obtain the revised estimated release capacity.
[0079] Determine the ratio of the runtime of the request corresponding to each expiring lease to the preset lease duration. The preset lease duration is the default duration from when the lease is written to its expiration, for example, 125,000 milliseconds. The runtime is the continuous running time of the corresponding request since it was accepted. Leases whose ratio reaches the preset renewal trigger ratio are classified as leases that have entered the renewal trigger interval. The preset renewal trigger ratio can be 0.8. Leases whose ratio does not reach the preset renewal trigger ratio are classified as leases that have not entered the renewal trigger interval.
[0080] The number of leases not yet in the renewal trigger zone is multiplied by the first release weight to obtain the first weighted lease number. The number of leases already in the renewal trigger zone is multiplied by the second release weight to obtain the second weighted lease number. A second release weight less than the first release weight indicates that leases already in the renewal trigger zone should not be fully considered as being released on time. For example, the first release weight could be 1.0, and the second release weight could be 0.4.
[0081] Add the first weighted lease number to the second weighted lease number to obtain the total weighted lease number. Multiply the total weighted lease number by the historical on-time release reliability to obtain the revised estimated release capacity.
[0082] For example, if the prediction window is 2000 milliseconds, and the number of expiring leases within the prediction window is 5, of which 3 have not yet entered the renewal trigger period and 2 have entered the renewal trigger period, the first release weight is 1.0, the second release weight is 0.4, and the historical on-time release reliability is 0.85, then the corrected estimated release capacity is 0.85 multiplied by (3 multiplied by 1.0 plus 2 multiplied by 0.4), which is 3.23. The above values are for illustrative purposes only and do not constitute a limitation on the embodiments of this application.
[0083] Step 105: Determine the shared predicted admission quota available for the current request based on the difference between the revised expected release capacity and the predicted quota already occupied by other requesting access nodes.
[0084] The revised projected releaseable capacity represents the capacity expected to be released within the future forecast window, which is shared by multiple requesting access nodes. If each requesting access node directly performs over-admission based on the revised projected releaseable capacity, multiple requesting access nodes may reuse the same future release capacity, causing actual overload. Therefore, a shared projected admission quota is set, and each requesting access node completes quota checking and deduction in the same atomic operation. The projected quota already occupied by other requesting access nodes represents the portion that other requesting access nodes have pre-drawn.
[0085] The shared predicted admission quota is the difference between the revised estimated release capacity and the predicted quota already occupied by other requesting access nodes. When the revised estimated release capacity is less than the already occupied predicted quota, the shared predicted admission quota is set to zero, and over-admission is no longer allowed. The specific calculation method is explained in the subsequent optional embodiments.
[0086] As an optional embodiment, in step 105, determining the currently available shared predicted access quota based on the difference between the revised estimated releaseable capacity and the predicted quota already occupied by other requesting access nodes includes: rounding down the revised estimated releaseable capacity to obtain the allocatable predicted capacity; determining the difference between the allocatable predicted capacity and the predicted quota already occupied by other requesting access nodes as the shared predicted access quota, wherein the shared predicted access quota is not less than zero; and after the prediction window ends, verifying and calibrating the shared predicted access quota based on the number of leases actually released within the prediction window.
[0087] The revised projected release capacity is rounded down to obtain the allocable projected capacity. Rounding is used because concurrent slots are in integer units. The allocable projected capacity is subtracted from the projected quota already occupied by other requesting nodes; the difference is determined as the shared projected admission quota. If the difference is negative, the shared projected admission quota is set to zero.
[0088] After the forecast window ends, the number of leases actually released on time within the forecast window is tallied. The actual release quantity is compared with the pre-drawn quota within the forecast window, and the shared forecast access quota is written off and calibrated. For example, if the actual release quantity exceeds the pre-drawn quota, the remaining quota is written off. If the actual release quantity is lower than the pre-drawn quota, the quota allocation for subsequent forecast windows is adjusted based on the difference to ensure that subsequent forecasts closely approximate the actual release situation.
[0089] Step 106: If the current number of leases in the ordered set reaches the concurrency limit, determine the admission confidence of the current request based on the shared predicted admission quota and the excess amount by which the current number of leases exceeds the concurrency limit.
[0090] The current number of leases is the number of currently valid leases in the ordered set. When the current number of leases has not reached the concurrency limit, requests can be accepted directly without calculating the admission confidence level. When the current number of leases has reached the concurrency limit, requests should be rejected directly in the traditional way. However, at this time, there may be slots about to be released within the prediction window, and controlled admission can be implemented based on the shared prediction admission quota.
[0091] Admission confidence indicates the reliability of accepting a current request under full load conditions, and is determined based on the shared predicted admission quota and the excess amount of the current number of leases exceeding the concurrency limit. The excess amount reflects the scale of demand waiting for admission under full load conditions. The specific calculation method is explained in the subsequent optional embodiments.
[0092] As an optional embodiment, in step 106, determining the admission confidence level of the current request based on the shared predicted admission quota and the excess amount by which the current number of leases exceeds the concurrency limit includes: determining the admission confidence level as the ratio of the shared predicted admission quota to the baseline excess amount, wherein the admission confidence level does not exceed 1; wherein the baseline excess amount is the difference between the current number of leases and the concurrency limit plus one, and the baseline excess amount is at least 1; when the admission confidence level reaches the preset minimum admission confidence level threshold, accepting the current request with probability based on the admission confidence level.
[0093] The baseline excess amount is the difference between the current number of leases and the concurrency limit, plus one, and is at least 1. When the current number of leases is exactly equal to the concurrency limit, the difference plus one is 1, indicating that the current request itself constitutes an excess request. The ratio of the shared predicted admission limit to the baseline excess amount is determined as the admission confidence level; a ratio exceeding 1 is counted as 1, meaning the admission confidence level does not exceed 1.
[0094] When the admission confidence level reaches a preset minimum admission confidence threshold, the current request is accepted with probability based on the admission confidence level. The preset minimum admission confidence threshold can be a value between 0.5 and 0.8. For example, if the concurrency limit is 64, the current number of leases is 64, the shared predicted admission limit is 3, and the baseline excess amount is 1, then the admission confidence level is 1, reaching the minimum admission confidence threshold, and the current request is accepted with probability 1. Accepting requests with probability based on admission confidence level allows multiple excess requests to distribute the limited predicted capacity according to their confidence levels, rather than accepting or rejecting all of them.
[0095] Step 107: If the number of current leases has not reached the concurrency limit, or if the number of current leases has reached the concurrency limit and the admission confidence level has reached the preset minimum admission confidence level threshold, then the current request is accepted, and the lease corresponding to the current request is written into the ordered set. Otherwise, the current request is rejected.
[0096] Accepting the current request means scheduling the request to the target upstream service for processing and reserving concurrent slots for it. If the current number of leases has not reached the concurrency limit, it means there are currently free slots, and the current request is accepted directly. If the current number of leases reaches the concurrency limit and the admission confidence level reaches the preset minimum admission confidence threshold, it means there is sufficient reliable expected release capacity within the future prediction window, and the current request is accepted in a controlled manner.
[0097] When a current request is accepted, the lease corresponding to the current request is written into an ordered set. The write operation is completed in the same atomic operation as the aforementioned cleanup, statistics, and quota deduction. When multiple request access nodes concurrently execute the occupancy request, the same predicted capacity will not be occupied repeatedly.
[0098] The score of the written lease is the sum of the current time and the preset lease duration.
[0099] The score of the written lease is the sum of the current time and the preset lease duration, indicating that the lease expires after the preset lease duration from the time of writing. The preset lease duration is, for example, 125000 milliseconds. When the current request is rejected, a rejection result is returned. The requesting access node can try the next candidate upstream according to the candidate sorting. If no available candidate upstream is found, the current scheduling ends. When rejected, the lease corresponding to the current request is not written to the ordered set, and the ordered set remains unchanged.
[0100] As an optional embodiment, in step 107, after writing the lease corresponding to the current request into the ordered set, the method further includes: receiving a renewal request for the target lease already written into the ordered set; if the number of current leases in the ordered set has not reached the concurrency limit, and the target lease has not reached any of the upper limits of single renewal duration, cumulative renewal times, and total lease lifecycle, then if the ratio of the runtime of the request corresponding to the target lease to the preset lease duration reaches the preset renewal trigger ratio, or the preset lease duration of the request corresponding to the target lease reaches the preset renewal trigger ratio, the method further includes: receiving a renewal request for the target lease; if the number of current leases in the ordered set has not reached the concurrency limit, and the target lease has not reached the upper limit of any of the upper limits of single renewal duration, cumulative renewal times, and total lease lifecycle, then the method further includes: receiving a renewal request for the target lease; if the number of current leases in the ordered set has not reached the concurrency limit, and the number of current leases in the ordered set has not reached the concurrency limit ... If the remaining execution time is greater than the remaining lease time, the score of the target lease is updated to the sum of the current time and the preset lease duration. If the number of current leases in the ordered set reaches the concurrency limit, or the target lease reaches any one of the upper limits of the single renewal duration, the cumulative renewal count, and the total lease lifecycle, the score of the target lease is not updated, and the request corresponding to the target lease is allowed to continue to be executed until completion. The target lease is no longer included in the concurrency placeholder statistics, and no release notification is triggered when the request corresponding to the target lease is completed.
[0101] Long-running requests may have leases that expire before completion. Once a lease expires and is cleared, the request is considered no longer occupying a slot, which may be inconsistent with the actual running status. Therefore, leases nearing expiration are allowed to be renewed. Provided the current number of leases has not reached the concurrency limit and this renewal does not violate the aforementioned limit constraints, the renewal trigger condition must meet at least one of the following: the ratio of the runtime of the request corresponding to the target lease to the preset lease duration reaches a preset renewal trigger ratio, such as 0.8; or the predicted remaining execution time of the request corresponding to the target lease is greater than the remaining lease time, meaning that according to the predicted remaining execution time, the request cannot be completed before the lease expires. If neither the renewal trigger condition nor the rejection of renewal condition is met, the score of the target lease remains unchanged.
[0102] Upon renewal, the target lease's score is updated to the sum of the current time and the preset lease duration, effectively resetting the lease expiration time to the time after the preset lease duration from the current time. To prevent unlimited reuse of renewals, the target lease is constrained by a single renewal duration limit, a cumulative renewal count limit, and a total lease lifetime limit. Before updating the score, it checks whether the current renewal duration exceeds the single renewal duration limit, whether the cumulative renewal count after this renewal exceeds the cumulative renewal count limit, and whether the difference between the updated lease expiration time and the initial write time exceeds the total lease lifetime limit. The total lease lifetime limit is, for example, between 180,000 milliseconds and 300,000 milliseconds.
[0103] If the current number of leases in the ordered set reaches the concurrency limit, or if this renewal violates any of the aforementioned limit constraints, the score of the target lease will be refused to be updated regardless of whether the renewal trigger condition is met, and the system will enter timeout protection mode. The request corresponding to the target lease will be allowed to continue until completion, and the target lease will not be deleted. However, the target lease will no longer participate in the concurrency placeholder statistics, and a release notification will not be triggered when the request corresponding to the target lease completes. This avoids directly interrupting the request due to renewal rejection and limits the lease's continued occupancy time.
[0104] For example, the conditions for renewing a visa can be expressed using the following formula:
[0105] The above formula is used to determine whether the renewal trigger conditions have been met. The actual update also requires that the current number of leases has not reached the concurrent limit and that this renewal does not violate the aforementioned limit constraints. Among these, This is the runtime of the request, which is the time that the request corresponding to the target lease has been running continuously since it was accepted, and it increases in real time as the request runs. The preset lease duration is the default time from when the lease is written until its expiration, defined by the configuration of the target upstream service, for example, 125 seconds. If the preset lease duration is too long, abnormally leftover leases will not be reclaimed in a timely manner. If the preset lease duration is too short, long-running requests will frequently renew. The preset lease duration can be determined based on the typical request processing time of the upstream service. α is the preset renewal trigger ratio, for example, 0.8, which can be determined based on the typical request duration distribution of the target upstream service. For the remaining lease term, To predict the remaining execution time, the remaining execution time can be determined based on the historical execution time statistics or execution progress of the request.
[0106] In addition, the target lease is also subject to a single renewal duration limit and a cumulative renewal count limit. The single renewal duration limit is the maximum extension allowed for the lease expiration date after the update relative to the lease expiration date before the update. The cumulative renewal count limit is the maximum number of times the same lease can be renewed. Together with the total lease lifetime limit, these two constitute a triple constraint on the same lease, which can be determined based on the upstream service's tolerance for long-term occupation of concurrent slots.
[0107] When renewal is permitted, the updated total lease lifetime must satisfy: ;in, This is the difference between the expiry date of the renewed lease and the initial write date of the target lease. This represents the maximum total lease lifetime, for example, 240 seconds. The maximum total lease lifetime limits the cumulative renewal scale of the same lease and can be determined based on the maximum processing time per transaction of the upstream service.
[0108] The pre-inspection start time can be expressed by the following formula: ;in, The next slot release time is predicted based on the current distribution of expiring scores. For the historical round-trip time of the candidate upstream, Pre-inspection processing takes time. To prevent fluctuations in the actual release time, a safety buffer period is set, for example, 12 milliseconds. This safety buffer period can be determined based on the historical deviation between the actual release time and the expected release time; the larger the deviation, the longer the safety buffer period. If the pre-detection result expires, the target candidate state changes, or the deviation between the actual release time and the expected release time exceeds a preset range, the pre-detection result is discarded and recalculated.
[0109] in, The next slot release time, predicted based on the current expiration score distribution, is the expiration time of the lease with the smallest score in the ordered set after clearing the expiring leases. This can be updated as the score distribution changes after each clearing operation. The historical round-trip latency of candidate upstream services can be obtained from the latency statistics of each upstream service in the latency baseline pool. For example, the average round-trip time of historical requests of candidate upstream services can be taken, with a value ranging from 5 milliseconds to 100 milliseconds, and can be updated on a rolling basis with new round-trip latency samples. The time consumed for pre-detection processing, i.e. the time required to perform a pre-detection on a candidate upstream, can be determined based on the time consumption statistics of historical pre-detection operations, for example, from 5 milliseconds to 50 milliseconds.
[0110] Step 108: After the current request is processed, delete the lease corresponding to the current request in the ordered set and release the concurrent slot occupied by the current request.
[0111] Once the current request is processed, the concurrent slot it occupies can be released. The lease corresponding to the current request is removed from the ordered set. After deletion, the lease is no longer counted in the current lease count, and the corresponding slot becomes available for subsequent requests. The deletion operation, like the write operation, is performed within an atomic operation.
[0112] As an optional embodiment, in step 108, before deleting the lease corresponding to the current request in the ordered set after the current request processing is completed, the method further includes: determining the expected release time of the next slot based on the score distribution of each lease in the ordered set; determining the pre-detection start time based on the expected release time, the historical round-trip delay of the candidate upstream, the pre-detection processing time, and the safety buffer time, wherein the pre-detection start time is the difference between the expected release time and the sum of the historical round-trip delay, the pre-detection processing time, and the safety buffer time; at the pre-detection start time, A pre-check is performed on the upstream candidate target, and the pre-check result is cached in the local ready queue. The pre-check result includes candidate reachability, the most recent authentication or quota pre-check conclusion, candidate sorting context, and the validity period of the pre-check result. When the slot is released, if the pre-check result has not exceeded the validity period and the state of the upstream candidate target has not changed, the pre-check result is directly reused. If the state of the upstream candidate target changes, the pre-check result exceeds the validity period, or the deviation between the actual release time and the expected release time exceeds a preset range, the pre-check result becomes invalid and the pre-check is re-executed.
[0113] After a slot is released, waiting requests are awakened and admission checks are re-executed. There is a waiting gap between release and the start of processing of new requests. To shorten this gap, the expected release time of the next slot can be predicted in advance based on the score distribution of each lease in the ordered set. The score represents the lease's expiration time, and the score closest to the current time corresponds to the earliest expiring lease, whose expiration time is the expected release time of the next slot.
[0114] Determine the pre-check start time. The pre-check start time is the difference between the expected release time and the sum of historical round-trip time, pre-check processing time, and safety buffer time. In other words, it's calculated by working backward from the expected release time backward from the historical round-trip time, pre-check processing time, and safety buffer time. The historical round-trip time of the candidate upstream is the average round-trip time of historical requests for that candidate upstream, for example, 5 milliseconds to 100 milliseconds. The pre-check processing time is the time required to perform one pre-check, for example, 5 milliseconds to 50 milliseconds. The safety buffer time is used to absorb the jitter between the actual release time and the expected release time, for example, 5 milliseconds to 30 milliseconds.
[0115] At the start of the pre-screening process, a pre-screening is performed on the upstream of the target candidate, and the pre-screening results are cached in the local ready queue. The pre-screening results include candidate reachability, the most recent authentication or quota pre-screening conclusion, candidate ranking context, and the validity period of the pre-screening results, which is, for example, 100 milliseconds to 1000 milliseconds. The pre-screening content is consistent with the checks performed before formal admission, so that the pre-screening results can be directly reused during formal admission.
[0116] When releasing a slot, if the pre-inspection result has not expired and the status of the target candidate upstream has not changed, the pre-inspection result is directly reused, and the next concurrent slot occupancy request is initiated for the target candidate upstream, eliminating the pre-inspection waiting after release. If the status of the target candidate upstream changes, the pre-inspection result expires, or the deviation between the actual release time and the expected release time exceeds a preset range, the pre-inspection result becomes invalid, and the pre-inspection is re-executed.
[0117] For example, based on the score distribution, the next slot is predicted to be released at time t. The historical round-trip latency of a candidate upstream is 18 milliseconds, the pre-detection processing time is 20 milliseconds, and the safety buffer time is 12 milliseconds. Therefore, the pre-detection start time is t minus 50 milliseconds. The pre-detection is performed on the candidate upstream in advance at the pre-detection start time, and the results are cached. If the candidate state has not changed and the cache has not expired when the slot is actually released, the pre-detection results are directly reused. The above values are for illustrative purposes only and do not constitute a limitation on the embodiments of this application.
[0118] In this embodiment, the complete management and scheduling execution process of leased semaphores based on a token gateway is as follows: Taking the access of a large language model service through a token gateway as an example, after a client request arrives at the token gateway, the token gateway prefetches the configuration and real-time status of candidate upstream services in batches, performs hard filtering and scoring sorting, and selects the target upstream service. A concurrent slot occupancy request is initiated for the target upstream service, and within the same atomic operation, the following steps are completed sequentially: expired lease cleanup, cleanup quantity acquisition, expired lease statistics within the prediction window, current lease count judgment, shared prediction admission quota check and deduction, and lease writing. Requests are accepted directly when the current lease count has not reached the concurrency limit. When the concurrency limit is reached, controlled acceptance or rejection is performed according to the admission confidence level; if rejected, the next candidate upstream is tried. Node anomaly judgment is performed based on the number of expired leases obtained from each cleanup. If an anomaly is detected, the concurrency limit is reduced; if no anomalies are observed during the observation period, it is gradually restored. When the request execution time is close to the lease expiration time, renewal is performed; if renewal fails, a timeout protection mode is entered. After the request is processed, the corresponding lease release slot is deleted, and the release time of the next slot is predicted based on the score distribution. Pre-check is performed in advance and the results are cached. When the slot is released, the pre-check results that have not expired are directly reused.
[0119] Taking the token gateway accessing the large language model service as an example, through the above process, the admission judgment tends to be consistent with the actual available capacity, the batch rejection and repeated retries when approaching the concurrency limit are reduced, and processing resources are continuously utilized. Leaving leases due to node anomalies can be identified, and the concurrency limit is automatically adjusted without the need to deploy an external watchdog component. Long-running requests are prevented from being mistakenly reclaimed through renewal. The waiting interval after slot release is shortened. The execution order of the above steps is for illustrative purposes only; in actual implementation, some steps may be adjusted in order or combined.
[0120] The above describes a token gateway-based lease semaphore management method in the embodiments of this application. The following describes the token gateway-based lease semaphore management device (e.g., a server) that performs the above-described token gateway-based lease semaphore management method.
[0121] See Figure 4 ,like Figure 4 The diagram illustrates a token gateway-based leased semaphore management device, which can be applied to distributed high-concurrency service request access scenarios. For example, it can be deployed on a gateway node to manage the occupancy, release, and scheduling of concurrent slots for the target upstream service. The token gateway-based leased semaphore management device in this embodiment can achieve the corresponding functionality described above. Figure 2 The steps of the token gateway-based lease semaphore management method executed in the corresponding embodiments are described above. The functions implemented by the token gateway-based lease semaphore management device can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions, and these modules can be software and / or hardware. The token gateway-based lease semaphore management device may include an input / output module 601 and a processing module 602. The functional implementation of the processing module 602 and the input / output module 601 can be found in [reference missing]. Figure 2 The operations performed in the corresponding embodiments will not be described in detail here. For example, the processing module 602 can be used to control the sending, receiving, and acquiring operations of the input / output module 601.
[0122] The input / output module 601 is configured to acquire concurrent slot occupancy requests for the target upstream service; receive renewal requests for the target lease already written into the ordered set; and output the result of accepting or rejecting the current request.
[0123] The processing module 602 is configured to, in response to the concurrent slot occupancy request, clear expired leases in the ordered set corresponding to the target upstream service to obtain the number of expired leases cleared in this cleanup; count the number of expired leases within a future preset prediction window; determine the corrected expected release capacity, shared prediction admission quota, and admission confidence level; write the lease corresponding to the current request into the ordered set upon acceptance; and delete the corresponding lease after the current request is processed.
[0124] In some implementations, the processing module 602 is further configured to: perform an exponential moving average based on the number of expired leases corresponding to the current request and previous requests to the target upstream service, using a preset smoothing factor, to obtain the average number of sliding window cleanups; determine the ratio of the average number of sliding window cleanups to the concurrency limit as the unit capacity cleanup ratio; determine whether the requesting access node is abnormal based on the average number of sliding window cleanups, the unit capacity cleanup ratio, the consecutive abnormal window count, the lease source clustering degree, and the expiration time clustering degree; reduce the concurrency limit when a node abnormality is determined to have occurred, and gradually restore the concurrency limit if no abnormality is determined to have occurred again within a preset observation window.
[0125] In some implementations, the processing module 602 is further configured to: determine the ratio of the runtime of the requests corresponding to each of the expiring leases to the preset lease duration; divide the leases that have entered the renewal trigger interval into leases that have not entered the renewal trigger interval according to the comparison result of the ratio and the preset renewal trigger ratio; weight the leases according to the second release weight and the first release weight respectively, and multiply them by the historical on-time release reliability to obtain the corrected expected release capacity; round down the corrected expected release capacity and subtract it from the predicted quota that has been occupied by other requesting access nodes to determine the shared predicted access quota; and determine the ratio of the shared predicted access quota to the baseline excess quantity as the access confidence level.
[0126] In some implementations, the processing module 602 is further configured to: update the score of the target lease when the ratio of the runtime of the request corresponding to the target lease to the preset lease duration reaches the preset renewal trigger ratio, or when the predicted remaining execution time is greater than the remaining lease time; allow the request corresponding to the target lease to continue execution until completion when the update is rejected, and the target lease no longer participates in the concurrent placeholder statistics; determine the expected release time of the next slot according to the score distribution of each lease in the ordered set, determine the pre-check start time according to the expected release time, control the input / output module 601 to perform pre-check on the upstream of the target candidate at the pre-check start time, and reuse the unexpired pre-check results when the slot is released.
[0127] In this embodiment, the processing module 602 cleans up the expiring leases in the ordered set and counts the number of expiring leases in the prediction window. It then reduces the predicted release capacity by the release reliability and determines the admission confidence level by combining the shared prediction admission quota. This allows the system to accept requests in a controlled manner based on the admission confidence level when the concurrency limit is approached, making the admission judgment consistent with the actual available capacity, reducing batch rejections and repeated retries, and ensuring continuous utilization of processing resources.
[0128] The above describes the token gateway-based lease semaphore management device in this application embodiment from the perspective of modular functional entities. The following describes the token gateway-based lease semaphore management device in this application embodiment from the perspective of hardware processing.
[0129] It should be noted that, Figure 4 The physical device corresponding to the input / output module 601 shown can be a transceiver, radio frequency circuit, communication module, and input / output (I / O) interface, etc., and the physical device corresponding to the processing module 602 can be a processor.
[0130] Figure 4 The devices shown can all have the following characteristics: Figure 5 The structure shown, when Figure 4 The token-based gateway-based leased semaphore management device shown has the following characteristics: Figure 5 When the structure shown is used, Figure 5 The processor and transceiver in the device can perform the same or similar functions as the processing module 602 and input / output module 601 provided in the aforementioned device embodiments. Figure 5 The memory storage processor in the memory needs to call the computer program when executing the above-mentioned token-based lease semaphore management method.
[0131] This application also relates to a chip system including at least one processor and an interface circuit. The processor includes a plurality of vector storage units. The processor is used to perform instruction and / or data interaction through the interface circuit, causing the chip system to perform the methods of any of the above embodiments.
[0132] In one possible implementation, the chip system may also directly include a memory in which computer programs or computer instructions are stored.
[0133] For example, the memory can be volatile memory or non-volatile memory, or may include both. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which serves as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DRRAM).
[0134] This application also relates to a processor, which includes a plurality of storage units for calling computer programs or computer instructions stored in the memory to cause the processor to execute the methods described in any of the above embodiments.
[0135] For example, in the embodiments of this application, the processor is an integrated circuit chip with signal processing capabilities. For instance, the processor may be an FPGA, a general-purpose processor, a DSP, an ASIC, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, a SoC, a CPU, a network processor (NP), a microcontroller unit (MCU), a PLD, or other integrated chips, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this application. In one possible implementation, the embodiments of this application also provide a computer-readable storage medium storing program code, which, when executed on the computer, causes the computer to perform the above-described method embodiments.
[0136] This application also provides a server; please refer to [link / reference]. Figure 6 , Figure 6 This is a schematic diagram of a server structure provided in an embodiment of this application. The server 1100 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 1122 (e.g., one or more processors) and memory 1132, and one or more storage media 1130 (e.g., one or more mass storage devices) for storing application programs 1142 or data 1144. The memory 1132 and storage media 1130 can be temporary or persistent storage. The program stored in the storage media 1130 may include one or more modules (not shown in the figure), each module may include a series of instruction operations on the server. Furthermore, the CPU 1122 may be configured to communicate with the storage media 1130 and execute the series of instruction operations in the storage media 1130 on the server 1100.
[0137] Server 1100 may also include one or more power supplies 1126, one or more wired or wireless network interfaces 1150, one or more input / output interfaces 1158, and / or one or more operating systems 1141, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. The steps performed by the server in the above embodiments can be based on this... Figure 6 The structure of server 1100 is shown. For example, the steps performed by the token-based gateway-based leased semaphore management device in the above embodiment can be based on this. Figure 6 The server architecture is shown. For example, the central processing unit 1122 performs the following operations by calling instructions from memory 1132: The concurrent slot occupancy requests for the target upstream service can be obtained through the input / output interface 1158, and the result of accepting or rejecting the current request can be output. In response to the concurrent slot occupancy request, the system can also clean up expired leases in the ordered set corresponding to the target upstream service to obtain the number of expired leases cleaned up. The members of the ordered set are lease identifiers, and the scores of the members represent lease expiration times. The system then counts the expired leases in the ordered set whose expiration times fall within a future preset prediction window to obtain the number of expired leases within the prediction window. Based on the reliability of the release of the expired leases, the number of expired leases within the prediction window is reduced to obtain a corrected estimated release capacity. Based on the difference between the corrected estimated release capacity and the predicted quota already occupied by other requesting access nodes, the shared predicted admission quota available to the current request is determined. In the ordered set… If the current number of leases reaches the concurrency limit, the admission confidence level of the current request is determined based on the shared predicted admission quota and the excess amount of the current number of leases exceeding the concurrency limit. If the current number of leases does not reach the concurrency limit, or if the current number of leases reaches the concurrency limit and the admission confidence level reaches the preset minimum admission confidence threshold, the current request is accepted, and the lease corresponding to the current request is written into the ordered set. Otherwise, the current request is rejected. The score of the written lease is the sum of the current time and the preset lease duration. After the current request is processed, the lease corresponding to the current request is deleted from the ordered set, and the concurrent slot occupied by the current request is released.
[0138] 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.
[0139] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and modules described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0140] In the embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, apparatuses, or modules, and may be electrical, mechanical, or other forms.
[0141] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0142] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium.
[0143] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0144] The computer program product includes one or more computer instructions. When the computer program is loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., a solid-state disk (SSD)).
[0145] The technical solutions provided in the embodiments of this application have been described in detail above. Specific examples have been used in the embodiments of this application to illustrate the principles and implementation methods of the embodiments of this application. The description of the above embodiments is only for the purpose of helping to understand the methods and core ideas of the embodiments of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the embodiments of this application. Therefore, the content of this specification should not be construed as a limitation on the embodiments of this application.
Claims
1. A method for managing leased semaphores based on a token gateway, characterized in that, The method includes: Obtain concurrent slot occupancy requests for the target upstream service; In response to the concurrent slot occupancy request, expired leases are cleared from the ordered set corresponding to the target upstream service to obtain the number of expired leases cleared in this cleanup. The members of the ordered set are lease identifiers, and the score of the members is the lease expiration time. The number of expiring leases in the ordered set whose expiration dates fall within a preset future prediction window is obtained. Based on the reliability of the release of the expiring leases, the number of expiring leases within the prediction window is reduced to obtain the revised expected release capacity; The shared predicted admission quota available for the current request is determined based on the difference between the revised expected release capacity and the predicted quota already occupied by other requesting access nodes. When the number of current leases in the ordered set reaches the concurrency limit, the admission confidence of the current request is determined based on the shared predicted admission quota and the excess amount by which the number of current leases exceeds the concurrency limit. If the number of current leases does not reach the concurrency limit, or if the number of current leases reaches the concurrency limit and the admission confidence level reaches the preset minimum admission confidence level threshold, then the current request is accepted and the lease corresponding to the current request is written into the ordered set; otherwise, the current request is rejected; wherein, the score of the written lease is the sum of the current time and the preset lease duration; After the current request is processed, the lease corresponding to the current request is deleted from the ordered set, and the concurrent slot occupied by the current request is released.
2. The method according to claim 1, characterized in that, The step of reducing the number of expiring leases within the prediction window based on the reliability of the release of the expiring leases to obtain the revised expected release capacity includes: Determine the ratio of the runtime of the request corresponding to each of the expired leases to the preset lease duration; Leases whose ratio reaches the preset renewal trigger ratio are classified as leases that have entered the renewal trigger range, and leases whose ratio does not reach the preset renewal trigger ratio are classified as leases that have not entered the renewal trigger range. Multiply the number of leases that have not entered the renewal trigger range by the first release weight to obtain the first weighted lease number; Multiply the number of leases that have entered the renewal trigger range by the second release weight to obtain the second weighted lease number; The first weighted lease number and the second weighted lease number are added together and then multiplied by the historical on-time release reliability to obtain the revised expected release capacity.
3. The method according to claim 1, characterized in that, The step of determining the shared predicted admission quota available for the current request based on the difference between the revised estimated releaseable capacity and the predicted quota already occupied by other requesting access nodes includes: The revised estimated release capacity is rounded down to obtain the allocatable predicted capacity; The difference between the allocatable predicted capacity and the predicted quota already occupied by other requesting access nodes is determined as the shared predicted access quota, and the shared predicted access quota is not less than zero. After the prediction window ends, the shared prediction access quota is revoked and calibrated based on the actual number of leases released within the prediction window.
4. The method according to claim 1, characterized in that, The step of determining the admission confidence level of the current request based on the shared predicted admission quota and the excess amount by which the current number of leases exceeds the concurrency limit includes: The ratio of the shared predicted admission quota to the benchmark excess amount is determined as the admission confidence level, and the admission confidence level does not exceed 1. Wherein, the benchmark excess quantity is the difference between the current number of leases and the concurrency limit plus one, and the benchmark excess quantity is at least 1; When the admission confidence level reaches the preset minimum admission confidence level threshold, the current request is accepted with probability based on the admission confidence level.
5. The method according to claim 1, characterized in that, After clearing expired leases from the ordered set corresponding to the target upstream service to obtain the number of expired leases cleared in this cleanup, the process further includes: Based on the number of expired leases corresponding to this request and previous requests to the target upstream service, an exponential moving average is performed using a preset smoothing factor to obtain the average number of clean-up windows. The ratio of the average number of cleanups per sliding window to the maximum concurrency limit is determined as the cleanup ratio per unit capacity.
6. The method according to claim 5, characterized in that, After determining the ratio of the average number of cleanups per sliding window to the maximum concurrency as the cleanup ratio per unit capacity, the method further includes: Based on the average number of cleaned-up sliding windows, the clean-up ratio per unit capacity, the count of consecutive abnormal windows, the clustering degree of lease sources and the clustering degree of expiration time, it is determined whether the request access node corresponding to the target upstream service is abnormal. A node anomaly is determined to have occurred when the average number of cleanups in the sliding window exceeds the product of the baseline number of cleanups and a preset crash detection threshold multiple, and at least one of the unit capacity cleanup ratio, the number of consecutive abnormal windows, the lease source clustering degree, and the expiration time clustering degree exceeds the corresponding preset threshold. When a node anomaly is detected, the concurrency limit is reduced by a preset derating ratio, and the reduced concurrency limit is not lower than the preset minimum safe capacity. If no node anomaly is detected again within the preset observation window, the concurrency limit is gradually increased according to the preset recovery cycle and preset recovery step size. If a node anomaly is detected again during the process of increasing the concurrency limit, the increase is stopped, and the concurrency limit is reduced again according to the preset reduction ratio.
7. The method according to claim 1, characterized in that, After writing the lease corresponding to the current request into the ordered set, the method further includes: Receive renewal requests for target leases that have been written into the ordered set; If the current number of leases in the ordered set has not reached the concurrency limit, and the target lease has not reached any of the upper limits of single renewal duration, cumulative renewal times, and total lease lifecycle, then if the ratio of the runtime of the request corresponding to the target lease to the preset lease duration reaches the preset renewal trigger ratio, or the predicted remaining execution time of the request corresponding to the target lease is greater than the remaining lease time, then the score of the target lease will be updated to the sum of the current time and the preset lease duration. When the number of current leases in the ordered set reaches the concurrency limit, or when the target lease reaches any of the upper limits of the single renewal duration, the cumulative renewal count, and the total lease lifecycle, the score of the target lease is not updated, the request corresponding to the target lease is allowed to continue to be executed until completion, the target lease is no longer included in the concurrency placeholder statistics, and no release notification is triggered when the request corresponding to the target lease is completed.
8. The method according to claim 1, characterized in that, Before deleting the lease corresponding to the current request in the ordered set after the current request has been processed, the process further includes: Based on the fractional distribution of each lease in the ordered set, determine the expected release time of the next slot; Based on the expected release time, the historical round-trip time of the candidate upstream, the pre-detection processing time, and the safety buffer time, the pre-detection start time is determined. The pre-detection start time is the difference between the expected release time and the sum of the historical round-trip time, the pre-detection processing time, and the safety buffer time. At the time of the pre-inspection initiation, a pre-inspection is performed on the upstream of the target candidate, and the pre-inspection results are cached in the local ready queue. The pre-inspection results include candidate reachability, the most recent authentication or quota pre-inspection conclusion, candidate sorting context, and the validity period of the pre-inspection results. When a slot is released, if the pre-inspection result has not exceeded the validity period and the state of the upstream of the target candidate has not changed, the pre-inspection result is directly reused. If the state of the upstream of the target candidate changes, the pre-detection result exceeds the validity period, or the deviation between the actual release time and the expected release time exceeds a preset range, the pre-detection result becomes invalid and the pre-detection is re-executed.
9. A leased semaphore management device based on a token gateway, characterized in that, The apparatus is used to perform the token-based gateway-based leased semaphore management method according to any one of claims 1-8, the apparatus comprising: The input / output module is configured to obtain concurrent slot occupancy requests for the target upstream service; The processing module is configured to respond to the concurrent slot occupancy request by clearing expired leases in the ordered set corresponding to the target upstream service, obtaining the number of expired leases to be cleared in this cleanup, where the members of the ordered set are lease identifiers and the scores of the members are lease expiration times; counting the expired leases in the ordered set whose expiration times fall within a future preset prediction window, obtaining the number of expired leases within the prediction window; reducing the number of expired leases within the prediction window according to the reliability of the release of the expired leases, obtaining a corrected estimated release capacity; determining the shared predicted admission quota available to the current request based on the difference between the corrected estimated release capacity and the predicted quota already occupied by other requesting access nodes; and in the ordered set... If the number of current leases in the set reaches the concurrency limit, the admission confidence of the current request is determined based on the shared predicted admission quota and the excess amount of the current leases exceeding the concurrency limit. If the number of current leases does not reach the concurrency limit, or if the number of current leases reaches the concurrency limit and the admission confidence reaches the preset minimum admission confidence threshold, the current request is accepted, and the lease corresponding to the current request is written into the ordered set. Otherwise, the current request is rejected. The score of the written lease is the sum of the current time and the preset lease duration. After the current request is processed, the lease corresponding to the current request is deleted from the ordered set, and the concurrent slot occupied by the current request is released.
10. A computing device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the token-based gateway lease semaphore management method according to any one of claims 1-8.
