Information queue management method, system, product and medium on wireless communication network
By allocating asynchronous messages as delay tasks into the time slot of the time roulette, using the design of the time roulette and index structure, the problems of high resource consumption and low efficiency of the message queue system in the prior art are solved, and efficient and reliable message processing is achieved.
Patent Information
- Application Number
- CN202411487238.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2044-10-24
AI Technical Summary
In the prior art, the message queue system based on timing scanning results in excessive consumption of system resources and low efficiency when processing a large number of delayed messages.
Asynchronous messages are assigned to the corresponding time slot of the time roulette as a delay task. Through the design and index structure of the time roulette, precise positioning and efficient processing of the task are achieved.
Through precise positioning and efficient processing, the processing efficiency of the message queue system is improved, resource consumption is reduced, and the system's recovery and processing capabilities are enhanced.
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] The present application relates to the field of wireless communication networks, and in particular to information queue management methods, systems, products and media on wireless communication networks. Background Art
[0002] With the rapid development of Internet technology and the continuous growth of business needs, message queue systems play an increasingly important role in modern distributed architectures. Among them, delayed message processing has become a key requirement for many application scenarios, such as scheduled tasks, delayed notifications, order timeout processing, etc. These scenarios require message queue systems to be able to efficiently and reliably process a large number of delayed messages while ensuring the accuracy and timeliness of the messages.
[0003] At present, message queue systems in related technologies (such as RocketMQ) usually use timed task scheduling when processing delayed messages. In specific implementation, the system maintains one or more timers to periodically scan delayed messages to be processed. When it is found that the scheduled execution time of the message has arrived, the system will take these messages out of the delay queue and put them into the regular message queue for processing. In order to support different delay times, the system may set multiple delay levels, each level corresponds to a fixed delay time, and messages are assigned to the corresponding level according to their delay time.
[0004] However, with the expansion of business scale and the surge in the number of delayed messages, the timed scanning-based method in the related art may lead to excessive consumption of system resources, especially when most messages have not expired, resulting in low efficiency. Summary of the invention
[0005] The present application provides a method, system, product and medium for managing an information queue on a wireless communication network, which are used to improve processing efficiency.
[0006] In a first aspect, the present application provides a method for managing an information queue on a wireless communication network, comprising: treating asynchronous messages in the wireless communication network as delayed tasks, and allocating them to corresponding time slots of a time wheel according to the processing time of each delayed task; the time wheel comprises a plurality of time slots, and the time slots are used to store delayed tasks whose difference between the corresponding time and the processing time is less than a preset first time threshold; synchronously storing the delayed tasks in a storage device; rotating the time wheel with the current time, and checking whether the delayed tasks in the time wheel corresponding to the current time have expired; if the delayed tasks have expired, executing a first strategy, and updating the execution results to the storage device; periodically checking the unprocessed tasks in the time wheel and the storage device, the unprocessed tasks being delayed tasks whose difference between the current time and the processing time is greater than a preset second time threshold; executing a second strategy, and updating the execution results to the time wheel and the storage device.
[0007] By adopting the above technical solution, asynchronous messages are treated as delayed tasks and assigned to the corresponding time slots of the time wheel, allowing accurate positioning based on the processing time of the message, avoiding frequent full scans and improving processing efficiency. Secondly, tasks are synchronously stored in storage devices to ensure the persistence of messages and improve recovery capabilities in the event of restarts or failures. By periodically checking unprocessed tasks and executing corresponding strategies, timed messages can be processed in a timely manner, preventing task accumulation and processing delays.
[0008] In combination with some embodiments of the first aspect, in some embodiments, the step of treating asynchronous messages in the wireless communication network as delayed tasks and allocating them to corresponding time slots of the time wheel according to the processing time of each delayed task specifically includes: determining the number of levels of the time wheel and the time granularity of each level based on the number of asynchronous messages in the wireless communication network and the processing time distribution, wherein the time granularity of the upper level of the time wheel is greater than the time granularity of the lower level of the time wheel, and the time slots of the upper level of the time wheel correspond to the time slots of the lower levels of multiple time wheels in terms of time span; treating asynchronous messages as delayed tasks and allocating them to corresponding time slots of the highest level of the time wheel of the time wheel according to the processing time of each delayed task; and sinking the delayed tasks in the time wheel from the time slots of the highest level to the time slots of the lowest level in sequence.
[0009] By adopting the above technical solutions, the design of the multi-level time wheel allows the number of levels and time granularity to be dynamically adjusted according to actual needs, adapting to the distribution of tasks of different scales and types. The high-level time wheel is responsible for coarse-grained time management, while the low-level time wheel handles fine time scheduling. The process of sinking tasks from high-level to low-level in sequence realizes the gradual refinement and precise positioning of tasks, improves the processing capacity of a large number of tasks, reduces response delays, solves the performance bottleneck problem in high-concurrency environments, and can handle delayed tasks in large-scale, high-concurrency environments more flexibly and efficiently.
[0010] In combination with some embodiments of the first aspect, in some embodiments, the step of sinking the delayed tasks in the time wheel from the highest level time slot to the lowest level time slot in sequence specifically includes: traversing the delayed tasks in the highest level time slot; determining the target time slot of each delayed task in the lower level of the highest level; checking whether the target time slot exists, and creating the target time slot if it does not exist; and moving the delayed task to the target time slot.
[0011] By adopting the above technical solution, the system traverses the time slots of the highest layer and sinks the tasks to the lower layer. In this process, the required time slots are dynamically created to ensure that only necessary time slots are created and maintained. This on-demand creation method reduces the number of idle time slots, thereby significantly reducing resource consumption during the scanning process.
[0012] In combination with some embodiments of the first aspect, in some embodiments, after the step of sinking the delayed tasks in the time wheel from the highest level time slot to the lowest level time slot in sequence, the method also includes: creating an index for each layer of the time wheel, wherein each node of the index corresponds to a time slot; each node of the index includes a delayed task pointer corresponding to the time slot, and forward pointers of different layers.
[0013] By adopting the above technical solution, an index is created for each layer of the time wheel, and a delayed task pointer and forward pointers of different layers are included in each index node, so as to construct an efficient multi-level navigation structure. This index structure makes it possible to quickly locate a specific time slot without traversing the entire time wheel. When a specific time slot needs to be accessed, these indexes can be used to locate the target time slot layer by layer starting from the top layer through the forward pointer, so that fast and efficient task positioning can be achieved in a complex multi-level time wheel structure. Especially in the scenario of processing a large number of tasks, the time complexity of task positioning is reduced and the efficiency of task scheduling is improved.
[0014] In combination with some embodiments of the first aspect, in some embodiments, if the delayed task expires, the first strategy is executed, and the execution result is updated to the storage device. The steps specifically include: if the delayed task expires, the first strategy is executed, and it is determined whether the execution result needs to be allocated to the time wheel; if it does not need to be allocated to the time wheel, the update task of the execution result is added to the asynchronous update queue; if it needs to be allocated to the time wheel, the execution result is used as a delayed task, and it is allocated to the corresponding time slot of the time wheel according to the processing time of each delayed task; it is determined whether the difference between the corresponding time of the corresponding time slot and the current time is greater than the expected completion time, and the expected completion time is determined by the number of update tasks in the asynchronous update queue and the average processing time; if it is not greater than, the update task of the execution result is added to the asynchronous update queue; if it is greater than, the execution result is synchronously updated to the storage device.
[0015] By adopting the above technical solution, it is determined whether the execution results need to be reallocated to the time wheel. For the results that do not need to be reallocated, they are added to the asynchronous update queue to reduce resource consumption. For the results that need to be reallocated, the current load is further evaluated, and by comparing the time of the corresponding time slot with the expected completion time, it is decided whether to perform a synchronous update. This load-based dynamic decision-making mechanism balances real-time and load, and improves overall processing efficiency and adaptability.
[0016] In combination with some embodiments of the first aspect, in some embodiments, executing the second strategy and updating the execution results to the time wheel and the storage device, specifically include: executing the second strategy, and determining whether the execution results need to be allocated to the time wheel; if they do not need to be allocated to the time wheel, adding the update task of the execution results to the asynchronous update queue; if they need to be allocated to the time wheel, synchronously updating the execution results to the storage device.
[0017] By adopting the above technical solution, the result of executing the second strategy is judged to determine whether it needs to be reallocated to the time wheel. This dynamic judgment mechanism enables flexible adjustments based on the actual execution of the task. For results that do not need to be reallocated, they are added to the asynchronous update queue to reduce resource consumption. For results that need to be reallocated, they will be immediately updated synchronously to quickly advance unprocessed tasks and avoid affecting the next link.
[0018] By adopting the above technical solution, the number of delayed tasks is determined, and the priority processing mechanism is activated only when the number of tasks is not less than 2, taking into account the waiting time and historical processing time of the task, which can reflect the urgency and complexity of the task. Based on this information, the priority of each task is calculated, and the tasks are processed in turn according to the calculated priority, ensuring that the most critical and urgent tasks can be processed in a timely manner.
[0019] In a second aspect, the present application provides an information queue management system on a wireless communication network, the information queue management system on the wireless communication network comprising: one or more processors and a memory; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, the one or more processors call the computer instructions to enable the information queue management system on the wireless communication network to perform the method described in the first aspect and any possible implementation method of the first aspect.
[0020] In a third aspect, the present application provides a computer program product comprising instructions, which, when executed on an information queue management system on a wireless communication network, enables the information queue management system on the wireless communication network to perform the method described in the first aspect and any possible implementation of the first aspect.
[0021] In a fourth aspect, the present application provides a computer-readable storage medium comprising instructions, which, when executed on an information queue management system on a wireless communication network, causes the information queue management system on the wireless communication network to execute the method described in the first aspect and any possible implementation of the first aspect.
[0022] One or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages:
[0023] 1. Treat asynchronous messages as delayed tasks and assign them to the corresponding time slots of the time wheel, allowing precise positioning based on the processing time of the message, avoiding frequent full scans and improving processing efficiency. Secondly, synchronously storing tasks to storage devices ensures the persistence of messages and improves recovery capabilities in the event of restarts or failures. By periodically checking unprocessed tasks and executing corresponding strategies, timed messages can be processed in a timely manner, preventing task accumulation and processing delays.
[0024] 2. The design of multi-level time wheels allows the number of levels and time granularity to be adjusted dynamically according to actual needs, adapting to the distribution of tasks of different scales and types. The high-level time wheel is responsible for coarse-grained time management, while the low-level time wheel handles fine time scheduling. The process of sinking tasks from high-level to low-level in sequence realizes the gradual refinement and precise positioning of tasks, improves the processing capacity of a large number of tasks, reduces response delays, solves the performance bottleneck problem in high-concurrency environments, and can handle delayed tasks in large-scale, high-concurrency environments more flexibly and efficiently. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a flow chart of a method for managing an information queue on a wireless communication network according to an embodiment of the present application;
[0026] Figure 2 is another flow chart of the information queue management method on the wireless communication network in the embodiment of the present application;
[0027] Figure 3 is another flow chart of the information queue management method on the wireless communication network in the embodiment of the present application;
[0028] Figure 4 is another flow chart of the information queue management method on the wireless communication network in the embodiment of the present application;
[0029] Figure 5 It is a schematic diagram of an exemplary hardware structure of an information queue management system on a wireless communication network in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The terms used in the following embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to be used as limitations to the present application. As used in the specification and appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include plural expressions, unless there is a clear indication to the contrary in the context. It should also be understood that the term "and / or" used in the present application refers to and includes any or all possible combinations of one or more listed items.
[0031] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features, and in the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.
[0032] See also Figure 1 , which is a flow chart of the information queue management method on a wireless communication network in an embodiment of the present application.
[0033] S101, taking asynchronous messages in a wireless communication network as delayed tasks, and allocating them to corresponding time slots of a time wheel according to the processing time of each delayed task; the time wheel includes a plurality of time slots, and the time slots are used to store delayed tasks whose difference between the corresponding time and the processing time is less than a preset first time threshold;
[0034] The time wheel consists of multiple time slots, each of which corresponds to a time range, and each time slot is responsible for storing tasks within a specific time range.
[0035] In some embodiments, by parsing the content of the asynchronous message, key information such as the task type and execution time are extracted; then a delayed task object is created, and the parsed information is filled into the object to obtain the delayed task;
[0036] In other embodiments, asynchronous messages can be directly regarded as delayed tasks.
[0037] In some embodiments, the processing time of each delayed task is obtained; then the time slot position where the delayed task should be placed is calculated: time slot position = (current time + processing time) / slot granularity % roulette wheel size; then the delayed task is inserted into the linked list corresponding to the calculated time slot position.
[0038] S102, synchronously storing the delayed task in a storage device;
[0039] In some embodiments, the system writes the complete information of each delayed task to the storage device. In this way, when the system fails or restarts, all unfinished delayed tasks can be recovered from the storage device to ensure that the tasks will not be lost.
[0040] In some embodiments, the delayed tasks in the time wheel can be regarded as virtual information, and the delayed tasks in the storage device can be regarded as physical information. The virtual information refers to the data structure maintained in the memory, which does not directly correspond to the physical storage, so as to achieve the effect of saving memory consumption.
[0041] S103, rotating the time wheel according to the current time, and checking whether the delayed task in the time wheel corresponding to the current time has expired;
[0042] In some embodiments, the system will continuously obtain the current system time and update the position of the time wheel according to the change of time. This rotation is a virtual concept, which is actually determined by calculation which time slot should be processed at the moment. After each rotation, the system will check all delayed tasks in the time slot corresponding to the current time. For each delayed task, the system will compare its scheduled execution time with the current time to determine whether the delayed task has expired and needs to be executed.
[0043] S104: If the delayed task expires, execute the first strategy and update the execution result to the storage device;
[0044] In some embodiments, the first strategy generally includes specific execution logic of the task, such as executing the task, transferring the task, assigning the task, ending the task, pausing the task, etc. After the execution is completed, the system will generate an execution result, which may include the completion status of the task, the data generated during the execution process, etc. Then, the system will update the execution result to the storage device to ensure the persistence and traceability of the task status.
[0045] S105, periodically checking the unprocessed tasks in the time wheel and the storage device, where the unprocessed tasks are delayed tasks whose difference between the current time and the processing time is greater than a preset second time threshold;
[0046] In some embodiments, the system will comprehensively check all tasks in the time wheel and storage device at preset time intervals. For each task, the system will calculate the difference between the current time and the scheduled processing time of the task. If this difference exceeds the preset second time threshold, the task will be marked as an unprocessed task. This mechanism can capture tasks that are not processed in time due to system failures, excessive load, etc., to ensure that all tasks can be processed in the end.
[0047] In actual use, there are multiple unprocessed delayed tasks that expire at the same time. How to ensure that key unprocessed tasks are processed in a timely manner?
[0048] In some embodiments, the second strategy includes:
[0049] S1051, determining whether the number of delayed tasks is not less than 2;
[0050] S1052. If there are not less than 2, calculate the waiting time of the delayed tasks respectively;
[0051] The waiting time refers to the time interval from the current moment to the scheduled execution time of the task.
[0052] S1053, obtaining the historical processing time of the delayed task;
[0053] Among them, historical processing time refers to the time required for the task to be executed in the past;
[0054] In some embodiments, the system first determines the range of historical data that needs to be obtained, which may include the time span (such as the last week or month) and the number of data points (such as the last 10 executions). The system queries the corresponding historical execution records for each delayed task. The system associates the processed historical processing time with the corresponding task to prepare for subsequent priority calculations.
[0055] It should be noted that, in some embodiments, there may be delayed tasks without historical processing time, in which case the historical processing time of the delayed tasks is directly determined as the preset default time.
[0056] S1054, determining the priority of the delayed task according to the historical processing time and the waiting time;
[0057] In some embodiments, the priority formula is: Priority = w1*(1 / waiting time)+w2*(1 / historical processing time), where w1 and w2 are weights; then all delayed tasks are traversed to obtain the waiting time and historical processing time of each task; then the formula is applied to calculate the priority value of each task; then the calculation result is standardized to the range of 0-100, which is not limited here.
[0058] S1055. Process the delayed tasks in order according to their priorities.
[0059] It can be seen that the number of delayed tasks is judged, and the priority processing mechanism is started only when the number of tasks is not less than 2. The waiting time and historical processing time of the task are comprehensively considered. These two factors can reflect the urgency and complexity of the task. Based on this information, the priority of each task is calculated, and the tasks are processed in turn according to the calculated priority, ensuring that the most critical and urgent tasks can be processed in time.
[0060] S106, executing the second strategy, and updating the execution result to the time wheel and the storage device.
[0061] In some embodiments, the second strategy is substantially similar to the first strategy, and typically includes specific execution logic of the task, such as executing the task, transferring the task, assigning the task, ending the task, pausing the task, and the like.
[0062] It can be seen that treating asynchronous messages as delayed tasks and assigning them to the corresponding time slots of the time wheel allows accurate positioning based on the processing time of the message, avoiding frequent full scans and improving processing efficiency. Secondly, synchronously storing tasks to storage devices ensures the persistence of messages and improves recovery capabilities in the event of restarts or failures. By periodically checking unprocessed tasks and executing corresponding strategies, timed messages can be processed in a timely manner, preventing task accumulation and processing delays.
[0063] However, in actual usage, there are some scenarios where the information is extremely large. For example, the order volume on the e-commerce platform is very large, which leads to a surge in the number of delayed tasks and makes it difficult for the system to handle all tasks efficiently.
[0064] See also Figure 2 ; Figure 2 is another flow chart of the information queue management method on the wireless communication network in the embodiment of the present application;
[0065] In some embodiments, step S101 specifically includes:
[0066] S201, based on the number of asynchronous messages in the wireless communication network and the processing time distribution, determine the number of levels of the time wheel and the time granularity of each level, wherein the time granularity of the upper level of the time wheel is greater than the time granularity of the lower level of the time wheel, and the time slot of the upper level of the time wheel corresponds to the time slots of the lower levels of multiple time wheels in terms of time span;
[0067] The number of levels indicates the number of vertical layers in the time wheel; the time granularity is used to indicate the length of time represented by each time slot; the time slot refers to the smallest unit used to store tasks in the time wheel. For example, in a three-layer time wheel, each time slot in the highest layer represents 1 day, each time slot in the middle layer represents 1 hour, and each time slot in the lowest layer represents 1 minute.
[0068] In some embodiments, the system first analyzes the number of asynchronous messages in the wireless communication network and the expected processing time distribution of these messages. Based on this data, the system determines how many layers of the time wheel are needed and the time granularity of each layer. The time granularity of the higher layer is usually larger and is used to manage long-term tasks, while the time granularity of the lower layer is smaller and is used to accurately schedule short-term tasks. Each time slot of the higher layer corresponds to multiple time slots of the lower layer in time span, forming a hierarchical structure. This design allows the system to manage a variety of delayed tasks from short-term to long-term while maintaining high efficiency.
[0069] S202, treating the asynchronous message as a delayed task, and assigning it to a corresponding time slot at the highest level of the time wheel of the time wheel according to the processing time of each delayed task;
[0070] It should be noted that the principle and process of this step are similar to those of step S101. The relevant principles and processes can refer to step S101 and will not be repeated here.
[0071] S203, sinking the delayed tasks in the time wheel from the highest level time slot to the lowest level time slot in sequence.
[0072] Among them, sinking refers to the process of moving tasks from a high level to a low level; the highest level refers to the level with the largest time granularity; the lowest level refers to the level with the smallest time granularity.
[0073] In some embodiments, the system periodically checks the time slots of each layer in the time wheel. When it detects that the time range of a high-level time slot is about to arrive, the system moves all tasks in the time slot to the corresponding time slot of the next layer. This process is repeated until the task is moved to the time slot of the lowest layer. The lowest layer has the smallest time granularity, which can more accurately schedule the execution time of tasks. This layer-by-layer sinking method can balance the efficiency and accuracy of the system, using coarse-grained management when the task is not yet approaching, and using fine-grained scheduling when the task is approaching.
[0074] It can be seen that the design of the multi-level time wheel allows the number of levels and time granularity to be dynamically adjusted according to actual needs, adapting to the distribution of tasks of different scales and types. The high-level time wheel is responsible for coarse-grained time management, while the low-level time wheel handles fine time scheduling. The process of sinking tasks from high-level to low-level in sequence realizes the gradual refinement and precise positioning of tasks, improves the processing capacity of a large number of tasks, reduces response delays, solves the performance bottleneck problem in high-concurrency environments, and can handle delayed tasks in large-scale, high-concurrency environments more flexibly and efficiently.
[0075] In actual use, due to the uneven time distribution of delayed tasks, and in this scenario, the time wheel has many levels and fine time granularity, many time slots in the time wheel may not have delayed tasks. This results in a large amount of unnecessary system resources being consumed during the scanning process.
[0076] Therefore, S203 specifically includes: S2031, traversing the delayed tasks in the time slot of the highest layer;
[0077] S2032, determining the target time slot of each delayed task in the lower layer of the highest layer;
[0078] In some embodiments, the system first obtains the expected execution time of the current task, and then calculates the time slot index corresponding to the execution time in the next layer based on the time granularity of the next layer.
[0079] In some specific embodiments, the expected execution timestamp of the task is obtained; then the current system timestamp is obtained; then the difference between the two timestamps is calculated; then according to the time granularity of the next layer, the time difference is divided by the time granularity to obtain the slot offset; finally, the slot index corresponding to the current time is added with the offset to obtain the target time slot index, which is not limited here.
[0080] In some specific embodiments, a time mapping table is maintained to pre-calculate the lower-level slots corresponding to different time ranges; then, based on the execution time of the task, the corresponding slot range is searched in the mapping table; then, a binary search is performed within the range to quickly locate the specific slot; then, it is checked whether the located slot has a conflict; finally, if there is a conflict, linear probing is used to find the next available slot, which is not limited here.
[0081] S2033, check whether the target time slot exists, and if not, create the target time slot;
[0082] In some embodiments, the system first checks whether the calculated target time slot already exists in the data structure of the time wheel. This check may involve accessing the internal data structure of the time wheel (such as an array or hash table). If it is found that the target time slot does not exist, the system will immediately create this time slot.
[0083] It should be noted that step S201 and step S2033 reflect the difference between theoretical design and practical application. The number of levels of the time wheel and the time granularity of each layer determined in step S201 represent the theoretical structural design of the time wheel. This step defines the overall framework of the time wheel in the design phase, including the possible multi-layer structure and the time accuracy of each layer. In contrast, step S2033 reflects the specific implementation of the time wheel in practical application. This step selects appropriate layers and time slots from the theoretical structure designed in step S201 according to the actual needs of the system. This may mean using only certain levels and certain time slots in the theoretical design.
[0084] In other words, step S201 provides a comprehensive theoretical framework, while step S2033 is the specific application and optimization of this framework in actual scenarios.
[0085] In some embodiments, the time wheel may not have certain time slots, which means that there are some time periods without corresponding time slots, but the system is still running. In this case, the system will continue to run during the time period without time slots, but will not perform related task scheduling or triggering operations.
[0086] In other embodiments, when the time wheel does not have certain time slots, the adjacent time slots will expand the time range they represent to absorb the time originally represented by these missing time slots, which means that the actual time granularity of some time slots may be larger than the initially set time granularity.
[0087] S2034. Move the delayed task to the target time slot.
[0088] It should be noted that the principle and process of this step are similar to those of step S101. The relevant principles and processes can refer to step S101 and will not be repeated here.
[0089] It can be seen that the system dynamically creates the required time slots by traversing the time slots of the highest layer and sinking the tasks to the lower layers, ensuring that only necessary time slots are created and maintained. This on-demand creation method reduces the number of idle time slots, thereby significantly reducing resource consumption during the scanning process.
[0090] In actual use, the time wheel has many levels and time slots. How to quickly find the corresponding time slot?
[0091] After step S203, the process further includes S204, creating an index for each layer of the time wheel, wherein each node of the index corresponds to a time slot; each node of the index includes a delayed task pointer corresponding to the time slot, and forward pointers of different layers.
[0092] Among them, index represents a data structure used to quickly find and access data; node refers to the basic unit in the index structure, which is used to store information and establish connections; delayed task pointer refers to the memory address pointing to the delayed task stored in the time slot; forward pointer refers to the pointer to a higher-level node in the same index structure.
[0093] In some embodiments, the system creates a separate index structure for each layer of the time wheel. For each layer, the system traverses all time slots of the layer and creates a corresponding index node for each time slot. During the creation process, the system stores the memory address (or reference) of the delayed task in the time slot in the corresponding index node. At the same time, the system also creates forward pointers pointing to different levels for each node. These forward pointers usually point to related nodes in higher levels, forming a skip list structure. The design of this index structure allows the system to quickly skip a large number of irrelevant time slots when searching for tasks, improving search efficiency. In addition, this structure also facilitates range queries and task management operations.
[0094] In some specific embodiments, firstly, a dynamic array is allocated for each layer to store all index nodes of the layer; then, the time slots of each layer are traversed, and an index node is created for each non-empty time slot; then, the identifier of the corresponding time slot and the reference of the delayed task list are stored in each index node; then, the forward pointer of each node is calculated and set, and a probabilistic strategy is usually used to determine the number of layers of the pointer; finally, the index nodes of each layer are sorted to ensure that a binary search can be performed, which is not limited here.
[0095] In some specific embodiments, a skip list data structure is used to implement indexing; first, a head node (sentinel node) is created for each layer; then the time slots of each layer are traversed, and a skip list node is created for each time slot; then the number of layers of each node is randomly determined, and nodes with higher layers will have more forward pointers; then the forward pointer of each node is set to ensure that they point to the correct high-level node; finally, the index structure is optimized, which may include merging sparse nodes or adjusting the number of layers to balance query efficiency, which is not limited here.
[0096] It can be seen that in some embodiments, after the step of sinking the delayed tasks in the time wheel from the highest level time slot to the lowest level time slot in sequence, the method also includes: creating an index for each layer of the time wheel, wherein each node of the index corresponds to a time slot; each node of the index includes a delayed task pointer corresponding to the time slot, and forward pointers of different layers.
[0097] In actual use, after completing the delayed task, how to update according to the actual situation;
[0098] See also Figure 3 , Figure 3 is another flow chart of the information queue management method on the wireless communication network in the embodiment of the present application;
[0099] Step S104 specifically includes: S301, if the delayed task expires, executing the first strategy, and determining whether the execution result needs to be allocated to the time wheel;
[0100] It should be noted that judging whether the execution result needs to be assigned to the time wheel is essentially evaluating whether the corresponding asynchronous message represents a phased task that has not yet been fully completed.
[0101] In some embodiments, it is determined whether the first strategy is to end the task; if it is to end the task, then it does not need to be allocated to the time wheel, otherwise it needs to be allocated to the time wheel.
[0102] S302: If it is not necessary to allocate to the time wheel, the update task of the execution result is added to the asynchronous update queue;
[0103] The asynchronous update queue refers to a data structure used to store pending update operations.
[0104] In some embodiments, the system first creates an update task object containing execution result information. This object usually contains information such as task ID, execution result, timestamp, etc. Then, the system adds this update task object to a predefined asynchronous update queue. This queue may be an in-memory data structure, such as a thread-safe queue or a priority queue. By using an asynchronous update queue, the system can batch multiple update operations, reduce frequent access to storage devices, and thus improve overall performance.
[0105] S303, if it needs to be allocated to the time wheel, the execution result is used as a delayed task, and it is allocated to the corresponding time slot of the time wheel according to the processing time of each delayed task;
[0106] It should be noted that the principle and process of this step are similar to those of step S101. The relevant principles and processes can refer to step S101 and will not be repeated here.
[0107] S304, determining whether the difference between the time corresponding to the corresponding time slot and the current time is greater than the estimated completion time, where the estimated completion time is determined by the number of update tasks in the asynchronous update queue and the average processing time;
[0108] In some embodiments, the system first calculates the difference between the time corresponding to the time slot to which the task is assigned and the current system time. This difference represents how much processing time the system has before the next task is executed. Then, the system estimates the expected completion time of the current asynchronous update queue. This estimate is usually based on the current number of tasks in the queue and the average processing time of historical statistics. The system compares these two times to determine whether the asynchronous update queue has enough time to process all update operations before the next task is executed.
[0109] In some specific embodiments, first obtain the timestamp of the time slot assigned to the task and the current system timestamp; then calculate the difference between the two timestamps to obtain the available time; then query the current length of the asynchronous update queue and the average processing time of the last N update operations; then estimate the expected completion time of the queue as: queue length * average processing time; finally, compare the available time and the expected completion time, and return the comparison result, which is not limited here.
[0110] S305: If not, the update task of the execution result is added to the asynchronous update queue;
[0111] It should be noted that the principle and process of this step are similar to those of step S302. The relevant principles and processes can be referred to step S302 and will not be repeated here.
[0112] S306: If it is greater, the execution result is synchronously updated to the storage device.
[0113] In some embodiments, the system first prepares the data of the execution result. Then, the system establishes a connection with the storage device, which may be a database connection, a file system operation, etc., depending on the type of the storage device. Then, the system performs a write operation to write the execution result data to the specified storage location.
[0114] It can be seen that it will determine whether the execution result needs to be reallocated to the time wheel. For results that do not need to be reallocated, they are added to the asynchronous update queue to reduce resource consumption. For results that need to be reallocated, the current load will be further evaluated, and by comparing the time of the corresponding time slot with the expected completion time, it will be decided whether to perform a synchronous update. This load-based dynamic decision-making mechanism balances real-time and load, and improves overall processing efficiency and adaptability.
[0115] In actual use, for overdue tasks, how to update them according to the actual situation after completing the delayed tasks;
[0116] See also Figure 4 , Figure 4 is another flow chart of the information queue management method on the wireless communication network in the embodiment of the present application;
[0117] S401, executing the second strategy, and determining whether the execution result needs to be allocated to the time wheel;
[0118] It should be noted that the principle and process of this step are similar to those of step S301. The relevant principles and processes can be referred to step S301 and will not be repeated here.
[0119] S402: If it is not necessary to allocate to the time wheel, the update task of the execution result is added to the asynchronous update queue;
[0120] It should be noted that the principle and process of this step are similar to those of step S302. The relevant principles and processes can be referred to step S302 and will not be repeated here.
[0121] S403: If it is necessary to allocate to the time wheel, the execution result is synchronously updated to the storage device.
[0122] It should be noted that the difference between embodiments S401 to S403 and embodiments S301 to S306 is that the synchronization objects of embodiments S401 to S403 are overdue tasks, which have exceeded the expected execution time and need to be processed quickly to catch up with the progress, and tend to adopt a synchronous update method, while the synchronization objects of embodiments S301 to S306 are tasks in normal processing, which are still within the expected execution time range and are processed according to the normal scheduling order. The choice of synchronous or asynchronous update can be considered based on actual conditions.
[0123] It can be seen that the result of executing the second strategy is judged to determine whether it needs to be reallocated to the time wheel. This dynamic judgment mechanism enables flexible adjustments based on the actual execution of the task. For results that do not need to be reallocated, they are added to the asynchronous update queue to reduce resource consumption. For results that need to be reallocated, they will be updated synchronously immediately to quickly advance unprocessed tasks and avoid affecting the next link.
[0124] The following introduces an exemplary information queue management system 500 on a wireless communication network provided by an embodiment of the present application. Figure 5 It is a schematic diagram of an exemplary hardware structure of an information queue management system 500 on a wireless communication network provided in an embodiment of the present application.
[0125] In some embodiments, the information queue management system 500 on the wireless communication network is a computer device or the information queue management system 500 on the wireless communication network includes a computer device. The computer device includes a processor, a memory and a network interface connected by a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The network interface of the computer device is used to communicate with other external terminals or servers through a network connection. In some embodiments, the network interface can be a wired network interface, and in some embodiments, the network interface can also be a wireless network interface. When the computer program is executed by the processor, the method in the embodiment of the present application is implemented.
[0126] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0127] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
[0128] As used in the above embodiments, the term "when..." may be interpreted to mean "if..." or "after..." or "in response to determining..." or "in response to detecting...", depending on the context. Similarly, the phrases "upon determining..." or "if (the stated condition or event) is detected" may be interpreted to mean "if determining..." or "in response to determining..." or "upon detecting (the stated condition or event)" or "in response to detecting (the stated condition or event)", depending on the context.
[0129] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk), etc.
[0130] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.
Claims
1. A method for managing information queues on a wireless communication network, characterized in that: include: Treating asynchronous messages in the wireless communication network as delayed tasks, and allocating them to corresponding time slots of a time wheel according to the processing time of each delayed task; the time wheel includes a plurality of time slots, and the time slots are used to store the delayed tasks whose difference between the corresponding time and the processing time is less than a preset first time threshold; Synchronously storing the delayed task in a storage device; Rotate the time wheel according to the current time, and check whether the delayed task in the time wheel corresponding to the current time has expired; If the delayed task expires, the first strategy is executed, and the execution result is updated to the storage device; Periodically checking the unprocessed tasks in the time wheel and the storage device, wherein the unprocessed tasks are the delayed tasks for which the difference between the current time and the processing time is greater than a preset second time threshold; Executing the second strategy, and updating the execution result to the time wheel and the storage device; The second strategy includes: determining whether the number of the delayed tasks is not less than 2; If there are not less than 2, the waiting time of the delayed task is calculated respectively; Obtain the historical processing time of the delayed task; The priority of the delayed task is determined according to the historical processing time and the waiting time; and the delayed tasks are processed in sequence according to the priority.
2. The method according to claim 1, characterized in that The step of using the asynchronous messages in the wireless communication network as the delayed tasks and allocating them to the corresponding time slots of the time wheel according to the processing time of each delayed task specifically includes: determining the number of levels of the time wheel and the time granularity of each level based on the number of asynchronous messages in the wireless communication network and the distribution of processing time, wherein the time granularity of the upper level of the time wheel is greater than the time granularity of the lower level of the time wheel, and the time slots of the upper level of the time wheel correspond to multiple time slots of the lower level of the time wheel in terms of time span; The asynchronous messages are regarded as delayed tasks, and are allocated to corresponding time slots at the highest level of the time wheel of the time wheel according to the processing time of each delayed task; The delayed tasks in the time wheel are sequentially sunk from the highest level time slot to the lowest level time slot.
3. The method according to claim 2, characterized in that The step of sequentially sinking the delayed tasks in the time wheel from the highest level time slot to the lowest level time slot specifically includes: Traversing the delayed tasks in the time slots of the highest level; Determine a target time slot for each of the delayed tasks at a layer below the highest layer; Checking whether the target time slot exists, and creating the target time slot if it does not exist; Move the delayed task to the target time slot.
4. The method according to claim 2, characterized in that: After the step of sequentially sinking the delayed tasks in the time wheel from the highest level time slot to the lowest level time slot, the method further includes: An index is created for each layer of the time wheel, wherein each node of the index corresponds to a time slot; each node of the index includes the delayed task pointer corresponding to the time slot and forward pointers of different layers.
5. The method according to claim 1, characterized in that If the delayed task expires, the first strategy is executed, and the execution result is updated to the storage device, specifically including: If the delayed task expires, the first strategy is executed, and it is determined whether the execution result needs to be allocated to the time wheel; If it does not need to be allocated to the time wheel, the update task of the execution result is added to the asynchronous update queue; If it is necessary to allocate it to the time wheel, the execution result is used as the delayed task, and it is allocated to the corresponding time slot of the time wheel according to the processing time of each delayed task; Determine whether the difference between the time corresponding to the corresponding time slot and the current time is greater than the estimated completion time, where the estimated completion time is determined by the number of update tasks in the asynchronous update queue and the average processing time; If not, the update task of the execution result is added to the asynchronous update queue; If it is greater, the execution result is synchronously updated to the storage device.
6. The method according to claim 1, characterized in that The step of executing the second strategy and updating the execution result to the time wheel and the storage device specifically includes: executing the second strategy and determining whether the execution result needs to be allocated to the time wheel; if it does not need to be allocated to the time wheel, adding the update task of the execution result to the asynchronous update queue; If it is necessary to allocate it to the time wheel, the execution result is synchronously updated to the storage device.
7. An information queue management system on a wireless communication network, characterized in that: The information queue management system on the wireless communication network includes: one or more processors and a memory; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, and the one or more processors call the computer instructions to enable the information queue management system on the wireless communication network to execute the method described in any one of claims 1-6.
8. A computer program product comprising instructions, characterized in that When the computer program product runs on an information queue management system on a wireless communication network, the information queue management system on the wireless communication network is enabled to execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium comprising instructions, characterized in that: When the instruction is executed on an information queue management system on a wireless communication network, the information queue management system on the wireless communication network executes the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Delay message processing method and device, computer equipment and storage medium
CN117194413A
Financial platform task processing method and device, storage medium and electronic equipment
CN118798481A