Queue control method and device, equipment and medium
By checking the remaining memory in the delay queue and adding tasks that do not meet the criteria to the candidate file, the memory overflow problem caused by the delay queue is solved, and the reliability of the application system is improved.
Patent Information
- Application Number
- CN202411223051.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-02
- Publication Date
- 2024-11-26
AI Technical Summary
Because the delay queue is an unbounded queue, it can easily lead to memory overflow problems, affecting the reliability of the application system.
Before adding a delay task to the queue, check whether the remaining memory meets the preset conditions, add it to the queue if it is satisfied, and add the task to the candidate file of the non-memory storage device if it is not satisfied, avoid memory overflow in this way .
It effectively avoids memory overflow problems caused by adding delayed tasks to the queue, and improves the reliability and stability of the application system.
Smart Images

Figure CN119025282A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of storage technology, and in particular to a queue control method, device, equipment and medium. Background Art
[0002] OOM (Out Of Memory) refers to the situation where there is unreclaimable memory or too much memory in the application system, so that the memory required for program operation is greater than the maximum memory available. At this time, the server system will not be able to run, and sometimes even automatically shut down the software. Restarting the server or system software will release some memory, but due to system configuration, data flow, user code and other reasons, memory overflow errors cannot be avoided even if the user re-executes the task.
[0003] At present, since the delay queue is an unbounded queue, when using the delay queue, it is easy to cause memory overflow problems, affecting the reliability of the application system. Therefore, how to avoid memory overflow problems and improve the reliability of the application system is a problem that needs to be solved urgently. Summary of the invention
[0004] In view of this, the purpose of this application is to provide a queue control method, device, equipment and medium, which can effectively avoid memory overflow and thus improve the reliability of the application system. The specific scheme is as follows:
[0005] In a first aspect, the present application discloses a queue control method, comprising:
[0006] When a new delayed task is obtained, the remaining memory is checked;
[0007] Determining whether a preset task adding condition corresponding to the delay queue is met based on the remaining memory;
[0008] If the preset task adding condition is met, the new delayed task is added to the delayed queue;
[0009] If the preset task adding condition is not met, the new delayed task is added to the candidate file corresponding to the delayed queue, wherein the candidate file is stored in a non-memory storage device.
[0010] Optionally, judging whether a preset task adding condition corresponding to the delay queue is met based on the remaining memory includes:
[0011] Calculating the ratio of the remaining memory to the total memory;
[0012] Determine whether the ratio is greater than or equal to a preset threshold value. If the ratio is greater than or equal to the preset threshold value, determine that the preset task adding condition corresponding to the delay queue is met; otherwise, determine that the preset task adding condition corresponding to the delay queue is not met.
[0013] Optionally, before adding the new delayed task to the candidate file corresponding to the delayed queue, the method further includes:
[0014] Determine whether there is a target delayed task in the delayed queue whose execution time is later than that of the new delayed task;
[0015] If there is no target delayed task whose execution time is later than that of the new delayed task, triggering the step of adding the new delayed task to the candidate file corresponding to the delayed queue;
[0016] If there is a target delayed task whose execution time is later than that of the new delayed task, the target delayed task is deleted from the delayed queue, added to the candidate file, and the new delayed task is added to the delayed queue.
[0017] Optionally, after adding the new delayed task to the delayed queue, the method further includes:
[0018] The persistent file corresponding to the delay queue is updated, wherein the persistent file is used to save the delayed tasks in the delay queue.
[0019] Optionally, also include:
[0020] In response to the queue initialization operation, the delayed task is loaded from the persistent file into the delayed queue.
[0021] Optionally, also include:
[0022] In response to the execution of any delayed task in the delay queue, removing the any delayed task from the delay queue;
[0023] Determine whether there is a candidate delayed task in the candidate file;
[0024] If there are candidate delayed tasks in the candidate file, the candidate delayed tasks are selected from the candidate file and added to the delayed queue.
[0025] Optionally, the selecting a candidate delayed task from the candidate file and adding it to the delayed queue includes:
[0026] A delayed task with the latest execution time is selected from the candidate file and added to the delayed queue.
[0027] In a second aspect, the present application discloses a queue control device, comprising:
[0028] The memory check module is used to check the remaining memory when a new delayed task is obtained;
[0029] A condition judgment module, used for judging whether a preset task adding condition corresponding to the delay queue is met based on the remaining memory;
[0030] A queue adding module, configured to add the new delayed task to the delayed queue if the condition judgment module determines that the preset task adding condition is met;
[0031] The file adding module is used to add the new delayed task to the candidate file corresponding to the delayed queue if the condition judgment module determines that the preset task adding condition is not met, wherein the candidate file is stored in a non-memory storage device.
[0032] In a third aspect, the present application discloses an electronic device, including a memory and a processor, wherein:
[0033] The memory is used to store the computer program;
[0034] The processor is used to execute the computer program to implement the aforementioned queue control method.
[0035] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program, wherein the computer program implements the aforementioned queue control method when executed by a processor.
[0036] It can be seen from the above scheme that the present invention provides a queue control method, including: when a new delayed task is obtained, checking the remaining memory; judging whether the preset task adding condition corresponding to the delay queue is met based on the remaining memory; if the preset task adding condition is met, adding the new delayed task to the delay queue; if the preset task adding condition is not met, adding the new delayed task to the candidate file corresponding to the delay queue, wherein the candidate file is stored in a non-memory storage device.
[0037] It can be seen that the beneficial effects of the present application are: before adding a new delayed task to the delay queue, first check the remaining memory, and if the remaining memory meets the preset task adding conditions corresponding to the delay queue, add the new delayed task to the delay queue; if the remaining memory does not meet the preset task adding conditions, add the new delayed task to the standby file stored in the non-memory storage device. In this way, when adding a delay queue, a memory check is performed first, and the delayed task is added to the delay queue if the remaining memory is sufficient, otherwise it is added to the standby file. This can avoid memory overflow problems caused by adding delayed tasks to the delay queue, thereby improving the reliability of the application system.
[0038] Correspondingly, a queue control device, equipment and readable storage medium provided by the present application also have the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0040] Figure 1 A flow chart of a queue control method provided in an embodiment of the present application;
[0041] Figure 2 A delay queue initialization flow chart provided for an embodiment of the present application;
[0042] Figure 3 A delay queue adding flow chart provided in an embodiment of the present application;
[0043] Figure 4 A flowchart of removing tasks from a delay queue provided in an embodiment of the present application;
[0044] Figure 5 A schematic diagram of the structure of a queue control device provided in an embodiment of the present application;
[0045] Figure 6 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0047] When the memory overflows, the server system will not be able to run, and sometimes it will even automatically shut down the software. Among them, restarting the server or system software will release part of the memory. However, memory overflow errors caused by system configuration, data flow, user code, etc. cannot be avoided even if the user re-executes the task. Therefore, when a memory overflow event occurs, it is necessary to troubleshoot the problem as soon as possible, otherwise it will cause serious production line accidents. Since the delay queue is an unbounded queue, when using the delay queue, it is easy to cause memory overflow problems, affecting the reliability of the application system. To this end, the present application provides a queue control scheme that can avoid memory overflow problems caused by adding delayed tasks to the delay queue, thereby improving the reliability of the application system.
[0048] First, the professional terms involved in this application are explained:
[0049] Memory overflow, derived from java.lang.OutOfMemoryError. When the JVM does not have enough memory to allocate space for the object and the garbage collector has no space to reclaim, this error will be thrown (not an exception, because the problem is not serious enough to be handled by the application).
[0050] JVM (Java Virtual Machine) is an abstract computer model that provides a cross-platform operating environment for Java programs. JVM is a highly engineered software abstraction that provides a standardized operating environment for executing Java applications.
[0051] DelayQueue is a class in the Java concurrent package (java.util.concurrent). It implements the BlockingQueue interface and is an unbounded blocking queue that supports delayed retrieval of elements. DelayQueue is mainly used to place objects that implement the Delayed interface, each of which has an expiration time; only when the object's expiration time is reached can it be taken from the queue. Usage scenarios include: scheduled task scheduling, cache expiration management, and delayed messages in message queues.
[0052] MemoryMXBean is an interface in the JMX (Java Management Extensions) framework that provides the ability to access and manipulate information related to the Java Virtual Machine (JVM) memory system. Through this MXBean (management bean), developers and operation and maintenance personnel can monitor and manage the memory usage of Java applications, including the usage statistics of heap memory and non-heap memory.
[0053] An unbounded queue means that the number of elements in this queue is unlimited. It can be infinite. On the contrary, a bounded queue means that the number of elements in this queue has a maximum limit.
[0054] See also Figure 1 As shown, the embodiment of the present application discloses a queue control method, including:
[0055] Step S11: When a new delayed task is obtained, the remaining memory is checked.
[0056] Among them, the delayed task can be understood as a task that the application system needs to delay processing. The application system can be understood as a software system. For example, the application system is a shopping platform. After placing an order on the shopping platform, the order will be retained for 30 minutes. If the payment is not made within 30 minutes, the order will be cancelled. In this scenario, canceling the order is a delayed task. Use a delayed queue to save the order cancellation task. The delayed queue is stored in the memory. When the order volume increases sharply, it may cause a memory overflow, causing the program to terminate and the platform function cannot be used normally. The remaining memory is the remaining memory of the target memory. In one embodiment, the target memory can be the memory allocated to the application system. In another embodiment, the target memory can be understood as the overall memory of the device running the application system. Among them, the memory can be heap memory. In this embodiment, the preset memory check interface can be called to obtain the remaining memory.
[0057] Step S12: determining whether a preset task adding condition corresponding to the delay queue is satisfied based on the remaining memory.
[0058] In an optional implementation, the ratio of the remaining memory to the total memory can be calculated; it is determined whether the ratio is greater than or equal to a preset threshold value, if the ratio is greater than or equal to the preset threshold value, it is determined that the preset task adding condition corresponding to the delay queue is met, otherwise, it is determined that the preset task adding condition corresponding to the delay queue is not met. It can be understood that the total memory is the total amount of the target memory, and when the remaining memory is sufficient, the preset task adding condition is met.
[0059] Step S13: If the preset task adding condition is met, the new delayed task is added to the delayed queue.
[0060] It is understandable that if the preset task adding conditions are met, that is, the remaining memory is sufficient, a delay queue can be added.
[0061] Furthermore, in this embodiment, after adding the new delayed task to the delayed queue, the persistent file corresponding to the delayed queue may be updated, wherein the persistent file is used to store the delayed tasks in the delayed queue.
[0062] Further, the embodiment of the present application can load the delayed task from the persistent file to the delay queue in response to the queue initialization operation. It is understandable that by persisting the delay queue, data recovery of the program under abnormal circumstances can be guaranteed, thereby improving the robustness of the delay queue.
[0063] Step S14: If the preset task adding condition is not met, the new delayed task is added to a candidate file corresponding to the delayed queue, wherein the candidate file is stored in a non-memory storage device.
[0064] In an optional implementation of the present application, it can be determined whether there is a target delayed task in the delay queue whose execution time is later than that of the new delayed task; if there is no target delayed task whose execution time is later than that of the new delayed task, the step of adding the new delayed task to the standby file corresponding to the delay queue is triggered; if there is a target delayed task whose execution time is later than that of the new delayed task, the target delayed task is deleted from the delay queue, and the target delayed task is added to the standby file, and the new delayed task is added to the delay queue. Specifically, the delay task at the tail of the delay queue (i.e., the delay task with the latest execution time) can be obtained first, and then the execution time can be compared with the new execution task. If the new execution task is executed earlier than the tail delay task, the tail delay task is removed, and the removed tail delay task is added to the standby file, and finally the new execution task is added to the delay queue.
[0065] Furthermore, this embodiment can remove any delayed task from the delay queue in response to the execution of the delayed task in the delay queue; determine whether there is a standby delayed task in the standby file; if there is a standby delayed task in the standby file, select the standby delayed task from the standby file and add it to the delay queue.
[0066] In an optional implementation, the delayed task with the latest execution time can be selected from the candidate file and added to the delayed queue. It is understandable that the delayed task with the latest execution time is the one with the earliest execution time.
[0067] Furthermore, the embodiment of the present application updates the persistent file corresponding to the delay queue after removing the arbitrary delayed task from the delay queue.
[0068] It can be seen that the embodiment of the present application first checks the remaining memory before adding a new delayed task to the delay queue. If the remaining memory meets the preset task adding condition corresponding to the delay queue, the new delayed task is added to the delay queue; if the remaining memory does not meet the preset task adding condition, the new delayed task is added to a standby file stored in a non-memory storage device. In this way, when adding a delay queue, a memory check is performed first. If the remaining memory is sufficient, the delayed task is added to the delay queue, otherwise it is added to the standby file. This can avoid memory overflow problems caused by adding delayed tasks to the delay queue, thereby improving the reliability of the application system.
[0069] Furthermore, this embodiment can solve the memory overflow problem caused by the delay queue DelayQueue because it is an unbounded queue. From the perspective of monitoring memory usage, this embodiment provides a memory-safe delay queue solution through MemoryMXBean technology to solve the problem that the delay queue DelayQueue may cause OOM. This embodiment ensures that the memory is not used up, thereby avoiding OOM caused by insufficient memory. On the basis of the original delay queue, when adding elements (i.e., delayed tasks), the current memory usage and remaining situation are detected, and memory safety is ensured by actively refusing to add more elements, that is, there will be no OOM. The specific design is as follows:
[0070] Define a class called MemorySecurityDelayQueue, which is an extension of the standard java.util.concurrent.DelayQueue. In other words, rewrite the standard java.util.concurrent.DelayQueue. This extension is mainly to add a memory safety check before adding delayed tasks to the queue, ensuring that new tasks are allowed to be added only when the remaining heap memory of the system exceeds a certain threshold, so as to prevent memory overflow caused by excessive addition of tasks when memory is tight.
[0071] Among them, the following functions are implemented in the MemorySecurityDelayQueue class: 1. Memory security limit: A static variable limit is defined in the class, with a default value of 0.2, which means that when the remaining heap memory is less than 20% of the total memory, the queue will no longer accept new delayed tasks. 2. Memory monitoring: Use MemoryMXBean under the java.lang.management package to monitor the heap memory usage of the Java virtual machine, and obtain the current heap memory usage statistics through the getHeapMemoryUsage() method. 3. Remaining memory check method (remainingMemory): This method calculates the current heap memory usage, determines whether the remaining memory meets the ratio requirements set by limit, and decides whether to allow the addition of new delayed tasks. 4. Rewrite the addition method: Rewrite the add, offer, put and offer methods with timeout parameters. All these methods will call the remainingMemory method to check the memory status before trying to add elements to the queue. Only when the memory check passes will the corresponding method of the parent class be called to try to add elements. 5. Rewrite the deletion method: Rewrite the remove, poll and other methods. All these methods can delete elements in the queue and in the candidate file when deleting queue elements, and after deleting, they will call the method to query whether there are candidate elements. If there are candidate elements, the candidate elements will be added to the queue, and the candidate element deletion method will be called to delete the element from the candidate file. Deleting an element will also update the corresponding persistent file to ensure the accuracy of the persistent file. 6. Set an attribute in the class to represent the path and file name of the candidate file. And provide four methods to query whether there are candidate elements, query the most recently executed candidate elements, add candidate elements, and delete candidate elements. 7. Queue persistence: provides three methods for deleting elements, adding elements, and initializing loading elements. The add method will be called when adding elements to the queue, and the delete method will be called when deleting elements from the queue. When the persistent file needs to be loaded during queue initialization, the initialization loading element method will be called. By designing this class, the robustness of the application in processing delayed tasks can be improved, especially in an environment with limited resources. By adding a standby mechanism to ensure that more tasks are added when memory is insufficient, potential memory overflow errors can be effectively prevented. A persistence mechanism is added to prevent data loss caused by program exceptions, thereby improving the robustness, stability, and reliability of the system.
[0072] For further information, see Figure 2 As shown, Figure 2A delay queue initialization flow chart provided for an embodiment of the present application. Initialize the delay queue, i.e., MemorySecurityDelayQueue, and determine whether to set the remaining memory ratio. If not, set the remaining memory ratio to the default ratio, such as 0.2. If yes, set the memory ratio to the specified ratio, that is, the remaining memory ratio can be set to the specified ratio in this embodiment, and the remaining memory ratio can also be the default ratio. Determine whether to load local historical elements. If not, the delay queue is initialized successfully. If yes, determine whether to specify a module name. If not, first set the module name to the system default module name. If so, directly search for the local persistent file based on the module name to determine whether the file exists. If it exists, load the data in the file into the queue. The delay queue is initialized successfully. Otherwise, the delay queue is initialized successfully. Among them, local can be understood as the server running the application system, and the historical element is the delayed task in the persistent file.
[0073] For further information, see Figure 3 As shown, Figure 3A delay queue addition flow chart provided for an embodiment of the present application. The queue is added to the queue, and a memory check is performed. If the remaining memory is sufficient, an attempt is made to add a task to the queue. If the remaining memory is sufficient, an attempt is made to add a task to the queue. After successful addition, the new element is persisted to the file and the process ends. If the remaining memory is insufficient, the tail task of the queue is obtained. If the new task is executed earlier than the tail task, an attempt is made to remove the tail task and add the new task to the queue. The removed tail task is saved in the candidate file of the queue, and the new task is added to the queue. After successful addition, the new element is persisted to the file. If the new task is executed later than the tail task, the new task is saved in the candidate file of the queue. Specifically, when a new delay task attempts to be added to the MemorySecurityDelayQueue, the process begins. Check whether the remaining heap memory of the current system exceeds the limit ratio (limit): Check the heap memory usage of the current JVM by calling the remainingMemory() method. This method calculates the proportion of the remaining memory (maximum heap memory minus the used memory) to the total memory and compares it with the preset limit value. If the remaining memory ratio is greater than or equal to the limit, it means that there is enough memory space to safely add new tasks and perform the addition operation; if the remaining memory ratio is less than the limit, it indicates that the memory is tight and the remaining memory is insufficient. First, get the element at the end of the queue (that is, the element with the latest execution time), and then compare the execution time with the element to be added. If the newly added element is executed earlier than the tail element, remove the tail element and add the removed tail element to the candidate file, and add the newly added element to the queue. Update the queue persistence file and the task is added successfully: Once the task is successfully added to the queue, update the queue persistence file and mark the addition operation as successful. Return the result of the addition operation: Whether it is successful or failed, it will be returned to the caller through a Boolean value to indicate the result of the addition operation. End: The process ends and waits for the next request to add a task. Through this process, MemorySecurityDelayQueue performs a memory safety check before each attempt to add a task, effectively preventing the continued accumulation of tasks when memory resources are tight, thereby ensuring the memory safety and stability of the system.
[0074] For further information, see Figure 4 As shown, Figure 4The present invention discloses a flowchart for removing tasks from a delayed queue. The queue is dequeued, the task is waiting for expiration, the thread executing the task is blocked, the task status is detected, the task expires, the waiting thread is awakened, the element at the head of the queue is obtained, a specific task is executed, the element is removed from the queue, and the candidate file is queried to see if there is a candidate element. If so, the element with the earliest execution time among the candidate elements is inserted into the queue, the candidate element inserted into the queue pair is deleted from the candidate file, the queue persistence file is updated, and the process ends. Specifically, when the task of the MemorySecurityDelayQueue expires, the process begins. Get the head element in the queue, that is, the specific task corresponding to the element to be executed. Remove the element from the queue. Determine whether there is an element in the candidate file. If there is an element candidate, the element with the closest execution time is obtained from the candidate file, added to the queue, and then the candidate element inserted into the corresponding candidate file is removed from the candidate file. Update the queue persistence file, and the element removal is successful: once the element is successfully removed, the queue persistence file is updated, and the removal operation is marked as successful.
[0075] The embodiment of the present application provides a memory-safe delay queue, MemorySecurityDelayQueue. That is, on the basis of the memory-insecure delay queue, memory control related to MemoryMXBean and element candidate mechanism are added to achieve memory safety, and data loss of the queue is prevented through a persistence mechanism. In this way, the implementation method is flexible, DelayQueue and MemoryMXBean belong to JDK internal packages or interfaces, and there is no need to introduce other middleware, which reduces the complexity and cost of operation and maintenance; the operation of the queue is controlled by obtaining real-time memory, which is more accurate and avoids OOM; the persistence mechanism is added to ensure data recovery of the program under abnormal circumstances, etc., which improves the robustness of the queue.
[0076] See also Figure 5 As shown, the embodiment of the present application discloses a queue control device, including:
[0077] The memory checking module 11 is used to check the remaining memory when a new delayed task is acquired;
[0078] A condition judgment module 12, used for judging whether a preset task adding condition corresponding to the delay queue is satisfied based on the remaining memory;
[0079] A queue adding module 13, configured to add the new delayed task to the delayed queue if the condition judgment module determines that the preset task adding condition is met;
[0080] The file adding module 14 is used to add the new delayed task to the candidate file corresponding to the delayed queue if the condition judgment module determines that the preset task adding condition is not met, wherein the candidate file is stored in a non-memory storage device.
[0081] It can be seen that the embodiment of the present application first checks the remaining memory before adding a new delayed task to the delay queue. If the remaining memory meets the preset task adding condition corresponding to the delay queue, the new delayed task is added to the delay queue; if the remaining memory does not meet the preset task adding condition, the new delayed task is added to a standby file stored in a non-memory storage device. In this way, when adding a delay queue, a memory check is performed first. If the remaining memory is sufficient, the delayed task is added to the delay queue, otherwise it is added to the standby file. This can avoid memory overflow problems caused by adding delayed tasks to the delay queue, thereby improving the reliability of the application system.
[0082] Among them, the condition judgment module 12 includes:
[0083] A ratio calculation submodule, used to calculate the ratio of the remaining memory to the total memory;
[0084] The threshold judgment submodule is used to judge whether the ratio is greater than or equal to a preset threshold. If the ratio is greater than or equal to the preset threshold, it is determined that the preset task adding condition corresponding to the delay queue is met; otherwise, it is determined that the preset task adding condition corresponding to the delay queue is not met.
[0085] Furthermore, the queue adding module 13 is also used to: determine whether there is a target delayed task in the delay queue whose execution time is later than that of the new delayed task; if there is no target delayed task whose execution time is later than that of the new delayed task, trigger the step of adding the new delayed task to the standby file corresponding to the delay queue; if there is a target delayed task whose execution time is later than that of the new delayed task, delete the target delayed task from the delay queue, add the target delayed task to the standby file, and add the new delayed task to the delay queue.
[0086] Furthermore, the device also includes a persistent file update module, which is used to update the persistent file corresponding to the delay queue after adding the new delayed task to the delay queue, wherein the persistent file is used to save the delayed tasks in the delay queue.
[0087] Furthermore, the device also includes a queue initialization module, which is used to load the delayed task from the persistent file to the delayed queue in response to the queue initialization operation.
[0088] Furthermore, the device also includes:
[0089] A task removal module, configured to remove any delayed task from the delay queue in response to the execution of any delayed task in the delay queue;
[0090] The queue adding module 13 also includes:
[0091] A candidate judgment submodule, used to judge whether there is a candidate delayed task in the candidate file;
[0092] The task adding submodule is used to select a candidate delayed task from the candidate file and add it to the delayed queue if the candidate judging submodule determines that there is a candidate delayed task in the candidate file.
[0093] Among them, the task adding submodule is specifically used to select the delayed task with the latest execution time from the candidate file and add it to the delayed queue.
[0094] See also Figure 6 As shown, an embodiment of the present application discloses an electronic device 20, including a processor 21 and a memory 22; wherein the memory 22 is used to store a computer program; the processor 21 is used to execute the computer program, the queue control method disclosed in the above embodiment.
[0095] For the specific process of the above-mentioned queue control method, reference may be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.
[0096] Furthermore, the memory 22 as a carrier for storing resources may be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., and the storage method may be temporary storage or permanent storage.
[0097] In addition, the electronic device 20 also includes a power supply 23, a communication interface 24, an input / output interface 25 and a communication bus 26; wherein the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and an external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input / output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0098] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the queue control method disclosed in the aforementioned embodiment.
[0099] For the specific process of the above-mentioned queue control method, reference may be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.
[0100] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0101] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0102] The above is a detailed introduction to a queue control method, device, equipment and medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A queue control method, characterized in that: include: When a new delayed task is obtained, the remaining memory is checked; Determining whether a preset task adding condition corresponding to the delay queue is met based on the remaining memory; If the preset task adding condition is met, the new delayed task is added to the delayed queue; If the preset task adding condition is not met, the new delayed task is added to the candidate file corresponding to the delayed queue, wherein the candidate file is stored in a non-memory storage device.
2. The queue control method according to claim 1, characterized in that: The determining whether a preset task adding condition corresponding to the delay queue is met based on the remaining memory includes: Calculating the ratio of the remaining memory to the total memory; Determine whether the ratio is greater than or equal to a preset threshold value. If the ratio is greater than or equal to the preset threshold value, determine that the preset task adding condition corresponding to the delay queue is met; otherwise, determine that the preset task adding condition corresponding to the delay queue is not met.
3. The queue control method according to claim 1, characterized in that: Before adding the new delayed task to the candidate file corresponding to the delayed queue, the method further includes: Determine whether there is a target delayed task in the delayed queue whose execution time is later than that of the new delayed task; If there is no target delayed task whose execution time is later than that of the new delayed task, triggering the step of adding the new delayed task to the candidate file corresponding to the delayed queue; If there is a target delayed task whose execution time is later than that of the new delayed task, the target delayed task is deleted from the delayed queue, added to the candidate file, and the new delayed task is added to the delayed queue.
4. The queue control method according to claim 1, characterized in that: After adding the new delayed task to the delayed queue, the method further includes: The persistent file corresponding to the delay queue is updated, wherein the persistent file is used to save the delayed tasks in the delay queue.
5. The queue control method according to claim 4, characterized in that: Also includes: In response to the queue initialization operation, the delayed task is loaded from the persistent file into the delayed queue.
6. The queue control method according to any one of claims 1 to 5, characterized in that: Also includes: In response to the execution of any delayed task in the delay queue, removing the any delayed task from the delay queue; Determine whether there is a candidate delayed task in the candidate file; If there are candidate delayed tasks in the candidate file, the candidate delayed tasks are selected from the candidate file and added to the delayed queue.
7. The queue control method according to claim 6, characterized in that: The step of selecting a candidate delayed task from the candidate file and adding it to the delayed queue includes: A delayed task with the latest execution time is selected from the candidate file and added to the delayed queue.
8. A queue control device, characterized in that: include: The memory check module is used to check the remaining memory when a new delayed task is obtained; A condition judgment module, used for judging whether a preset task adding condition corresponding to the delay queue is met based on the remaining memory; A queue adding module, configured to add the new delayed task to the delayed queue if the condition judgment module determines that the preset task adding condition is met; The file adding module is used to add the new delayed task to the candidate file corresponding to the delayed queue if the condition judgment module determines that the preset task adding condition is not met, wherein the candidate file is stored in a non-memory storage device.
9. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store the computer program; The processor is used to execute the computer program to implement the queue control method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the queue control method according to any one of claims 1 to 7 is implemented.
