Time slot-based namespace allocation method and device, equipment and storage medium

CN122204820BActive Publication Date: 2026-09-25HASHPOWER INTERNET (BEIJING) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202610677663.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-05-18
Publication Date
2026-09-25
Estimated Expiration
2046-05-18

AI Technical Summary

Technical Problem

现有命名空间分配方法为采用租户与命名空间静态一对一映射模式,即在租户注册时为其创建专属命名空间,该命名空间在租户全生命周期内独立占用且持续存在,导致命名空间数量随租户规模线性增长

Benefits of technology

[0015]由上述技术方案可知,本申请提供一种基于时间槽的命名空间分配方法、装置、设备及存储介质,本方案通过动态时间槽的周期粒度与注册时间戳动态计算目标时间槽的目标命名空间名称,并为目标命名空间名称分配目标命名空间,实现在多租户均对应目标时间槽时,可共享目标命名空间,打破了传统租户与命名空间一对一静态绑定的局限,避免一个租户独占一个命名空间且在集群中存在大量低活跃度租户时,产生较多僵尸命名空间的问题,大大减少了僵尸命名空间,提升资源利用率。且通过多租户共享命名空间,显著降低K8s集群中命名空间总数量,缓解集群存储压力与集群响应性能瓶颈;同时,基于安全数量阈值自动扩张周期粒度的机制,可在不新增命名空间的前提下支撑海量租户接入,保证大规模多租户场景下集群的响应效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122204820B_ABST
    Figure CN122204820B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a time slot-based namespace allocation method and device, equipment and a storage medium, the method comprising: obtaining a period granularity of a dynamic time slot, a tenant account of a tenant and a registration timestamp, processing the registration timestamp and the period granularity to obtain a target namespace name of a target time slot; finding the target namespace name from a shared namespace set, if the target namespace name is not found, counting a total number of namespace names in the shared namespace set; if a sum of the total number and 1 is greater than a security number threshold, processing the sum, the security number threshold and the period granularity to obtain an expanded period granularity, and obtaining a new target namespace name based on the expanded period granularity, if the new target namespace name is found from the shared namespace set, constructing a mapping relationship between the new target namespace name and the tenant account. The time slot is used to realize multi-tenant shared namespace, and the utilization rate of cluster resources is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of resource management technology, specifically to a namespace allocation method, apparatus, device, and storage medium based on time slots. Background Technology

[0002] Kubernetes (K8S), as a mainstream container orchestration platform, uses namespaces as a core resource object for achieving multi-tenant isolation. It is widely used in multi-tenant SaaS platform architectures to isolate resources, permissions, and network policies among tenants. Current namespace allocation methods employ a static one-to-one mapping between tenants and namespaces. This means that a dedicated namespace is created for each tenant upon registration, and this namespace is independently occupied and persists throughout the tenant's lifecycle, leading to a linear increase in the number of namespaces with the size of the tenant base. However, a single K8S cluster has a defined upper limit on the number of namespaces. Excessive namespaces significantly increase cluster storage pressure and degrade cluster response performance. For example, cluster control plane queries require traversing all namespace metadata, causing cluster response latency to continuously worsen as the number of namespaces increases. Furthermore, a large number of inactive tenants monopolizing namespaces for extended periods result in extremely low cluster resource utilization and generate numerous zombie namespaces, making it difficult for the cluster to support ultra-large-scale multi-tenant access requirements. Summary of the Invention

[0003] To address the problems in the prior art, this application provides a time-slot-based namespace allocation method, apparatus, device, and storage medium, which can effectively improve the utilization rate of cluster resources while ensuring cluster response performance, and can effectively support the ultra-large-scale multi-tenant access requirements of the cluster.

[0004] To solve at least one of the above problems, this application provides the following technical solution: Firstly, this application provides a time-slot-based namespace allocation method, comprising: obtaining the periodic granularity of a dynamic time slot, the tenant's account, and the registration timestamp; calculating the registration timestamp and the periodic granularity using a namespace index formula to obtain the target namespace name of the target time slot; searching for the target namespace name in a shared namespace set; if not found, counting the total number of namespace names in the shared namespace set; if the sum of the total number and 1 is not greater than a safe number threshold, allocating a corresponding target namespace for the target namespace name; and constructing and storing a mapping relationship between the target namespace name and the tenant account to allocate the target namespace... The target namespace corresponding to the name is allocated to the tenant. If the sum of the total number and 1 is greater than the security number threshold, the periodic granularity adjustment formula is used to calculate the sum, the security number threshold, and the periodic granularity to obtain the expanded periodic granularity. The namespace index formula is then used to calculate the registration timestamp and the expanded periodic granularity to obtain the new target namespace name for the new target time slot. The new target namespace name is then searched from the shared namespace set. If found, the mapping relationship between the new target namespace name and the tenant account is constructed and stored, so that the tenant is one of the users of the namespace corresponding to the new target namespace name.

[0005] In some embodiments, the step of using a namespace index formula to calculate the registration timestamp and the periodic granularity to obtain the target namespace name of the target time slot includes: obtaining a preset base timestamp; calculating the difference between the registration timestamp and the preset base timestamp; calculating a first ratio of the difference to the periodic granularity, and rounding down the first ratio to obtain the time identifier of the target time slot, wherein the time length of the target time slot is equal to the periodic granularity; and concatenating the time identifier and the preset identifier to obtain the target namespace name of the target time slot.

[0006] In some embodiments, the method further includes: periodically counting the tenant set corresponding to each namespace name in the shared namespace set, determining the latest active time of the tenants in the tenant set, determining the latest retention time of the namespace name based on the latest active time of the tenants and the namespace retention grace period, and when the latest retention time is less than the current time, reclaiming the namespace corresponding to the namespace name and deleting the correspondence between the namespace name and the namespace from the shared namespace set.

[0007] In some embodiments, the calculation of the sum, the safety quantity threshold, and the periodic granularity using the periodic granularity adjustment formula to obtain the expanded periodic granularity includes: calculating a second ratio of the sum to the safety quantity threshold, rounding the second ratio up to obtain an integer ratio; and using the product of the integer ratio and the periodic granularity as the expanded periodic granularity.

[0008] In some embodiments, after calculating the sum, the security quantity threshold, and the periodic granularity using the periodic granularity adjustment formula to obtain the expanded periodic granularity, the method further includes: updating each namespace name in the shared namespace set and the namespace corresponding to each namespace name based on the expanded periodic granularity; for each updated namespace name in the updated shared namespace set, calculating the tenant activity rate corresponding to the updated namespace name; when the tenant activity rate is greater than a preset tenant activity rate, calculating the namespace retention grace period corresponding to the updated namespace name based on the standard namespace retention grace period, the tenant activity rate, and the preset tenant activity rate; when the tenant activity rate is less than the preset tenant activity rate, using the standard namespace retention grace period as the namespace retention grace period corresponding to the updated namespace name.

[0009] In some embodiments, the method further includes: periodically counting the total number of namespace names in the shared namespace set and counting the total number of tenants; calculating the total number and the total number of tenants using a reuse rate formula to obtain a namespace reuse rate; when the namespace reuse rate is lower than a preset reuse rate, calculating the minimum total number of namespace names based on the preset reuse rate and the total number of tenants; calculating the shortest period granularity based on the minimum total number, the current time, and a preset base timestamp; and updating each namespace name in the shared namespace set and the namespace corresponding to each namespace name based on the shortest period granularity.

[0010] In some embodiments, obtaining the period granularity of the dynamic time slot includes: calculating the maximum number of namespaces in real time based on the current time, a preset base timestamp, and the historical period granularity of the previous time; if the maximum number of namespaces is not greater than the security number threshold, then the historical period granularity is used as the period granularity of the dynamic time slot at the current time; if the maximum number of namespaces is greater than the security number threshold, then the period granularity of the dynamic time slot at the current time is calculated based on the security number threshold, the current time, and the preset base timestamp, and the period granularity is updated based on the period granularity to update the namespace names in the shared namespace set and the namespaces corresponding to each namespace name.

[0011] Secondly, this application provides a time-slot-based namespace allocation device, the device comprising: an acquisition unit, configured to acquire the periodic granularity of a dynamic time slot, the tenant's account, and a registration timestamp; and to calculate the registration timestamp and the periodic granularity using a namespace index formula to obtain the target namespace name of the target time slot; and an allocation unit, configured to search for the target namespace name in a shared namespace set; if not found, to count the total number of namespace names in the shared namespace set; if the sum of the total number and 1 is not greater than a safe number threshold, to allocate a corresponding target namespace to the target namespace name; and to construct and store a mapping relationship between the target namespace name and the tenant account, so as to allocate the target namespace name to the target namespace name. The target namespace corresponding to the namespace name is allocated to the tenant for use; the allocation unit is further configured to, if the sum of the total number and 1 is greater than the security number threshold, calculate the sum, the security number threshold and the periodic granularity using the periodic granularity adjustment formula to obtain the expanded periodic granularity, and calculate the registration timestamp and the expanded periodic granularity using the namespace index formula to obtain the new target namespace name of the new target time slot, and search for the new target namespace name from the shared namespace set. If found, a mapping relationship between the new target namespace name and the tenant account is constructed and stored so that the tenant is one of the users of the namespace corresponding to the new target namespace name.

[0012] Thirdly, this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the time-slot-based namespace allocation method.

[0013] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the time-slot-based namespace allocation method described above.

[0014] Fifthly, this application provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the time-slot-based namespace allocation method.

[0015] As can be seen from the above technical solutions, this application provides a time-slot-based namespace allocation method, apparatus, device, and storage medium. This solution dynamically calculates the target namespace name for the target time slot using the periodic granularity of the dynamic time slot and the registration timestamp, and allocates the target namespace name accordingly. This enables multiple tenants to share the target namespace when they all correspond to the target time slot, breaking the limitation of the traditional one-to-one static binding between tenants and namespaces. It avoids the problem of a large number of zombie namespaces generated when a tenant exclusively occupies a namespace and there are many inactive tenants in the cluster, significantly reducing zombie namespaces and improving resource utilization. Furthermore, by sharing namespaces among multiple tenants, the total number of namespaces in the K8s cluster is significantly reduced, alleviating cluster storage pressure and cluster response performance bottlenecks. Simultaneously, the mechanism of automatically expanding the periodic granularity based on a safe quantity threshold can support massive tenant access without adding new namespaces, ensuring the cluster's response efficiency in large-scale multi-tenant scenarios. Attached Figure Description

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

[0017] Figure 1 This is a flowchart illustrating the time-slot-based namespace allocation method in an embodiment of this application. Figure 2 This is a structural diagram of the time-slot-based namespace allocation system in the embodiments of this application; Figure 3 This is a structural diagram of the time-slot-based namespace allocation device in the embodiments of this application. Detailed Implementation

[0018] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0019] The acquisition, storage, use, and processing of data in this application all comply with relevant laws and regulations.

[0020] In view of the problems existing in the prior art, this application provides a time-slot-based namespace allocation method, apparatus, device, and storage medium. It dynamically calculates the target namespace name for the target time slot using the periodic granularity of the dynamic time slot and the registration timestamp, and allocates the target namespace name accordingly. This enables multiple tenants to share the target namespace when they all correspond to the target time slot, breaking the limitation of the traditional one-to-one static binding between tenants and namespaces. It avoids the problem of a large number of zombie namespaces generated when a single tenant occupies a namespace and there are many inactive tenants in the cluster, significantly reducing zombie namespaces and improving resource utilization. Furthermore, by sharing the namespace among multiple tenants, the total number of namespaces in the Kubernetes cluster is significantly reduced, alleviating cluster storage pressure and cluster response performance bottlenecks. Simultaneously, the mechanism of automatically expanding the periodic granularity based on a safe quantity threshold can support massive tenant access without adding new namespaces, ensuring the cluster's response efficiency in large-scale multi-tenant scenarios.

[0021] To improve namespace resource utilization, support massive tenant access without exceeding the cluster namespace limit, and ensure cluster response efficiency in large-scale multi-tenant scenarios, this application provides an embodiment of a time-slot-based namespace allocation method. See [link to implementation details]. Figure 1 The time-slot-based namespace allocation method specifically includes the following: Step S110: Obtain the period granularity of the dynamic time slot, the tenant's tenant account and registration timestamp, and use the namespace index formula to calculate and process the registration timestamp and the period granularity to obtain the target namespace name of the target time slot.

[0022] In this context, a dynamic time slot refers to a time window with a variable duration. The period granularity refers to the duration of the dynamic time slot at the current moment. The target time slot is the time slot in which the tenant, with a duration equal to the period granularity, applies to the cluster namespace. The tenant is the user applying to rent the cluster namespace. The tenant account is the tenant's unique identifier. The registration timestamp is the moment the tenant applies to rent the cluster namespace. The target namespace name is the unique identifier of the target time slot.

[0023] Specifically, in the aforementioned step S110, obtaining the period granularity of the dynamic time slot includes: calculating the maximum number of namespaces in real time based on the current time, a preset reference timestamp, and the historical period granularity of the previous time; if the maximum number of namespaces is not greater than the security threshold, then the historical period granularity is used as the period granularity of the dynamic time slot at the current time; if the maximum number of namespaces is greater than the security threshold, then the period granularity of the dynamic time slot at the current time is calculated based on the security threshold, the current time, and the preset reference timestamp, and the period granularity is updated based on the period granularity to update the namespace names in the shared namespace set and the namespaces corresponding to each namespace name.

[0024] Here, the preset base timestamp refers to a pre-defined starting point. The historical period granularity refers to the duration of the dynamic time slot three times prior. The maximum number of namespaces refers to the theoretically maximum number of namespaces that can be generated with the historical period granularity as the duration of the dynamic time slot. The safe number threshold refers to the maximum number of namespaces allowed by the cluster; exceeding this threshold will cause high storage pressure, decreased cluster service performance, and delayed response. The shared namespace set refers to the set of all namespaces and their corresponding namespace names in the storage cluster. A namespace name is both a unique identifier for a time slot and a unique identifier for a namespace. A namespace is a logically isolated unit within the cluster used to implement multi-tenant resource isolation, permission isolation, and environment isolation.

[0025] For example, the maximum number of namespaces can be calculated in real time based on the current time, a preset base timestamp, and the historical periodicity of the previous time. See the following formula: , in, Maximum number of namespaces; The current moment; Preset base timestamp; This refers to the granularity of historical cycles. Indicates to Perform floor rounding.

[0026] For example, the period granularity of the dynamic time slot at the current time can be calculated based on the security quantity threshold, the current time, and the preset reference timestamp, as shown in the following formula: , in, For safe quantity thresholds; The current moment; Preset base timestamp; The periodic granularity at the current moment. Indicates to Perform rounding up.

[0027] For example, updating the namespace names in the shared namespace set and the namespaces corresponding to each namespace name based on the periodic granularity includes: for each namespace name in the shared namespace set, re-determining a new time slot and a new namespace name corresponding to the new time slot based on the registration timestamp of the namespace name, a preset base timestamp and the periodic granularity, and re-determining the new namespace according to the new time slot, constructing the correspondence between the new namespace name and the new namespace and storing it in the shared namespace set, and deleting the correspondence between the namespace name and the corresponding namespace from the shared namespace set.

[0028] Therefore, by dynamically calculating the maximum number of namespaces in real time by combining the current moment, preset baseline timestamp, and historical period granularity, and comparing it with a safe number threshold, the historical period granularity can be directly used when the number of namespaces is within a safe range, reducing unnecessary calculation and resource adjustment overhead. When the maximum number of namespaces is about to exceed the safe threshold, the system automatically performs reverse calculation based on the safe number threshold, updates the period granularity of the dynamic time slot, and updates each namespace in the shared namespace set to reduce the total number of namespaces in the shared namespace set. This achieves precise control over the total number of namespaces, avoiding problems such as excessive cluster storage pressure, response latency, and cluster performance degradation caused by too many namespaces.

[0029] Specifically, in the aforementioned step S110, the step of using the namespace index formula to calculate and process the registration timestamp and the periodic granularity to obtain the target namespace name of the target time slot includes: obtaining a preset base timestamp; calculating the difference between the registration timestamp and the preset base timestamp; calculating the first ratio of the difference to the periodic granularity, and rounding down the first ratio to obtain the time identifier of the target time slot, wherein the time length of the target time slot is equal to the periodic granularity; and concatenating the time identifier and the preset identifier to obtain the target namespace name of the target time slot.

[0030] The rounding down process involves taking the integer part of the first ratio, ensuring that all tenants within the same time slot calculate the same integer number, thus achieving time-based segmentation and classification. The preset identifier refers to a pre-defined fixed prefix or suffix character used to standardize the namespace name format for easier identification and management. Concatenating the time identifier and the preset identifier involves combining them into a string to form the target namespace name.

[0031] For example, the target namespace name of the target time slot is obtained by concatenating the time identifier and the preset identifier, as shown in the following formula: , in, This refers to the registration timestamp. The target namespace name of the target time slot; This refers to the preset identifier; For time identification, It also serves as a time marker, with T representing the periodic granularity; This is the preset base timestamp.

[0032] Therefore, by introducing a preset baseline timestamp, and using the registration timestamp and periodic granularity as the calculation basis, the total time length of the registration timestamp and the preset baseline timestamp is calculated using difference operations. The total time length is then segmented using the periodic granularity, and rounded down to obtain the time identifier of the target time slot to which the registration timestamp belongs. This identifier is then combined with the preset identifier to generate the target namespace name. This allows tenants within the same time slot to be automatically assigned to the same namespace name, enabling dynamic reuse and orderly allocation of namespaces along the time dimension. This method is simple and efficient to calculate, with unified and unique naming rules, avoiding namespace name conflicts. It also ensures adaptive matching between the tenant allocation logic and the periodic granularity of the dynamic time slots. This improves the automation and standardization of namespace allocation in multi-tenant scenarios, and enhances the consistency, traceability, and ease of maintenance of namespace allocation strategies.

[0033] Step S120: Search for the target namespace name in the shared namespace set. If it is not found, count the total number of namespace names in the shared namespace set. If the sum of the total number and 1 is not greater than the security threshold, allocate the corresponding target namespace to the target namespace name, construct and store the mapping relationship between the target namespace name and the tenant account, so as to allocate the target namespace corresponding to the target namespace name to the tenant for use.

[0034] For example, after obtaining the target namespace name, the system first checks if the target namespace name already exists in the shared namespace set. If it exists, there is no need to allocate a target namespace name again, because a corresponding namespace has already been allocated for the namespace name in the shared namespace set. At this point, it is only necessary to establish a mapping relationship between the target namespace name and the tenant account, so that the tenant corresponding to the tenant account can be one of the users of the namespace corresponding to the target namespace name. This allows the tenant of the tenant account to share the target namespace with the tenants corresponding to other tenant accounts of the namespace name, thereby achieving namespace reuse and improving cluster resource utilization. If the target namespace name does not exist in the shared namespace set, it means that no tenant belonging to the target time slot has rented the target namespace name yet. In this case, a target namespace needs to be allocated for the target namespace name, and the mapping relationship between the target namespace name and the target namespace needs to be stored in the shared namespace set.

[0035] Specifically, if the target namespace name is found in the shared namespace set, a mapping relationship between the target namespace name and the tenant account is constructed and stored, so as to allocate the target namespace corresponding to the target namespace name to the tenant for use.

[0036] Therefore, by first searching for the target namespace name in the shared namespace set, existing namespaces can be reused, avoiding the duplicate creation of namespace names and namespaces corresponding to the same time slots, thus reducing redundant resource overhead. When no corresponding namespace name is found, it is first checked whether the total number of namespaces plus one is still within the safe number threshold. Then, a new target namespace is allocated and a mapping relationship between the target namespace and the tenant account is established. This ensures that the number of namespaces created is always within a safe and controllable range, preventing excessive pressure on cluster storage and performance. Furthermore, by establishing a mapping relationship between target namespace names and tenant accounts, the same namespace can be shared by multiple tenants, significantly improving the reuse and utilization rate of namespaces and cluster resources. While achieving multi-tenant isolation, it also takes into account efficient resource utilization and cluster operational stability, making namespace allocation more intelligent, secure, and resource-efficient.

[0037] Step S130: If the sum of the total quantity and 1 is greater than the security quantity threshold, then the periodic granularity adjustment formula is used to calculate the sum, the security quantity threshold, and the periodic granularity to obtain the expanded periodic granularity. Then, the namespace index formula is used to calculate the registration timestamp and the expanded periodic granularity to obtain the new target namespace name of the new target time slot. The new target namespace name is searched from the shared namespace set. If found, the mapping relationship between the new target namespace name and the tenant account is constructed and stored so that the tenant is one of the users of the namespace corresponding to the new target namespace name.

[0038] In this process, the time length of the expanded period granularity is greater than the time length of the period granularity. By expanding the period granularity, the duration covered by a single time slot is increased, reducing the total number of time slots, which in turn reduces the total number of namespace names. This avoids problems such as a surge in cluster storage pressure and a decline in service performance due to exceeding the namespace limit. When calculating the new target namespace name for the new target time slot using the namespace index formula based on the registration timestamp and the expanded period granularity, the expanded period granularity replaces the aforementioned period granularity to obtain the new target namespace name. For the specific processing procedure, please refer to the aforementioned process of calculating the target namespace name for the target time slot using the namespace index formula, which will not be elaborated further here.

[0039] Specifically, in the aforementioned step S130, the calculation and processing of the sum, the safety quantity threshold, and the periodic granularity using the periodic granularity adjustment formula to obtain the expanded periodic granularity includes: calculating a second ratio of the sum to the safety quantity threshold, and rounding the second ratio up to obtain an integer ratio; and using the product of the integer ratio and the periodic granularity as the expanded periodic granularity.

[0040] For example, the expanded periodic granularity is obtained by calculating the sum, the safety quantity threshold, and the periodic granularity using the periodic granularity adjustment formula, as shown in the following formula: , in, For periodic granularity; To expand the granularity of the cycle; The total number; This is a safety quantity threshold. It refers to Perform rounding up.

[0041] Therefore, when the number of new namespaces exceeds the safe limit, the expansion cycle granularity with a longer time length is automatically calculated through the cycle granularity adjustment formula. The total number of namespaces is reduced by using a longer time slot width. Then, the new target namespace name is recalculated based on the expansion cycle granularity, realizing the dynamic convergence of the number of namespaces. This avoids problems such as a surge in cluster storage pressure and a decline in service performance caused by exceeding the limit of the number of namespaces. Tenant allocation is completed without adding new namespaces, further improving the namespace reuse rate and cluster resource utilization rate, and ensuring that the multi-tenant allocation process is safe, stable and adaptively controllable.

[0042] In some examples, after calculating the sum, the security quantity threshold, and the periodic granularity using the periodic granularity adjustment formula in step S130 to obtain the expanded periodic granularity, the method further includes: updating each namespace name in the shared namespace set and the namespace corresponding to each namespace name based on the expanded periodic granularity; for each updated namespace name in the updated shared namespace set, calculating the tenant activity rate corresponding to the updated namespace name; when the tenant activity rate is greater than a preset tenant activity rate, calculating the namespace retention grace period corresponding to the updated namespace name based on the standard namespace retention grace period, the tenant activity rate, and the preset tenant activity rate; when the tenant activity rate is less than the preset tenant activity rate, using the standard namespace retention grace period as the namespace retention grace period corresponding to the updated namespace name.

[0043] Tenant activity rate is a metric that measures the usage frequency of a namespace, reflecting the actual utilization of resources. Preset tenant activity rate is a pre-defined activity threshold used to distinguish between hot and cold namespaces. Standard namespace retention grace period is the system's default minimum namespace reclamation wait time. Namespace retention grace period is the maximum wait time that a namespace can be retained, dynamically calculated based on tenant activity.

[0044] Specifically, the tenant activity rate corresponding to the updated namespace name is calculated by: calculating the total number of active users of all tenants corresponding to the updated namespace name, and using the ratio of the total number of active users to the time length of the time slot corresponding to the updated namespace name as the tenant activity rate.

[0045] Specifically, the namespace retention grace period corresponding to the updated namespace name is calculated based on the standard namespace retention grace period, the tenant activity rate, and the preset tenant activity rate, including: calculating a third ratio of the tenant activity rate to the preset tenant activity rate; and using the product of the third ratio and the standard namespace retention grace period as the namespace retention grace period corresponding to the updated namespace name.

[0046] In addition, it should be explained that the updated namespace set in the updated shared namespace set is called the updated namespace set in this example, but it may be called the namespace set in other examples.

[0047] Therefore, after globally updating the shared namespace set based on the expansion cycle granularity, the system further achieves precise perception of namespace usage popularity by statistically analyzing the tenant activity rate corresponding to each updated namespace name. Combined with the preset tenant activity rate and the standard namespace retention grace period, the system dynamically calculates the namespace retention grace period for the corresponding namespace. This allows for the automatic extension of the retention time for namespaces with high activity rates, ensuring business continuity and stability for active tenants, while applying the standard grace period to namespaces with low activity rates to accelerate the recovery of idle resources. Under the premise of ensuring stable operation of multi-tenant services, this system achieves refined and intelligent scheduling of namespace resources, effectively improving cluster resource utilization while preventing invalid namespaces from occupying cluster storage and scheduling resources for extended periods, further optimizing the overall operational efficiency and stability of the cluster.

[0048] In some examples, the method further includes: periodically counting the tenant set corresponding to each namespace name in the shared namespace set, determining the latest active time of the tenants in the tenant set, determining the latest retention time of the namespace name based on the latest active time of the tenants and the namespace retention grace period, and when the latest retention time is less than the current time, reclaiming the namespace corresponding to the namespace name and deleting the correspondence between the namespace name and the namespace from the shared namespace set.

[0049] The latest active time for a tenant refers to the moment when the corresponding namespace was most recently used by any tenant in the tenant set. Each namespace name has a corresponding namespace retention grace period.

[0050] Therefore, by periodically analyzing the tenant set corresponding to each namespace name, the latest active time of the tenant corresponding to the time slot is accurately captured. Combined with the namespace retention grace period corresponding to the time slot, the latest retention time is determined. This serves as the core criterion for namespace reclamation. When the latest retention time is less than the current time, the corresponding namespace is promptly reclaimed and its corresponding relationship in the shared namespace set is deleted. This method achieves dynamic and intelligent namespace reclamation, which avoids low-activity and idle namespaces occupying cluster storage, scheduling, and other resources for a long time, reducing the cluster's ineffective load. It also accurately controls the reclamation timing, preventing the accidental reclamation of namespaces with potential usage needs, and ensuring the continuity and stability of tenant business usage. At the same time, periodically performing reclamation operations forms a closed-loop management of "dynamic allocation - intelligent monitoring - timely reclamation," further improving the utilization and turnover efficiency of cluster resources, optimizing the overall cluster operating performance, reducing resource waste, and balancing the needs of multi-tenant isolation with the refined management of cluster resources.

[0051] In some examples, the method further includes: periodically counting the total number of namespace names in the shared namespace set and counting the total number of tenants; calculating the total number and the total number of tenants using a reuse rate formula to obtain a namespace reuse rate; when the namespace reuse rate is lower than a preset reuse rate, calculating the minimum total number of namespace names based on the preset reuse rate and the total number of tenants; calculating the shortest period granularity based on the minimum total number, the current time, and a preset base timestamp; and updating each namespace name in the shared namespace set and the namespace corresponding to each namespace name based on the shortest period granularity.

[0052] For example, the namespace reuse rate is obtained by calculating the total number and the total number of tenants using the reuse rate formula, as shown in the following formula: , Where R refers to namespace reuse rate; N refers to the total number; and M refers to the total number of tenants.

[0053] For example, the minimum total number of namespace names can be calculated based on the preset reuse rate and the total number of tenants, as shown in the following formula: , in, This refers to the minimum total quantity; This refers to the preset reuse rate; M refers to the total number of tenants.

[0054] For example, the shortest period granularity is calculated based on the minimum total quantity, the current time, and a preset reference timestamp, as shown in the following formula: , in, This refers to the shortest period granularity. This refers to the minimum total quantity. It refers to Round up.

[0055] Therefore, by periodically counting the total number of namespace names and the total number of tenants in the shared namespace set, and calculating the namespace reuse rate based on the reuse rate formula, real-time monitoring of namespace resource reuse in multi-tenant scenarios can be achieved. When the reuse rate is lower than the preset reuse rate, the minimum total number of namespace names is automatically calculated based on the preset reuse rate and the total number of tenants. Then, the shortest period granularity is obtained by combining the current time with the preset baseline timestamp, and the namespace names and corresponding cluster resources are updated accordingly. When namespace reuse is insufficient and resource utilization is inadequate, the time slot granularity can be adaptively adjusted to improve the tenant sharing rate and effectively improve the resource idle problem.

[0056] In some examples, such as Figure 2As shown, to avoid problems such as excessive cluster storage pressure, high cluster load, decreased cluster performance, and low resource reuse rate caused by an excessive number of namespaces in a Kubernetes multi-tenant cluster, this embodiment of the invention constructs a namespace allocation system based on dynamic time slots through modular design. This system specifically includes: adopting a modular layered architecture, dividing the system into an external input layer, a core scheduling layer, a core business module layer, and a bottom output layer; the external input layer is used to respond to tenants' namespace rental requests, collect tenant accounts and registration timestamps, and monitor metrics such as the total number of namespaces, tenant reuse rate, and tenant activity rate in real time. The core scheduling layer is used to route tenants' namespace rental requests to the corresponding processing modules, and to route corresponding processing requests to the corresponding modules based on the metrics monitored by the external input layer. The core business module layer includes a time slot mapping module, a tenant routing table, a lifecycle management module, and an adaptive adjustment module. By modularizing and decoupling the functional logic, system complexity is reduced, and maintainability and scalability are improved. Specifically, the time slot mapping module calculates the target namespace name based on the tenant registration timestamp and dynamic periodic granularity, enabling dynamic mapping of tenants by time slot. The tenant routing table serves as the core index, storing the correspondence between namespace names, namespaces, and tenant accounts, providing data support for the entire process. The lifecycle management module is responsible for the creation, monitoring, and recycling of namespaces, ensuring controllable resource lifecycles. The adaptive adjustment module dynamically adjusts the periodic granularity of time slots based on monitoring indicators such as the total number of namespaces, tenant reuse rate, and tenant activity rate, controlling the total number of namespaces within a safe threshold range. The underlying output layer uses a Kubernetes API server and distributed key-value storage to complete the actual operation and persistence of namespace resources, thereby effectively controlling the total number of namespaces, improving resource reuse rate, and avoiding cluster stability risks while ensuring multi-tenant resource isolation requirements.

[0057] In summary, this solution dynamically calculates the target namespace name for the target time slot based on the periodic granularity of the dynamic time slot and the registration timestamp, and then allocates the target namespace name accordingly. This allows multiple tenants to share the target namespace when they all correspond to the target time slot, breaking the limitations of the traditional one-to-one static binding between tenants and namespaces. It avoids the problem of a large number of zombie namespaces generated when a single tenant occupies a namespace and there are many inactive tenants in the cluster, significantly reducing the number of zombie namespaces and improving resource utilization. Furthermore, by sharing the namespace among multiple tenants, the total number of namespaces in the Kubernetes cluster is significantly reduced, alleviating cluster storage pressure and cluster response performance bottlenecks. Simultaneously, the mechanism of automatically expanding the periodic granularity based on a safe quantity threshold can support massive tenant access without adding new namespaces, ensuring the cluster's response efficiency in large-scale multi-tenant scenarios.

[0058] To improve namespace resource utilization, support massive tenant access without exceeding the cluster namespace limit, and ensure cluster response efficiency in large-scale multi-tenant scenarios, this application provides an embodiment of a time-slot-based namespace allocation device for implementing all or part of the aforementioned time-slot-based namespace allocation method. See [link to embodiment]. Figure 3 The time-slot-based namespace allocation device specifically includes the following components: The acquisition unit 10 is used to acquire the period granularity of the dynamic time slot, the tenant's tenant account and registration timestamp, and to calculate and process the registration timestamp and the period granularity using the namespace index formula to obtain the target namespace name of the target time slot.

[0059] The allocation unit 20 is used to search for the target namespace name from the shared namespace set. If it is not found, it counts the total number of namespace names in the shared namespace set. If the sum of the total number and 1 is not greater than the safe number threshold, it allocates the corresponding target namespace to the target namespace name, constructs and stores the mapping relationship between the target namespace name and the tenant account, so as to allocate the target namespace corresponding to the target namespace name to the tenant for use.

[0060] The allocation unit 20 is further configured to, if the sum of the total quantity and 1 is greater than the safety quantity threshold, calculate the sum, the safety quantity threshold and the periodic granularity using the periodic granularity adjustment formula to obtain the expanded periodic granularity, and calculate the registration timestamp and the expanded periodic granularity using the namespace index formula to obtain the new target namespace name of the new target time slot, and search for the new target namespace name from the shared namespace set. If found, a mapping relationship between the new target namespace name and the tenant account is constructed and stored so that the tenant is one of the users of the namespace corresponding to the new target namespace name.

[0061] As described above, the time-slot-based namespace allocation device provided in this application can dynamically calculate the target namespace name of the target time slot through the periodic granularity of the dynamic time slot and the registration timestamp, and allocate the target namespace name to the target namespace. This enables multiple tenants to share the target namespace when they all correspond to the target time slot, breaking the limitation of the traditional one-to-one static binding between tenants and namespaces. It avoids the problem of a large number of zombie namespaces when a tenant occupies a namespace and there are a large number of inactive tenants in the cluster, greatly reducing the number of zombie namespaces and improving resource utilization. Furthermore, by sharing the namespace among multiple tenants, the total number of namespaces in the K8s cluster is significantly reduced, alleviating cluster storage pressure and cluster response performance bottlenecks. At the same time, the mechanism of automatically expanding the periodic granularity based on a safe quantity threshold can support the access of massive numbers of tenants without adding new namespaces, ensuring the response efficiency of the cluster in large-scale multi-tenant scenarios.

[0062] To further illustrate this solution, this application also provides a specific application example of implementing the time-slot-based namespace allocation method using the aforementioned time-slot-based namespace allocation device, which specifically includes the following: In some embodiments, when the device is used to calculate the target namespace name of the target time slot by using the namespace index formula to calculate the registration timestamp and the periodic granularity, it is specifically used to: obtain a preset base timestamp; calculate the difference between the registration timestamp and the preset base timestamp; calculate the first ratio of the difference to the periodic granularity, and round down the first ratio to obtain the time identifier of the target time slot, wherein the time length of the target time slot is equal to the periodic granularity; and concatenate the time identifier and the preset identifier to obtain the target namespace name of the target time slot.

[0063] In some embodiments, the apparatus is further configured to: periodically count the tenant set corresponding to each namespace name in the shared namespace set, determine the latest active time of the tenants in the tenant set, determine the latest retention time of the namespace name based on the latest active time of the tenants and the namespace retention grace period, and when the latest retention time is less than the current time, reclaim the namespace corresponding to the namespace name and delete the correspondence between the namespace name and the namespace from the shared namespace set.

[0064] In some embodiments, when the device is used to calculate the sum, the safety quantity threshold, and the periodic granularity using the periodic granularity adjustment formula to obtain the expanded periodic granularity, it is specifically used to: calculate a second ratio of the sum to the safety quantity threshold, and round the second ratio up to obtain an integer ratio; and use the product of the integer ratio and the periodic granularity as the expanded periodic granularity.

[0065] In some embodiments, after calculating the sum, the security quantity threshold, and the periodic granularity using the periodic granularity adjustment formula to obtain the expanded periodic granularity, the device is further configured to: update each namespace name in the shared namespace set and the namespace corresponding to each namespace name based on the expanded periodic granularity; for each updated namespace name in the updated shared namespace set, calculate the tenant activity rate corresponding to the updated namespace name; when the tenant activity rate is greater than a preset tenant activity rate, calculate the namespace retention grace period corresponding to the updated namespace name based on the standard namespace retention grace period, the tenant activity rate, and the preset tenant activity rate; when the tenant activity rate is less than the preset tenant activity rate, use the standard namespace retention grace period as the namespace retention grace period corresponding to the updated namespace name.

[0066] In some embodiments, the apparatus is further configured to: periodically count the total number of namespace names in the shared namespace set and count the total number of tenants; calculate the total number and the total number of tenants using a reuse rate formula to obtain a namespace reuse rate; when the namespace reuse rate is lower than a preset reuse rate, calculate the minimum total number of namespace names based on the preset reuse rate and the total number of tenants; calculate the shortest period granularity based on the minimum total number, the current time, and a preset base timestamp; and update each namespace name in the shared namespace set and the namespace corresponding to each namespace name based on the shortest period granularity.

[0067] In some embodiments, when the device is used to obtain the period granularity of the dynamic time slot, it is specifically used to: calculate the maximum number of namespaces in real time based on the current time, a preset reference timestamp, and the historical period granularity of the previous time; if the maximum number of namespaces is not greater than the security number threshold, then the historical period granularity is used as the period granularity of the dynamic time slot at the current time; if the maximum number of namespaces is greater than the security number threshold, then the period granularity of the dynamic time slot at the current time is calculated based on the security number threshold, the current time, and the preset reference timestamp, and the period granularity is updated based on the period granularity to update the namespace names in the shared namespace set and the namespaces corresponding to each namespace name.

[0068] This invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the time-slot-based namespace allocation method.

[0069] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described time-slot-based namespace allocation method.

[0070] This invention also provides a computer program product, which includes a computer program that, when executed by a processor, implements the above-described time-slot-based namespace allocation method.

[0071] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0072] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0073] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0074] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0075] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A namespace allocation method based on time slots, characterized in that, The method includes: Obtain the periodic granularity of the dynamic time slot, the tenant's tenant account and registration timestamp, obtain a preset base timestamp, and calculate the difference between the registration timestamp and the preset base timestamp; calculate the first ratio of the difference to the periodic granularity, and round down the first ratio to obtain the time identifier of the target time slot, wherein the time length of the target time slot is equal to the periodic granularity; concatenate the time identifier and the preset identifier to obtain the target namespace name of the target time slot; The target namespace name is searched in the shared namespace set. If it is not found, the total number of namespace names in the shared namespace set is counted. If the sum of the total number and 1 is not greater than the safe number threshold, the target namespace name is allocated to the target namespace name. The mapping relationship between the target namespace name and the tenant account is constructed and stored so that the target namespace name corresponding to the target namespace name can be allocated to the tenant for use. If the sum of the total quantity and 1 is greater than the security quantity threshold, then a second ratio of the sum to the security quantity threshold is calculated, and the second ratio is rounded up to obtain an integer ratio. The product of the integer ratio and the period granularity is used as the expanded period granularity, and the registration timestamp and the expanded period granularity are calculated using the namespace index formula to obtain a new target namespace name for the new target time slot. The new target namespace name is then searched from the shared namespace set. If found, a mapping relationship between the new target namespace name and the tenant account is constructed and stored, so that the tenant is one of the users of the namespace corresponding to the new target namespace name.

2. The namespace allocation method based on time slots according to claim 1, characterized in that, The method further includes: For each namespace name in the shared namespace set on a periodic basis, the set of tenants corresponding to the namespace name is counted, and the latest active time of the tenants in the set is determined. Based on the latest active time of the tenants and the namespace retention grace period, the latest retention time of the namespace name is determined. When the latest retention time is less than the current time, the namespace corresponding to the namespace name is reclaimed, and the correspondence between the namespace name and the namespace is deleted from the shared namespace set.

3. The namespace allocation method based on time slots according to claim 1, characterized in that, After multiplying the integer ratio by the periodic granularity as the expanded periodic granularity, the method further includes: Based on the expansion cycle granularity, the namespace names in the shared namespace set and the namespaces corresponding to each namespace name are updated again. For each updated namespace name in the updated shared namespace set, the tenant activity rate corresponding to the updated namespace name is calculated. When the tenant activity rate is greater than the preset tenant activity rate, the namespace retention grace period corresponding to the updated namespace name is calculated based on the standard namespace retention grace period, the tenant activity rate and the preset tenant activity rate. When the tenant activity rate is less than the preset tenant activity rate, the standard namespace retention grace period is used as the namespace retention grace period corresponding to the updated namespace name.

4. The namespace allocation method based on time slots according to claim 1, characterized in that, The method further includes: The total number of namespace names in the shared namespace set is periodically counted, and the total number of tenants is counted. The namespace reuse rate is obtained by calculating the total number and the total number of tenants using the reuse rate formula. When the namespace reuse rate is lower than the preset reuse rate, the minimum total number of namespace names is calculated based on the preset reuse rate and the total number of tenants. The shortest period granularity is calculated based on the minimum total number, the current time, and the preset base timestamp. The namespace names in the shared namespace set and the namespaces corresponding to each namespace name are updated again based on the shortest period granularity.

5. The namespace allocation method based on time slots according to claim 1, characterized in that, The process of obtaining the periodic granularity of the dynamic time slot includes: The maximum number of namespaces is calculated in real time based on the current time, the preset base timestamp, and the historical period granularity of the previous time. If the maximum number of namespaces is not greater than the safe number threshold, the historical period granularity is used as the period granularity of the dynamic time slot at the current time. If the maximum number of namespaces is greater than the security number threshold, then the periodicity of the dynamic time slot at the current time is calculated based on the security number threshold, the current time, and the preset base timestamp, and the namespace name in the shared namespace set and the namespace corresponding to each namespace name are updated based on the periodicity.

6. A namespace allocation device based on time slots, characterized in that, The device includes: The acquisition unit is used to acquire the periodic granularity of the dynamic time slot, the tenant's tenant account and registration timestamp, acquire a preset base timestamp, calculate the difference between the registration timestamp and the preset base timestamp; calculate the first ratio of the difference to the periodic granularity, and round down the first ratio to obtain the time identifier of the target time slot, wherein the time length of the target time slot is equal to the periodic granularity; and concatenate the time identifier and the preset identifier to obtain the target namespace name of the target time slot. The allocation unit is used to search for the target namespace name from the shared namespace set. If it is not found, it counts the total number of namespace names in the shared namespace set. If the sum of the total number and 1 is not greater than the safe number threshold, it allocates the corresponding target namespace to the target namespace name, constructs and stores the mapping relationship between the target namespace name and the tenant account, so as to allocate the target namespace corresponding to the target namespace name to the tenant for use. The allocation unit is further configured to: if the sum of the total quantity and 1 is greater than the security quantity threshold, calculate a second ratio of the sum to the security quantity threshold, and round the second ratio up to obtain an integer ratio; multiply the integer ratio by the period granularity as the expanded period granularity, and use the namespace index formula to calculate the registration timestamp and the expanded period granularity to obtain a new target namespace name for the new target time slot; search for the new target namespace name in the shared namespace set; if found, construct and store the mapping relationship between the new target namespace name and the tenant account, so that the tenant is one of the users of the namespace corresponding to the new target namespace name.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the time-slot-based namespace allocation method according to any one of claims 1 to 5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the time-slot-based namespace allocation method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Resource management method and device, electronic equipment and computer readable medium

    CN112416593A

  • Bandwidth allocation method and device for namespace

    CN121455417A