A dynamic maintenance method, device and equipment for pre-creating a sandbox pool
Patent Information
- Application Number
- CN202611359631.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-03
- Publication Date
- 2026-11-10
Smart Images

Figure CN123069356A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of cloud computing and computing resource management technology, and in particular to a dynamic maintenance method, apparatus and equipment for pre-created sandbox pools. Background Technology
[0002] With the development of cloud computing technology, sandboxes, as relatively isolated runtime environments, can be used to provide corresponding computing resources and runtime environments for tasks such as code execution, tool invocation, and development testing. In the above applications, it is usually necessary to create a sandbox according to the runtime environment configuration corresponding to the task, and then provide it to the requesting party after completing the corresponding resource preparation and environment initialization.
[0003] Existing sandbox services can create corresponding sandboxes upon receiving a sandbox retrieval request, or they can pre-create a certain number of sandboxes to form a sandbox pool. When a sandbox retrieval request is received, the already created sandboxes are retrieved from the sandbox pool, reducing the waiting time caused by resource preparation and environment initialization after the request arrives. As the sandbox pool continues to run, the sandboxes within the pool will change accordingly based on their usage and operational status, and the available sandbox resources that the sandbox pool can provide will also change accordingly.
[0004] Therefore, when using pre-created sandbox pools to provide sandbox resources, how to reasonably maintain the available sandbox resources in the sandbox pool so that the sandbox pool can continue to provide available sandboxes during continuous operation is a technical problem that needs to be solved. Summary of the Invention
[0005] This invention provides a method, apparatus, and equipment for the dynamic maintenance of pre-created sandbox pools, which solves the problem in the prior art that pre-created sandbox pools are difficult to maintain continuously available sandbox resources, and realizes the dynamic maintenance of the effective status of sandboxes and pool capacity in the sandbox pool.
[0006] This invention provides a dynamic maintenance method for pre-created sandbox pools, comprising the following steps: Multiple sandboxes are pre-created based on the sandbox template to form a sandbox pool, and the validity period information of each sandbox is obtained. The order of obtaining sandboxes is determined based on the validity period information of each sandbox. When a sandbox obtaining request is received, a target sandbox in a valid state is obtained from the sandbox pool according to the sandbox obtaining order, and the target sandbox is removed from the sandbox pool. Under the condition that the preset validity period maintenance triggering condition is met, the validity period of the sandbox in the sandbox pool is checked. If the validity period update condition is met, the validity period of the sandbox and the corresponding validity period information are updated. If the preset capacity maintenance triggering conditions are met, the number of pre-created sandboxes in the sandbox pool that are in a user-accessible state is obtained as the current pool capacity, and the target pool capacity corresponding to the sandbox pool is obtained. The target pool capacity is used to characterize the number of pre-created sandboxes in the sandbox pool that are expected to be in a user-accessible state. If the current pool capacity is less than the target pool capacity, the concurrency control permission for the sandbox pool is obtained, and the current pool capacity is re-determined after obtaining the concurrency control permission. A sandbox is created based on the difference between the redefined current pool capacity and the target pool capacity, and the created sandbox is added to the sandbox pool after creation.
[0007] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool is provided, wherein the validity period information includes the expiration time of the sandbox; the step of determining the sandbox acquisition order according to the validity period information corresponding to each sandbox includes: sorting the sandboxes in the sandbox pool according to the expiration time corresponding to each sandbox, so that the sandboxes with earlier expiration times are acquired before the sandboxes with later expiration times.
[0008] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool includes a validity period maintenance triggering condition that includes reaching a preset validity period maintenance cycle. The method involves detecting the validity period of sandboxes in the sandbox pool, and updating the validity period and corresponding validity period information of the sandboxes when they meet the validity period update conditions. This includes: obtaining the remaining validity period of unexpired sandboxes in the sandbox pool; extending the validity period of the corresponding sandbox by calling the validity period update interface provided by the sandbox service when the remaining validity period is less than a preset validity period threshold; obtaining the updated expiration time of the sandbox, and synchronously updating the validity period information corresponding to the sandbox in the distributed storage cluster according to the updated expiration time; and synchronously updating the sorting score of the sandbox in the ordered set according to the updated expiration time when the sandbox pool uses ordered set storage and the expiration timestamp of the sandbox is used as the sorting score.
[0009] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool is provided, wherein the capacity maintenance triggering condition includes reaching a preset capacity maintenance cycle; the step of obtaining concurrent control permission for the sandbox pool and re-determining the current pool capacity after obtaining the concurrent control permission includes: obtaining a distributed lock corresponding to the sandbox pool; after obtaining the distributed lock, re-obtaining the number of pre-created sandboxes in the sandbox pool that are in a user-obtainable state, and determining the current pool capacity based on the re-obtained number of pre-created sandboxes.
[0010] According to a dynamic maintenance method for a pre-created sandbox pool provided by the present invention, the step of creating sandboxes based on the difference between the re-determined current pool capacity and the target pool capacity, and adding the created sandboxes to the sandbox pool after creation, includes: determining the number of sandboxes to be supplemented based on the difference between the target pool capacity and the re-determined current pool capacity; creating sandboxes corresponding to the sandbox templates based on the number of sandboxes to be supplemented; after any sandbox is created and added to the sandbox pool, re-acquiring the number of pre-created sandboxes in the sandbox pool that are in a user-accessible state, and updating the current pool capacity based on the re-acquired number of pre-created sandboxes; if the updated current pool capacity is still less than the target pool capacity, continuing to create sandboxes; and releasing the distributed lock after the sandbox replenishment of the sandbox pool is completed.
[0011] According to a dynamic maintenance method for a pre-created sandbox pool provided by the present invention, the step of obtaining a target sandbox in a valid state from the sandbox pool according to the sandbox acquisition order and removing the target sandbox from the sandbox pool includes: obtaining a sandbox to be verified from the sandbox pool according to the sandbox acquisition order; determining whether the sandbox to be verified has expired based on the expiration time corresponding to the sandbox to be verified; if the sandbox to be verified has not expired, determining the sandbox to be verified as the target sandbox and removing the target sandbox from the sandbox pool; if the sandbox to be verified has expired, calling the sandbox deletion interface provided by the sandbox service to destroy the sandbox instance corresponding to the sandbox to be verified, clearing the expiration information corresponding to the sandbox to be verified, and continuing to obtain the next sandbox from the sandbox pool according to the sandbox acquisition order.
[0012] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool further includes: if a target sandbox in a valid state is not obtained from the sandbox pool according to the sandbox acquisition request, triggering an asynchronous sandbox replenishment task for the sandbox pool, and creating an on-demand sandbox for the sandbox acquisition request; and returning the sandbox identifier of the on-demand sandbox to the requester of the sandbox acquisition request.
[0013] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool further includes: during the process of checking the expiration date of sandboxes in the sandbox pool, if a sandbox has expired, calling the sandbox deletion interface provided by the sandbox service to destroy the expired sandbox instance, deleting the expired sandbox from the sandbox pool, and clearing the expiration date information corresponding to the expired sandbox.
[0014] According to a dynamic maintenance method for a pre-created sandbox pool provided by the present invention, sandboxes in the sandbox pool are stored in an ordered set, and the expiration timestamps corresponding to each sandbox are used as the sorting scores of the corresponding sandboxes; the corresponding sandboxes are obtained from the ordered set in ascending order of the sorting scores.
[0015] The present invention also provides a dynamic maintenance device for a pre-created sandbox pool, comprising the following modules: The sandbox pool initialization module is used to pre-create multiple sandboxes to form a sandbox pool based on the sandbox template, and to obtain the validity period information of each sandbox. The sandbox scheduling module is used to determine the sandbox acquisition order based on the validity period information of each sandbox. When a sandbox acquisition request is received, the module acquires a target sandbox that is in a valid state from the sandbox pool according to the sandbox acquisition order and removes the target sandbox from the sandbox pool. The validity period maintenance module is used to detect the validity period of sandboxes in the sandbox pool when the preset validity period maintenance trigger conditions are met, and to update the validity period of the sandbox and the corresponding validity period information when the sandbox meets the validity period update conditions. The capacity detection module is used to obtain the number of pre-created sandboxes in the sandbox pool that are in a user-accessible state as the current pool capacity when the preset capacity maintenance triggering conditions are met, and to obtain the target pool capacity corresponding to the sandbox pool. The target pool capacity is used to characterize the number of pre-created sandboxes in the sandbox pool that are expected to be in a user-accessible state. If the current pool capacity is less than the target pool capacity, the module obtains the concurrency control permission for the sandbox pool, and redetermines the current pool capacity after obtaining the concurrency control permission. The capacity replenishment module is used to create a sandbox based on the difference between the redefined current pool capacity and the target pool capacity, and to add the created sandbox to the sandbox pool after the sandbox is created.
[0016] The present invention also 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 computer program to implement the dynamic maintenance method for the pre-created sandbox pool as described above.
[0017] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the dynamic maintenance method for a pre-created sandbox pool as described above.
[0018] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the dynamic maintenance method for a pre-created sandbox pool as described above.
[0019] This invention provides a method, apparatus, and equipment for the dynamic maintenance of a pre-created sandbox pool, which has the following beneficial effects: A sandbox pool is formed by pre-creating sandboxes, and the sandbox acquisition order is determined based on the validity period information of each sandbox, enabling sandbox acquisition requests to obtain target sandboxes in a valid state from the sandbox pool. After a target sandbox is acquired, it is removed from the sandbox pool, allowing the pool capacity to change with the actual consumption of available sandboxes. By detecting the validity period of sandboxes in the pool and synchronously updating the validity period and corresponding validity period information of sandboxes that meet the validity period update conditions, the valid state of pre-created sandboxes in the pool is continuously maintained. By using the number of pre-created sandboxes in the sandbox pool that are available for user acquisition as the current pool capacity, when the capacity is insufficient, concurrency control permissions are obtained and the current pool capacity is redefined. Then, sandboxes are created and replenished based on the difference between the redefined current pool capacity and the target pool capacity, ensuring that the capacity replenishment corresponds to the actual number of available sandboxes after concurrency control. This achieves dynamic maintenance of the valid state of sandboxes and the sandbox pool capacity, improving the sandbox pool's ability to continuously provide available sandbox resources. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in this invention 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 invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0021] Figure 1 This is a flowchart illustrating the dynamic maintenance method for pre-created sandbox pools provided by the present invention.
[0022] Figure 2 This is a schematic diagram of the architecture of the E2B pre-created pooling management system provided by the present invention.
[0023] Figure 3 This is a schematic diagram of the structure of the dynamic maintenance device for the pre-created sandbox pool provided by the present invention.
[0024] Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0026] The terminology involved in this invention will be explained below.
[0027] An Application Programming Interface (API) is a set of interface specifications for function calls and data interaction between different software components. In this solution, it is used to implement sandbox creation, expiration update, and related sandbox operations.
[0028] The Application Programming Interface Client (APIClient) is a client used to initiate interface requests to the server. In this solution, it is used to initiate requests for template configuration, sandbox acquisition, and status query.
[0029] Creating a sandbox is an operation used to create sandbox instances. In this solution, it is used to create pre-created sandboxes or on-demand sandboxes.
[0030] E2B Sandbox Service (E2B) is a cloud-based sandbox service used to provide an isolated code execution environment. In this solution, operations such as sandbox creation, expiration update, and deletion are implemented through the corresponding sandbox service interface.
[0031] GET is a request method in the Hypertext Transfer Protocol, which can be used in this solution to initiate requests such as sandbox retrieval.
[0032] Hypertext Transfer Protocol (HTTP) is an application layer protocol used for transmitting request and response data between clients and servers. In this solution, it is used for communication between the client and the sandbox pooling management service.
[0033] The Hypertext Transfer Protocol Application Programming Interface Server (HTTP API Server) is a service component that receives and processes application programming interface requests via the Hypertext Transfer Protocol. In this solution, it is used to receive requests initiated by clients and parse and validate the request parameters.
[0034] The KeepAlive Manager is a management component used to maintain the effective status of the sandbox. In this solution, it is used to periodically check the remaining effective time of the sandbox and update the sandbox's validity period and corresponding validity period information when the validity period update conditions are met.
[0035] Metadata is data used to describe the attributes of data or resources. In this solution, it is used to record attribute information such as how the sandbox is created.
[0036] On-demand creation is a processing method that creates corresponding resources in real time based on actual requests. In this solution, it is used to create an on-demand sandbox for the current sandbox acquisition request when a target sandbox in a valid state is not obtained from the sandbox pool.
[0037] POST is a request method in the Hypertext Transfer Protocol, which can be used in this solution to submit requests such as sandbox template configuration.
[0038] Pool storage is a storage structure used to store sandbox data in a sandbox pool. In this solution, an ordered set is used to store the pool data of the sandbox pool.
[0039] Redis Cluster is a distributed data storage cluster. In this solution, it is used to store the pool data of the sandbox pool and the validity period information of the sandbox, and provides distributed lock functionality.
[0040] The Replenish Manager is a management component used to maintain the capacity of the sandbox pool. In this solution, it is used to periodically check the current pool capacity and the target pool capacity, and perform sandbox replenishment when the capacity is insufficient.
[0041] A Software Development Kit (SDK) is a set of tools used to support software development and API calls. In this solution, it can be used to send requests to the sandbox pooling management service for template configuration, sandbox acquisition, and status queries.
[0042] An ordered set is a data structure that stores members in an ordered manner based on their corresponding sorting scores. In this scheme, it is used to store sandboxes in the sandbox pool, and the expiration timestamp of the sandbox is used as the sorting score of the corresponding sandbox.
[0043] Time To Live (TTL) is used to represent the time a resource remains in a valid state. In this scheme, it is used to characterize the remaining valid duration of the sandbox and serves as the basis for maintaining the sandbox's validity period.
[0044] Time-to-Live (TTL) storage is a storage structure used to store sandbox expiration information. In this solution, it is used to record information such as the expiration time and remaining validity period of each sandbox.
[0045] Update Time To Live (UTL) is an operation used to update the validity period of resources. In this solution, it is used to extend the validity period of the sandbox and update the corresponding validity period information accordingly.
[0046] The Warmup Manager is a management component used to perform management operations related to the pre-creation of sandbox pools. In this solution, it is used to perform operations such as sandbox acquisition and sandbox template configuration.
[0047] The Warmup Service is a service component used to perform management and maintenance of pre-created sandbox pools. In this solution, it is used to coordinate sandbox acquisition, validity period maintenance, and capacity maintenance.
[0048] ZPopMin is an operation that removes and returns members with smaller sort scores from an ordered set. In this scheme, it is used to retrieve sandboxes in ascending order of sort scores corresponding to expiration timestamps.
[0049] The following is combined Figures 1 to 4 The embodiments of the present invention are described in detail.
[0050] The dynamic maintenance method for pre-created sandbox pools provided in this embodiment of the invention is executed by a dynamic maintenance device or system for pre-created sandbox pools. The device or system can be configured in a computer, which can be a local computer or a cloud computer. The local computer can be a computer, tablet, etc., and no specific limitation is made here.
[0051] Figure 1 This is a flowchart illustrating the dynamic maintenance method for pre-created sandbox pools provided by the present invention, as shown below. Figure 1 As shown, the method includes the following steps: S110. Create multiple sandboxes in advance according to the sandbox template to form a sandbox pool, and obtain the validity period information of each sandbox.
[0052] S120. Determine the sandbox acquisition order based on the validity period information of each sandbox. When a sandbox acquisition request is received, acquire the target sandbox in a valid state from the sandbox pool according to the sandbox acquisition order, and remove the target sandbox from the sandbox pool.
[0053] S130. If the preset validity period maintenance triggering conditions are met, the validity period of the sandbox in the sandbox pool is checked. If the validity period update conditions are met, the validity period of the sandbox and the corresponding validity period information are updated.
[0054] S140. Under the condition of meeting the preset capacity maintenance triggering condition, obtain the number of pre-created sandboxes in the sandbox pool that are in a state that can be obtained by users as the current pool capacity, and obtain the target pool capacity corresponding to the sandbox pool. The target pool capacity is used to characterize the number of pre-created sandboxes in the sandbox pool that are expected to be in a state that can be obtained by users. If the current pool capacity is less than the target pool capacity, obtain the concurrency control permission for the sandbox pool, and redetermine the current pool capacity after obtaining the concurrency control permission.
[0055] S150. Create a sandbox based on the difference between the redefined current pool capacity and the target pool capacity, and add the created sandbox to the sandbox pool after the sandbox is created.
[0056] Specifically, multiple sandboxes are created based on pre-configured sandbox templates, and these sandboxes are added to their corresponding sandbox pools. The validity period information for each sandbox is also retrieved. Sandbox templates configure the runtime environment for the sandboxes to be created; different templates can correspond to different sandbox pools. Upon system startup, the pre-configured sandbox templates are loaded, and a corresponding number of sandboxes are created based on the target pool capacity for each template, until the corresponding sandbox pool reaches its target capacity. This creates a sandbox pool containing multiple pre-created sandboxes before receiving a sandbox retrieval request. The validity period information for each sandbox characterizes its validity period and is recorded when the sandbox is added to the sandbox pool.
[0057] The sandbox acquisition order is determined based on the validity period information of each sandbox in the sandbox pool. When a sandbox acquisition request is received, the parameters carried in the request are parsed and their validity verified. The corresponding sandbox pool is determined based on the sandbox template corresponding to the request, and sandboxes are acquired from that pool according to the determined acquisition order. The validity status of the acquired sandbox is confirmed. If the sandbox is valid, it is designated as the target sandbox and provided to the requester. If the sandbox is not valid, other sandboxes are acquired from the sandbox pool according to the acquisition order until a valid target sandbox is obtained.
[0058] Under the condition that the preset validity period maintenance triggering conditions are met, the validity period of sandboxes in the sandbox pool is checked. The validity period maintenance triggering condition can be reaching the preset validity period maintenance cycle. The periodically triggered validity period maintenance task traverses the configured sandbox templates and obtains the sandboxes in the sandbox pool corresponding to each sandbox template, checking the validity period of each sandbox. When a sandbox is detected to meet the validity period update condition, the validity period of the corresponding sandbox is extended through the validity period update interface provided by the sandbox service, and the validity period information of the corresponding sandbox is updated synchronously according to the updated validity period, so that the actual validity period of the sandbox corresponds to the validity period information recorded in the sandbox pool.
[0059] Under the condition that the preset capacity maintenance triggering conditions are met, capacity maintenance is performed on the sandbox pool. The capacity maintenance triggering condition can be reaching a preset capacity maintenance cycle. Through periodically triggered capacity maintenance tasks, the configured sandbox templates are traversed to obtain the current pool capacity and target pool capacity of the sandbox pool corresponding to each sandbox template. In this embodiment, the current pool capacity refers to the number of pre-created sandboxes that have been created and added to the sandbox pool and are in a state where they can be obtained by users. Sandboxes that have already been obtained by users from the sandbox pool are no longer included in the current pool capacity, and sandboxes that are being created but have not yet been added to the sandbox pool are also not included in the current pool capacity. They will be included in the current pool capacity after the sandboxes are created and added to the sandbox pool. The target pool capacity refers to the number of pre-created sandboxes that are pre-configured for the sandbox pool and are expected to remain in a state where they can be obtained by users. It is used as the basis for determining whether the sandbox pool needs capacity replenishment and determining the number of sandboxes to be replenished.
[0060] When the current pool capacity is less than the target pool capacity, acquire concurrent control permissions for that sandbox pool; after acquiring concurrent control permissions, acquire the number of sandboxes in the sandbox pool again, and redetermine the current pool capacity based on the acquired number of sandboxes, so that subsequent sandbox replenishment is based on the sandbox pool capacity after acquiring concurrent control permissions.
[0061] The number of sandboxes to be created is determined based on the difference between the current pool capacity and the target pool capacity. Sandboxes are then created according to the corresponding sandbox templates and added to the sandbox pool until the current pool capacity reaches the target pool capacity. After replenishing the sandbox pool, the concurrency control permissions for that sandbox pool are released so that subsequent capacity maintenance processes can acquire the corresponding concurrency control permissions.
[0062] This embodiment schedules sandboxes based on their validity period information and updates the validity period and corresponding information of the sandboxes when the validity period maintenance trigger conditions are met, keeping the sandboxes in the sandbox pool available. Simultaneously, when the sandbox pool capacity is insufficient, it acquires concurrency control permissions and replenishes sandboxes based on the newly determined pool capacity after acquiring concurrency control permissions. This reduces the repeated replenishment of sandboxes based on the pool capacity before the change during concurrency capacity maintenance, achieving dynamic maintenance of the sandbox validity status and sandbox pool capacity, and improving the sandbox pool's ability to continuously provide available sandboxes.
[0063] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool is provided, wherein the validity period information includes the expiration time of the sandbox; the sandbox acquisition order is determined according to the validity period information corresponding to each sandbox, including: sorting the sandboxes in the sandbox pool according to the expiration time corresponding to each sandbox, so that the sandboxes with earlier expiration times are acquired before the sandboxes with later expiration times.
[0064] Specifically, the expiration information includes the expiration time of the sandbox, which indicates the end date of the sandbox's validity period. When a sandbox is added to the sandbox pool, its expiration time is recorded, and the sandboxes in the sandbox pool are sorted based on their expiration times, so that different sandboxes form a corresponding sandbox acquisition order in the sandbox pool.
[0065] When determining the order in which sandboxes are acquired, sandboxes with earlier expiration dates are placed before those with later expiration dates, giving them higher acquisition priority. If sandboxes in the sandbox pool have different expiration dates, the order in which they are acquired is determined based on their expiration dates.
[0066] This embodiment sorts the sandboxes in the sandbox pool according to their expiration time, so that sandboxes with earlier expiration times are acquired first, reducing the chance of sandboxes with earlier expiration times expiring due to prolonged stay in the sandbox pool, and improving the utilization efficiency of pre-created sandboxes.
[0067] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool includes the following validity period maintenance triggering conditions: reaching a preset validity period maintenance cycle; performing validity period detection on sandboxes in the sandbox pool; and updating the validity period and corresponding validity period information of sandboxes when the validity period update conditions are met, including: obtaining the remaining validity period of unexpired sandboxes in the sandbox pool; extending the validity period of the corresponding sandbox by calling the validity period update interface provided by the sandbox service when the remaining validity period is less than a preset validity period threshold; obtaining the expiration time of the sandbox after the update, and synchronously updating the validity period information corresponding to the sandbox in the distributed storage cluster according to the updated expiration time; and synchronously updating the sorting score of the sandbox in the ordered set according to the updated expiration time when the sandbox pool adopts ordered set storage and uses the expiration timestamp of the sandbox as the sorting score.
[0068] Specifically, the validity period maintenance triggering conditions include reaching a preset validity period maintenance cycle. When the preset validity period maintenance cycle is reached, the validity period of the sandboxes in the sandbox pool is checked. The validity period maintenance cycle can be set according to the validity period of the sandboxes. In this embodiment, validity period maintenance can be triggered once every 5 minutes to obtain the remaining validity period of the sandboxes that have not expired in the sandbox pool, and determine whether the corresponding sandbox meets the validity period update conditions based on the remaining validity period.
[0069] If the remaining validity period of a sandbox is less than a preset validity period threshold, the sandbox is determined to meet the validity period update condition, and the validity period update interface provided by the sandbox service is called to extend the validity period of the corresponding sandbox. In this embodiment, the preset validity period threshold can be set to 10 minutes. When the remaining validity period of a sandbox is less than 10 minutes, the validity period of the sandbox is updated.
[0070] After the sandbox's expiration date is updated, the updated expiration time is obtained, and the corresponding expiration information is synchronously updated based on the updated expiration time, ensuring that the actual expiration time of the sandbox instance is consistent with the expiration time recorded in the distributed storage cluster. When using an ordered set to store the sandboxes in the sandbox pool, and using the expiration timestamp of each sandbox as a sorting score, the sorting score of the sandbox in the ordered set is also synchronously updated based on the updated expiration time, ensuring that the subsequent sandbox acquisition order is determined based on the updated expiration time.
[0071] This embodiment extends the validity period of sandbox instances by calling the validity period update interface, and synchronously updates the corresponding validity period information and the sorting score in the ordered set according to the updated expiration time. This ensures that the actual expiration time of the sandbox instance, the stored validity period information, and the sorting information used to determine the order of sandbox acquisition are consistent, reducing the situation where inconsistent expiration times recorded in different positions after the validity period update affect the judgment of the sandbox's valid status and the order of acquisition.
[0072] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool is provided. The capacity maintenance triggering condition includes reaching a preset capacity maintenance cycle; obtaining concurrent control permissions for the sandbox pool, and redetermining the current pool capacity after obtaining concurrent control permissions, including: obtaining a distributed lock corresponding to the sandbox pool; after obtaining the distributed lock, re-obtaining the number of pre-created sandboxes in the sandbox pool that are in a user-obtainable state, and determining the current pool capacity based on the re-obtained number of pre-created sandboxes.
[0073] Specifically, under the condition that the preset capacity maintenance triggering conditions are met, the sandbox pool's capacity is maintained. The number of pre-created sandboxes that have been created and added to the sandbox pool and are in a state where they are available for user acquisition is obtained, and this number is determined as the current pool capacity. Simultaneously, the target pool capacity corresponding to this sandbox pool is obtained. Sandboxes that have already been acquired by users from the sandbox pool are not included in the current pool capacity, nor are sandboxes that are being created but not yet added to the sandbox pool. The target pool capacity represents the number of pre-created sandboxes that are expected to remain in a state where they are available for user acquisition in the sandbox pool.
[0074] When the current pool capacity is less than the target pool capacity, acquire the distributed lock corresponding to the sandbox pool. After acquiring the distributed lock, reacquire the number of pre-created sandboxes in the sandbox pool that are available for user acquisition, and determine the current pool capacity based on the reacquired number, so that subsequent sandbox replenishment is based on the actual number of pre-created sandboxes available after acquiring the distributed lock.
[0075] This embodiment performs capacity maintenance on the sandbox pool when a preset capacity maintenance cycle is reached, and reacquires the number of sandboxes in the sandbox pool after obtaining the distributed lock. This allows the current pool capacity to reflect the sandbox pool capacity status after obtaining concurrent control authority, reducing the need for subsequent processing based on the pool capacity before the change during concurrent capacity maintenance and improving the accuracy of sandbox pool capacity maintenance.
[0076] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool is provided, which creates sandboxes based on the difference between the redefined current pool capacity and the target pool capacity, and adds the created sandboxes to the sandbox pool after creation. The method includes: determining the number of sandboxes to be supplemented based on the difference between the target pool capacity and the redefined current pool capacity; creating sandboxes corresponding to the sandbox templates based on the number of sandboxes to be supplemented; after any sandbox is created and added to the sandbox pool, re-acquiring the number of pre-created sandboxes in the sandbox pool that are available for user acquisition, and updating the current pool capacity based on the re-acquired number of pre-created sandboxes; continuing to create sandboxes if the updated current pool capacity is still less than the target pool capacity; and releasing the distributed lock after the sandbox replenishment of the sandbox pool is completed.
[0077] Specifically, the number of sandboxes to be added is determined based on the difference between the target pool capacity and the redefined current pool capacity, and sandboxes corresponding to the sandbox templates are created based on the number of sandboxes to be added. Sandboxes are not included in the current pool capacity while they are being created. After a sandbox is created and added to the corresponding sandbox pool, it is included in the current pool capacity as a pre-created sandbox that is available to users.
[0078] During sandbox replenishment, sandboxes are created according to the number of sandboxes to be replenished. Each time a sandbox is created and added to the sandbox pool, the number of pre-created sandboxes in the pool that are available for user acquisition is retrieved again, and the current pool capacity is updated based on the retrieved number. If the updated current pool capacity is still less than the target pool capacity, sandbox creation continues. The current round of sandbox creation stops when the updated current pool capacity reaches the target pool capacity, or when the preset capacity replenishment stop condition is met. The distributed lock is released after the current round of capacity replenishment ends.
[0079] This embodiment uses the number of pre-created sandboxes in the sandbox pool that are available to users as the current pool capacity, and the desired number of pre-created sandboxes available to users as the target pool capacity. This ensures that capacity detection and replenishment are based on the actual number of pre-created sandboxes available for acquisition. At the same time, sandboxes are only counted in the current pool capacity after they are created and added to the sandbox pool, so that the capacity statistics correspond to the actual availability of sandboxes, thus improving the accuracy of sandbox pool capacity maintenance.
[0080] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool is provided, which retrieves a target sandbox in a valid state from the sandbox pool according to the sandbox acquisition order and removes the target sandbox from the sandbox pool. The method includes: retrieving a sandbox to be verified from the sandbox pool according to the sandbox acquisition order; determining whether the sandbox to be verified has expired based on its corresponding expiration time; if the sandbox to be verified has not expired, identifying it as the target sandbox and removing it from the sandbox pool; if the sandbox to be verified has expired, calling the sandbox deletion interface provided by the sandbox service to destroy the actual sandbox instance corresponding to the sandbox to be verified, clearing the expiration information and related status information of the sandbox to be verified, and continuing to retrieve the next sandbox from the sandbox pool according to the sandbox acquisition order.
[0081] In one embodiment of the present invention, after the target sandbox is removed from the sandbox pool, the target sandbox is provided to the requester who requested the sandbox acquisition request; after the requester finishes using the target sandbox, the sandbox deletion interface provided by the sandbox service is called to destroy the actual sandbox instance corresponding to the target sandbox, and the target sandbox is not added back to the sandbox pool.
[0082] Specifically, sandboxes to be verified are retrieved from the sandbox pool in the order they were acquired, and their corresponding expiration times are obtained. The expiration time of each sandbox is compared with the current time to determine if it has expired. If the sandbox has not expired, it is designated as the target sandbox and removed from the sandbox pool, changing its status from available in the pool to being in use by the user. After removal, the target sandbox is no longer counted in the current pool capacity. Following removal, the target sandbox's identifier and usage status are written to the "Used Sandbox Record" in the distributed storage cluster. This "Used Sandbox Record" indicates that the corresponding sandbox has been acquired by the requester and has not yet been used, and is used to distinguish between pre-created sandboxes still in the sandbox pool and sandboxes already acquired by the requester when the system restarts.
[0083] If a sandbox to be verified has expired, it will not be provided to the requester as a target sandbox. Instead, the sandbox deletion interface provided by the sandbox service will be called to destroy the actual sandbox instance corresponding to the sandbox to be verified, and the expiration information and related status information of the sandbox to be verified will be cleared from the distributed storage cluster. After the cleanup is completed, the next sandbox will be retrieved from the sandbox pool according to the sandbox acquisition order, and the expiration status of the next sandbox will be verified until an unexpired target sandbox is obtained or it is determined that there is no sandbox in a valid state in the sandbox pool. During the period when the requester uses the target sandbox, the target sandbox remains outside the sandbox pool and will not be re-added to the sandbox pool, nor will it be used as a pre-created sandbox available for other requests to obtain. After the requester finishes using the target sandbox, the sandbox deletion interface provided by the sandbox service will be called to destroy the actual sandbox instance corresponding to the target sandbox, release the runtime resources occupied by the sandbox instance, and the target sandbox will not be re-added to the sandbox pool after use. After the actual sandbox instance corresponding to the target sandbox is destroyed, the validity period information, usage status information, and related metadata of the target sandbox in the distributed storage cluster are cleaned up to prevent the destroyed sandbox instance from leaving corresponding records in the distributed storage cluster. Thus, the pre-created sandbox is used only once, following the process of creation and addition to the sandbox pool, retrieval and removal from the sandbox pool, provision to the requester for use, and destruction after use.
[0084] This embodiment verifies the expiration status of sandboxes acquired in the order of acquisition, ensuring that sandboxes in a valid state are provided to the requester as target sandboxes. By removing target sandboxes from the sandbox pool after acquisition and no longer counting them in the current pool capacity, the pool capacity corresponds to the actual number of pre-created sandboxes in a state where they can be acquired by users. By destroying target sandboxes after the requester finishes using them and not adding them back to the sandbox pool, the one-time use process of sandboxes is clearly defined, preventing used sandboxes from re-entering the sandbox pool, thereby maintaining the consistency between the pre-created sandboxes in the pool and their available state.
[0085] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool is provided. If a target sandbox in a valid state is not obtained from the sandbox pool according to the sandbox acquisition request, an asynchronous sandbox replenishment task is triggered for the sandbox pool, and an on-demand sandbox is created for the sandbox acquisition request. The sandbox identifier of the on-demand sandbox is returned to the requester of the sandbox acquisition request.
[0086] The asynchronous sandbox replenishment task and the periodic capacity maintenance task use the same concurrency control method. Before creating a pre-created sandbox, the asynchronous sandbox replenishment task acquires the distributed lock of the corresponding sandbox pool. After acquiring the distributed lock, it redetermines the current pool capacity and performs sandbox replenishment based on the difference between the redetermined current pool capacity and the target pool capacity. Therefore, when multiple sandbox acquisition requests simultaneously trigger the asynchronous sandbox replenishment task, multiple replenishment tasks will not repeatedly create sandboxes based on the same old pool capacity.
[0087] In one embodiment of the present invention, creating an on-demand sandbox for a sandbox acquisition request includes: calling the sandbox creation interface provided by the sandbox service to create an on-demand sandbox; setting the validity period of the on-demand sandbox according to the timeout time corresponding to the sandbox acquisition request; and setting metadata for the on-demand sandbox to characterize the creation method of the on-demand sandbox.
[0088] Specifically, if a target sandbox in a valid state is not obtained from the sandbox pool according to the sandbox acquisition request, an asynchronous sandbox replenishment task is triggered for the sandbox pool to replenish the sandboxes in the sandbox pool; at the same time, an on-demand sandbox is created for the current sandbox acquisition request, so that the current sandbox acquisition request does not need to wait for the asynchronous sandbox replenishment task to complete, and after the on-demand sandbox is created, the sandbox identifier of the on-demand sandbox is returned to the requester of the sandbox acquisition request.
[0089] When creating an on-demand sandbox in response to a current sandbox retrieval request, the sandbox creation interface provided by the sandbox service is called to create the on-demand sandbox and obtain the timeout corresponding to the sandbox retrieval request. The validity period of the on-demand sandbox is then set based on the timeout. During the on-demand sandbox creation process, metadata is set for the on-demand sandbox to characterize its creation method, recording that the sandbox is created on demand in response to the sandbox retrieval request.
[0090] This embodiment triggers an asynchronous sandbox replenishment task when no valid target sandbox is obtained from the sandbox pool, and creates an on-demand sandbox for the current sandbox acquisition request. This allows the current sandbox acquisition request to obtain an available sandbox through on-demand creation, while asynchronously replenishing the sandbox pool, thereby improving the continuity of sandbox services when the sandbox pool is temporarily unable to provide a valid sandbox.
[0091] According to the dynamic maintenance method of the pre-created sandbox pool provided by the present invention, during the process of checking the validity period of sandboxes in the sandbox pool, if a sandbox has expired, the sandbox deletion interface provided by the sandbox service is called to destroy the expired sandbox instance, the expired sandbox is deleted from the sandbox pool, and the validity period information corresponding to the expired sandbox is cleared.
[0092] Specifically, during the expiration check of sandboxes in the sandbox pool, the expiration information of the corresponding sandbox is obtained, and it is determined whether the sandbox has expired based on the expiration information. If the sandbox has been determined to be expired, the sandbox deletion interface provided by the sandbox service is called to send a deletion request to the sandbox service to destroy the actual sandbox instance corresponding to the sandbox, so that the expired sandbox instance no longer occupies the corresponding runtime resources.
[0093] After destroying expired sandbox instances, the expired sandboxes are deleted from the sandbox pool, and the corresponding expiration information is cleared. Specifically, the sandbox pool data and expiration information corresponding to the sandbox in the distributed storage cluster are deleted, so that the sandboxes recorded in the sandbox pool correspond to the actual available sandboxes.
[0094] This embodiment destroys the corresponding actual sandbox instance by calling the sandbox deletion interface when the sandbox is detected to have expired, and simultaneously deletes the relevant data and corresponding expiration information in the sandbox pool. This cleans up the running resources and stored status information occupied by the expired sandbox, reduces the inconsistency between the actual sandbox instance and the sandbox pool record, and improves the accuracy of sandbox pool resource maintenance.
[0095] According to the present invention, a dynamic maintenance method for a pre-created sandbox pool is provided, which uses an ordered set to store the sandboxes in the sandbox pool and uses the expiration timestamp of each sandbox as the sorting score of the corresponding sandbox; and retrieves the corresponding sandbox from the ordered set in ascending order of sorting score.
[0096] Specifically, an ordered set is used to store the sandboxes in the sandbox pool. The sandbox identifier is used as a member of the ordered set, and the expiration timestamp of each sandbox is used as its sorting score. This sorts the sandboxes in the sandbox pool according to their expiration timestamps. The earlier the sandbox expires, the lower its sorting score; the later the sandbox expires, the higher its sorting score.
[0097] When retrieving sandboxes from the sandbox pool, the corresponding sandboxes are retrieved from the ordered set in ascending order of their sorted scores, ensuring that sandboxes with earlier expiration times are retrieved before those with later expiration times. In practice, this can be achieved by using the minimum sorted score member retrieval operation provided by the ordered set to obtain the sandbox with the smallest current sorted score.
[0098] This embodiment uses ordered sets to store the sandboxes in the sandbox pool and uses the expiration timestamp of the sandbox as the sorting score, so that the sandboxes can be stored and retrieved in an orderly manner according to their expiration time. This makes it easier to prioritize the retrieval of sandboxes with earlier expiration times and improve the utilization efficiency of pre-created sandboxes in the sandbox pool.
[0099] In one embodiment of the present invention, a plurality of sandbox templates are included, and different sandbox templates correspond to different sandbox pools; the target pool capacity corresponding to each sandbox template is obtained, and a corresponding sandbox is pre-created according to the target pool capacity corresponding to each sandbox template; when a sandbox acquisition request is received, the corresponding target sandbox pool is determined according to the sandbox template information carried in the sandbox acquisition request, and the target sandbox is acquired from the target sandbox pool.
[0100] Specifically, there are multiple sandbox templates, each corresponding to a different sandbox pool. The target pool capacity for each sandbox template is obtained, and corresponding sandboxes are pre-created according to the target pool capacity of each sandbox template. The created sandboxes are then added to their respective sandbox pools, so that each sandbox template has a sandbox pool for providing its corresponding sandbox.
[0101] Upon receiving a sandbox acquisition request, the sandbox template information carried in the sandbox acquisition request is obtained, and the target sandbox pool corresponding to it is determined based on the sandbox template information. The target sandbox is then acquired from the target sandbox pool so that the acquired target sandbox corresponds to the sandbox template specified in the sandbox acquisition request.
[0102] This embodiment establishes corresponding sandbox pools for different sandbox templates and pre-creates sandboxes according to the target pool capacity of each sandbox template, so that sandboxes corresponding to different sandbox templates can be pooled and managed separately; after receiving a sandbox acquisition request, the target sandbox is obtained from the corresponding target sandbox pool according to the sandbox template information, thereby improving the matching between the sandbox acquisition request and the pre-created sandbox.
[0103] In one embodiment of the present invention, a distributed storage cluster is used to store the pool data of the sandbox pool and the validity period information corresponding to each sandbox, wherein an ordered set is used to store the pool data and a hash structure is used to store the validity period information corresponding to each sandbox.
[0104] Specifically, a distributed storage cluster is used to store the pool data of the sandbox pool and the validity period information of each sandbox separately. The data used to record the sandboxes in the sandbox pool and the data used to record the validity period of the sandboxes are stored separately. Among them, an ordered set is used to store the pool data of the sandbox pool, so that each sandbox can be stored as a member of the ordered set; a hash structure is used to store the validity period information of each sandbox, so that the sandbox is associated with its corresponding validity period information.
[0105] When a sandbox is added to a sandbox pool, the corresponding pool data is written to an ordered set, and the expiration information of the sandbox is written to a hash structure. When the expiration information of a sandbox is updated, the expiration information of the sandbox in the hash structure is updated synchronously, so that the distributed storage cluster can save the pool data of the sandbox pool and the expiration information of the sandbox respectively.
[0106] This embodiment uses a distributed storage cluster to store the pool data of the sandbox pool and the validity information of each sandbox, and uses ordered sets and hash structures to store the two types of data respectively, which facilitates the management of sandboxes and their validity information in the sandbox pool, and provides corresponding data support for sandbox scheduling and validity maintenance in the sandbox pool.
[0107] The technical solution of the present invention will be further illustrated below through overall embodiments.
[0108] This invention provides an E2B pre-creation pooling management method to solve the problem of sandbox cold start. Through pre-creation and automatic maintenance mechanisms, it avoids sandbox cold start and improves resource utilization efficiency.
[0109] The technical solution to achieve this invention is: an E2B pre-creation pooling management method for solving sandbox cold start, comprising the following steps: ① System startup, loading configuration: parsing the WARMUP_TEMPLATES environment variable, setting default parameters, and connecting RedisCluster and E2BAPIService; ② Initialize the managers: Create instances of WarmupManager, KeepAliveManager, and ReplenishManager; ③ Clean up old data: Upon system restart, read the sandbox pool data and sandbox records in use from Redis Cluster. For sandboxes identified by the sandbox records in use that were acquired by the requester before the system restart and have not yet finished using, no destruction operation is performed, allowing the sandbox to continue operating normally after the system restart. For pre-created sandboxes still recorded in the sandbox pool at the time of system restart, call the sandbox deletion interface provided by the sandbox service to destroy the corresponding actual sandbox instance, and delete the sandbox pool data and expiration information corresponding to the pre-created sandbox in Redis Cluster. For sandboxes with missing or inconsistent status information, record the exception information and handle it according to the preset exception handling strategy. ④ Start background tasks: Start KeepAliveManager (triggered every 5 minutes) and ReplenishManager (triggered every 30 seconds); ⑤ Initialize the sandbox pool: Create a sandbox for each configuration template until the target pool size is reached; ⑥ Start API service: Start HTTPAPIServer and listen on the preset port; ⑦ When a user initiates a sandbox access request, the APIClient receives and submits it to the WarmupService; ⑧WarmupService parses the parameters and verifies their validity, then retrieves the corresponding number of sandboxes from the RedisCluster sandbox pool; ⑨ Determine whether the sandbox was successfully acquired. If yes, update the TTL and return the sandbox ID. Otherwise, trigger an asynchronous supplementary task and execute on-demand creation. ⑩ Create a sandbox as needed and set its metadata. Return the new sandbox ID, and the process ends.
[0110] The sandbox acquisition in step ⑧ specifically involves: I. Call the ZPopMin command of RedisCluster to retrieve sandboxes by expiration time; II. Check if the sandbox has expired; III. If it has not expired, proceed to step 9; if it has expired, retrieve it again from the pool.
[0111] The TTL update in step ⑨ specifically involves: I. Call the UpdateTTL interface of E2BAPIService; II. Synchronously modify the end_time field of the sandbox in RedisCluster; III. Return the updated sandbox ID to the APIClient.
[0112] The on-demand creation in step 9 specifically refers to: I. Call the CreateSandbox interface of E2BAPIService; II. Set metadata to {warmup:true,on_demand:true}; III. Return the newly created sandbox ID to the APIClient.
[0113] The KeepAliveManager task in step ④ is as follows: I. Traverse all configuration templates; II. Obtain the list of sandboxes under each template and the validity period information of each sandbox; III. Check the sandbox TTL. If the sandbox has not expired and the remaining validity period is less than 10 minutes, call the UpdateTTL interface to update the validity period of the sandbox instance and synchronously update the end_time field and sorted set score in RedisCluster. If the sandbox has expired, call the sandbox deletion interface of E2BAPIService to destroy the corresponding actual sandbox instance and delete the sandbox from the sandbox pool. IV. Clean up all expired sandbox records in RedisCluster.
[0114] The ReplenishManager task in step ④ is as follows: I. Traverse all configuration templates; II. Obtain the current pool size and the target pool size, and calculate the amount that needs to be replenished; III. Acquire the Redis distributed lock and check the pool size again; IV. The E2BAPIService is called repeatedly to create sandboxes. After any sandbox is created and added to the sandbox pool, the current pool capacity is retrieved again. The current pool capacity stops when the current pool capacity reaches the target pool size. When sandbox creation fails, the error information is recorded, and creation is re-initiated before the preset number of retries is reached. The current round of replenishment stops after the preset number of retries is reached, and the unfinished sandbox replenishment is left for processing in the next capacity maintenance cycle. V. The distributed lock is released when the current sandbox replenishment is successfully completed, the preset number of retries is reached, or other preset stopping conditions occur. The distributed lock release operation is set during the end processing of this round of capacity replenishment task so that the distributed lock can still be released if an exception occurs during the sandbox creation process.
[0115] The default parameters in step ① include the target pool size, KeepAlive refresh interval of 5 minutes, and Replenish replenishment interval of 30 seconds.
[0116] In step ⑦, the user request supports six types of API interfaces, including POST / warmup / start for configuring templates and GET / warmup / acquire for obtaining the sandbox.
[0117] In step I, Redis's ZPopMin command implements priority scheduling based on the sandbox expiration time, with the score being the sandbox expiration timestamp.
[0118] The distributed lock in step III is implemented based on RedisCluster to avoid multiple capacity replenishment tasks creating sandboxes at the same time and prevent duplicate replenishment.
[0119] The timeout in step 9 is 3600 seconds by default, but can be customized via API request parameters.
[0120] Figure 2 This is a schematic diagram of the architecture of the E2B pre-created pooling management system of the present invention, including the following steps: ①The APIClient (SDK / HTTP) initiates a target request. The request types include template configuration, sandbox retrieval, status query, etc., and carry parameters (template ID, number of requests, timeout, etc.).
[0121] ②The HTTPAPIServer listens on port 8080, receives requests from APIClient, parses the request parameters, and verifies their validity.
[0122] ③ After successful verification, the HTTPAPIServer forwards the request to the WarmupManager, which then performs sandbox acquisition, sandbox usage termination processing, or template configuration (add / delete / query) operations.
[0123] ④ KeepAliveManager triggers every 5 minutes, iterates through all configured templates, queries the list of sandboxes in RedisCluster and the validity period information of each sandbox, and checks the TTL of each sandbox based on the validity period information. If the sandbox has not expired and the remaining validity period is less than 10 minutes, it calls the UpdateTTL interface of E2BAPIService to extend the validity period of the sandbox instance, and synchronously updates the end_time field of the sandbox in RedisCluster and the sorting score in the sorted set. If the sandbox has expired, it calls the sandbox deletion interface of E2BAPIService to destroy the corresponding actual sandbox instance, deletes the sandbox from the sandbox pool, and cleans up the corresponding sandbox pool data, validity period information and related status information in RedisCluster.
[0124] ⑤ ReplenishManager triggers every 30 seconds, iterates through all configured templates, queries the current pool capacity and target pool capacity through RedisCluster, and attempts to acquire the Redis distributed lock for the corresponding sandbox pool when the current pool capacity is less than the target pool capacity. After acquiring the distributed lock, it queries the current pool capacity again and determines the number of sandboxes to be replenished based on the difference between the current pool capacity and the target pool capacity. It calls the CreateSandbox interface of E2BAPIService in a loop to create sandboxes. After any sandbox is created and added to the sandbox pool, it queries the current pool capacity again. It stops the current replenishment when the current pool capacity reaches the target pool capacity. It records error information when creation fails and re-initiates creation if the preset number of retries has not been reached. After the preset number of retries has been reached, it stops the current replenishment and leaves the unfinished replenishment tasks for the next capacity maintenance cycle. It releases the distributed lock when the current replenishment is completed, the maximum number of retries has been reached, or it stops due to other conditions.
[0125] ⑥ WarmupManager interacts bidirectionally with RedisCluster. It obtains sandbox IDs by sorting them by expiration time using PoolStorage (SortedSet), and queries the sandbox expiration time and remaining duration using TTLStorage (Hash). It uses DistributedLock to prevent multiple capacity replenishment tasks from being executed simultaneously and to prevent multiple capacity replenishment tasks from repeatedly creating sandboxes based on the same old pool capacity. The sandbox acquisition operation does not require obtaining the DistributedLock as an execution condition.
[0126] ⑦ If a sandbox is successfully retrieved from the sandbox pool, WarmupManager calls the UpdateTTL interface of E2BAPIService to update the sandbox's expiration time and returns the sandbox ID to APIClient; if the sandbox pool is empty, ReplenishManager is triggered to asynchronously replenish the sandbox, and at the same time, the CreateSandbox interface of E2BAPIService is called to create a sandbox as needed, setting metadata to {warmup:true,on_demand:true}, and returning the newly created sandbox ID to APIClient.
[0127] ⑧E2BAPIService receives relevant call commands and performs underlying operations such as CreateSandbox (create pre / on-demand sandbox), UpdateTTL (extend sandbox validity period), and DeleteSandbox (delete expired / invalid / used sandboxes) to generate usable sandbox instances.
[0128] ⑨ After the sandbox instance (pre-created / on-demand created) is initialized, it is available for users to perform subsequent operations such as code execution and tool invocation.
[0129] This invention achieves rapid acquisition of available sandboxes by pre-creating sandboxes and forming sandbox pools, enabling sandboxes to complete corresponding resource initialization in advance and scheduling sandboxes based on their validity information. It also achieves continuous maintenance of the effective status of sandboxes in the pool by periodically checking and updating sandbox validity and cleaning up expired sandboxes. Furthermore, it achieves dynamic maintenance of sandbox pool capacity by periodically checking the sandbox pool capacity and supplementing insufficient sandbox pools with concurrency control, reducing the need for repeated sandbox replenishment under concurrent conditions. By establishing corresponding sandbox pools for different sandbox templates, it achieves pooled management of sandbox resources under different operating environments. By creating and asynchronously replenishing sandbox pools on demand when no effective sandboxes are available, it achieves continuous service when the sandbox pool cannot provide effective sandboxes temporarily. Finally, by storing sandbox pool data and validity information through a distributed storage cluster, it achieves unified management of sandbox pool resources and their status information, improving the utilization efficiency of sandbox resources and the stability of sandbox pool operation.
[0130] The dynamic maintenance device for the pre-created sandbox pool provided by the present invention will be described below. The dynamic maintenance device for the pre-created sandbox pool described below can be referred to in correspondence with the dynamic maintenance method for the pre-created sandbox pool described above.
[0131] like Figure 3 The image shows a dynamic maintenance device for a pre-created sandbox pool provided by the present invention, comprising: The sandbox pool initialization module 310 is used to pre-create multiple sandboxes to form a sandbox pool based on the sandbox template, and to obtain the validity period information of each sandbox. The sandbox scheduling module 320 is used to determine the sandbox acquisition order based on the validity period information of each sandbox. When a sandbox acquisition request is received, the module acquires the target sandbox that is in a valid state from the sandbox pool according to the sandbox acquisition order and removes the target sandbox from the sandbox pool. The validity period maintenance module 330 is used to check the validity period of sandboxes in the sandbox pool when the preset validity period maintenance trigger conditions are met, and to update the validity period of sandboxes and corresponding validity period information when the validity period update conditions are met. The capacity detection module 340 is used to obtain the number of pre-created sandboxes in the sandbox pool that are in a user-accessible state as the current pool capacity when the preset capacity maintenance triggering conditions are met, and to obtain the target pool capacity corresponding to the sandbox pool. The target pool capacity is used to characterize the number of pre-created sandboxes in the sandbox pool that are expected to be in a user-accessible state. If the current pool capacity is less than the target pool capacity, the module obtains the concurrency control permission for the sandbox pool, and redetermines the current pool capacity after obtaining the concurrency control permission. The capacity replenishment module 350 is used to create sandboxes based on the difference between the redefined current pool capacity and the target pool capacity, and to add the created sandboxes to the sandbox pool after the sandboxes are created.
[0132] In one embodiment of the present invention, an E2B pre-creation pooling management system is provided to solve the problem of sandbox cold start, enabling sandbox acquisition in seconds, alleviating high-concurrency resource competition, and improving service response speed and stability.
[0133] The specific solution is: an E2B pre-created pooled management system that solves the problem of sandbox cold start, including APIClient, Warmup Service, Redis Cluster and E2B API Service. API Client receives user requests, Warmup Service is responsible for sandbox pool management and maintenance, Redis Cluster stores pool data and status information, and E2B API Service provides underlying sandbox operation support.
[0134] The API Client supports making requests via SDK or HTTP protocol, and adapts to operations such as template configuration and sandbox acquisition.
[0135] Warmup Service integrates HTTP API Server, Warmup Manager, KeepAlive Manager, and Replenish Manager. The HTTP API Server listens on port 8080 by default.
[0136] Redis Cluster uses Sorted Sets to store sandbox pool data and Hash to store TTL information, while also providing distributed lock functionality.
[0137] The E2B API Service supports sandbox creation, TTL update, and deletion operations.
[0138] Specifically, the functions of each module in the dynamic maintenance device for the pre-created sandbox pool provided in this embodiment of the invention correspond one-to-one with the operation flow of each step in the above-mentioned method-like embodiments, and the achieved effects are also the same. For details, please refer to the above embodiments, and this will not be repeated in this embodiment of the invention.
[0139] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communication interface 420, and the memory 430 communicate with each other through the communication bus 440. The processor 410 can call logical instructions in the memory 430 to execute a dynamic maintenance method for a pre-created sandbox pool. This method includes: pre-creating multiple sandboxes to form a sandbox pool according to a sandbox template, and obtaining the validity period information corresponding to each sandbox; determining the sandbox acquisition order according to the validity period information corresponding to each sandbox; upon receiving a sandbox acquisition request, acquiring a target sandbox in a valid state from the sandbox pool according to the sandbox acquisition order, and removing the target sandbox from the sandbox pool; and, under the condition that a preset validity period maintenance trigger condition is met, performing a validity period check on the sandboxes in the sandbox pool, and updating the validity period of the sandbox if the sandbox meets the validity period update condition. The system retrieves the current sandbox capacity and its corresponding validity period information. Under the condition that the preset capacity maintenance triggering conditions are met, it obtains the number of pre-created sandboxes in the sandbox pool that are in a user-accessible state as the current pool capacity, and obtains the target pool capacity corresponding to the sandbox pool. The target pool capacity is used to characterize the number of pre-created sandboxes in the sandbox pool that are expected to remain in a user-accessible state. If the current pool capacity is less than the target pool capacity, it obtains concurrency control permissions for the sandbox pool and redetermines the current pool capacity after obtaining concurrency control permissions. It creates sandboxes based on the difference between the redetermined current pool capacity and the target pool capacity, and adds the created sandboxes to the sandbox pool after creation.
[0140] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0141] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute a dynamic maintenance method for a pre-created sandbox pool provided by the above methods. The method includes: pre-creating multiple sandboxes to form a sandbox pool according to a sandbox template, and obtaining the validity period information corresponding to each sandbox; determining the sandbox acquisition order according to the validity period information corresponding to each sandbox; upon receiving a sandbox acquisition request, acquiring a target sandbox in a valid state from the sandbox pool according to the sandbox acquisition order, and removing the target sandbox from the sandbox pool; and, under the condition of satisfying a preset validity period maintenance triggering condition, performing maintenance on the sandboxes in the sandbox pool. The system performs an expiration check. If the sandbox meets the expiration update conditions, it updates the sandbox's expiration date and corresponding expiration information. If the preset capacity maintenance trigger conditions are met, it obtains the number of pre-created sandboxes in the sandbox pool that are in a user-accessible state as the current pool capacity, and obtains the target pool capacity corresponding to the sandbox pool. The target pool capacity is used to represent the number of pre-created sandboxes in the sandbox pool that are expected to remain in a user-accessible state. If the current pool capacity is less than the target pool capacity, it obtains concurrency control permissions for the sandbox pool and redetermines the current pool capacity after obtaining concurrency control permissions. It creates sandboxes based on the difference between the redetermined current pool capacity and the target pool capacity, and adds the created sandboxes to the sandbox pool after creation.
[0142] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements a dynamic maintenance method for a pre-created sandbox pool provided by the methods described above. This method includes: pre-creating multiple sandboxes to form a sandbox pool based on a sandbox template, and obtaining validity period information corresponding to each sandbox; determining the sandbox acquisition order based on the validity period information corresponding to each sandbox; upon receiving a sandbox acquisition request, acquiring a target sandbox in a valid state from the sandbox pool according to the sandbox acquisition order, and removing the target sandbox from the sandbox pool; and, under the condition that a preset validity period maintenance triggering condition is met, performing validity period detection on the sandboxes in the sandbox pool, and removing the target sandbox from the sandbox pool if the sandbox meets the validity period maintenance triggering condition. Under the condition of periodic update, update the validity period of the sandbox and the corresponding validity period information; under the condition of meeting the preset capacity maintenance triggering condition, obtain the number of pre-created sandboxes in the sandbox pool that are in a user-accessible state as the current pool capacity, and obtain the target pool capacity corresponding to the sandbox pool. The target pool capacity is used to represent the number of pre-created sandboxes in the sandbox pool that are expected to be in a user-accessible state. If the current pool capacity is less than the target pool capacity, obtain the concurrency control permission for the sandbox pool, and redetermine the current pool capacity after obtaining the concurrency control permission; create sandboxes according to the difference between the redetermined current pool capacity and the target pool capacity, and add the created sandboxes to the sandbox pool after the sandboxes are created.
[0143] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0144] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of various embodiments or some parts of embodiments.
[0145] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for dynamic maintenance of a pre-created sandbox pool, characterized in that, include: Multiple sandboxes are pre-created based on the sandbox template to form a sandbox pool, and the validity period information of each sandbox is obtained. The order of obtaining sandboxes is determined based on the validity period information of each sandbox. When a sandbox obtaining request is received, a target sandbox in a valid state is obtained from the sandbox pool according to the sandbox obtaining order, and the target sandbox is removed from the sandbox pool. Under the condition that the preset validity period maintenance triggering condition is met, the validity period of the sandbox in the sandbox pool is checked. If the validity period update condition is met, the validity period of the sandbox and the corresponding validity period information are updated. If the preset capacity maintenance triggering conditions are met, the number of pre-created sandboxes in the sandbox pool that are in a user-accessible state is obtained as the current pool capacity, and the target pool capacity corresponding to the sandbox pool is obtained. The target pool capacity is used to characterize the number of pre-created sandboxes in the sandbox pool that are expected to be in a user-accessible state. If the current pool capacity is less than the target pool capacity, the concurrency control permission for the sandbox pool is obtained, and the current pool capacity is re-determined after obtaining the concurrency control permission. A sandbox is created based on the difference between the redefined current pool capacity and the target pool capacity, and the created sandbox is added to the sandbox pool after creation.
2. The dynamic maintenance method for the pre-created sandbox pool according to claim 1, characterized in that, The validity period information includes the expiration time of the sandbox; The step of determining the order of acquiring sandboxes based on the validity period information of each sandbox includes: The sandboxes in the sandbox pool are sorted according to their expiration time, so that sandboxes with earlier expiration times are acquired before sandboxes with later expiration times.
3. The dynamic maintenance method for the pre-created sandbox pool according to claim 1, characterized in that, The validity period maintenance triggering condition includes reaching a preset validity period maintenance cycle; The step of checking the expiration date of the sandboxes in the sandbox pool, and updating the expiration date and corresponding expiration information of the sandboxes when they meet the expiration date update conditions, includes: Obtain the remaining valid duration of the sandboxes that have not expired in the sandbox pool; If the remaining valid duration is less than the preset valid duration threshold, the validity period of the corresponding sandbox is extended by calling the validity period update interface provided by the sandbox service. Obtain the updated expiration time of the sandbox, and synchronously update the validity information of the corresponding sandbox in the distributed storage cluster according to the updated expiration time; when the sandbox pool adopts ordered set storage and uses the expiration timestamp of the sandbox as the sorting score, synchronously update the sorting score of the sandbox in the ordered set according to the updated expiration time.
4. The dynamic maintenance method for the pre-created sandbox pool according to claim 1, characterized in that, The capacity maintenance triggering conditions include reaching a preset capacity maintenance cycle; The step of obtaining concurrency control permissions for the sandbox pool and, after obtaining the concurrency control permissions, re-determining the current pool capacity includes: Obtain the distributed lock corresponding to the sandbox pool; After acquiring the distributed lock, the number of pre-created sandboxes in the sandbox pool that are in a state where they can be acquired by users is retrieved again, and the current pool capacity is determined based on the number of pre-created sandboxes retrieved again.
5. The dynamic maintenance method for the pre-created sandbox pool according to claim 4, characterized in that, The step of creating a sandbox based on the difference between the redefined current pool capacity and the target pool capacity, and adding the created sandbox to the sandbox pool after creation, includes: The number of sandboxes to be replenished is determined based on the difference between the target pool capacity and the redefined current pool capacity. Based on the number of sandboxes to be supplemented, create sandboxes corresponding to the sandbox template. After any sandbox is created and added to the sandbox pool, re-acquire the number of pre-created sandboxes in the sandbox pool that are available to users, and update the current pool capacity based on the re-acquired number of pre-created sandboxes. If the updated current pool capacity is still less than the target pool capacity, continue to create sandboxes. The distributed lock is released after the sandbox pool is replenished.
6. The dynamic maintenance method for the pre-created sandbox pool according to claim 2, characterized in that, The step of acquiring a target sandbox in a valid state from the sandbox pool according to the sandbox acquisition order, and removing the target sandbox from the sandbox pool, includes: The sandboxes to be verified are obtained from the sandbox pool in the order of sandbox acquisition. Determine whether the sandbox to be verified has expired based on the expiration time corresponding to the sandbox to be verified. If the sandbox to be verified has not expired, the sandbox to be verified is identified as the target sandbox, and the target sandbox is removed from the sandbox pool. If the sandbox to be verified has expired, the sandbox deletion interface provided by the sandbox service is called to destroy the sandbox instance corresponding to the sandbox to be verified, clear the expiration information of the sandbox to be verified, and continue to obtain the next sandbox from the sandbox pool according to the sandbox acquisition order.
7. The dynamic maintenance method for pre-created sandbox pools according to claim 1, characterized in that, Also includes: If a target sandbox in a valid state is not obtained from the sandbox pool according to the sandbox acquisition request, an asynchronous sandbox replenishment task is triggered for the sandbox pool, and an on-demand sandbox is created for the sandbox acquisition request. The sandbox identifier of the on-demand sandbox is returned to the requester of the sandbox retrieval request.
8. The dynamic maintenance method for the pre-created sandbox pool according to claim 3, characterized in that, Also includes: During the process of checking the expiration dates of sandboxes in the sandbox pool, if a sandbox has expired, the sandbox deletion interface provided by the sandbox service is called to destroy the expired sandbox instance, delete the expired sandbox from the sandbox pool, and clear the expiration date information corresponding to the expired sandbox.
9. The dynamic maintenance method for the pre-created sandbox pool according to claim 2, characterized in that, The sandboxes in the sandbox pool are stored using an ordered set, and the expiration timestamp of each sandbox is used as the sorting score for that sandbox. The corresponding sandbox is obtained from the ordered set according to the sorting score in ascending order.
10. A dynamic maintenance device for a pre-created sandbox pool, characterized in that, include: The sandbox pool initialization module is used to pre-create multiple sandboxes to form a sandbox pool based on the sandbox template, and to obtain the validity period information of each sandbox. The sandbox scheduling module is used to determine the sandbox acquisition order based on the validity period information of each sandbox. When a sandbox acquisition request is received, the module acquires a target sandbox that is in a valid state from the sandbox pool according to the sandbox acquisition order and removes the target sandbox from the sandbox pool. The validity period maintenance module is used to detect the validity period of sandboxes in the sandbox pool when the preset validity period maintenance trigger conditions are met, and to update the validity period of the sandbox and the corresponding validity period information when the sandbox meets the validity period update conditions. The capacity detection module is used to obtain the number of pre-created sandboxes in the sandbox pool that are in a user-accessible state as the current pool capacity when the preset capacity maintenance triggering conditions are met, and to obtain the target pool capacity corresponding to the sandbox pool. The target pool capacity is used to characterize the number of pre-created sandboxes in the sandbox pool that are expected to be in a user-accessible state. If the current pool capacity is less than the target pool capacity, the module obtains the concurrency control permission for the sandbox pool, and redetermines the current pool capacity after obtaining the concurrency control permission. The capacity replenishment module is used to create a sandbox based on the difference between the redefined current pool capacity and the target pool capacity, and to add the created sandbox to the sandbox pool after the sandbox is created.
11. 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 computer program, it implements the dynamic maintenance method for the pre-created sandbox pool as described in any one of claims 1 to 9.
12. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the dynamic maintenance method for the pre-created sandbox pool as described in any one of claims 1 to 9.
13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the dynamic maintenance method for the pre-created sandbox pool as described in any one of claims 1 to 9.
