A method, apparatus, and device for polling candidate tasks based on logical offset pointers.
Patent Information
- Application Number
- CN202611045235.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-14
- Publication Date
- 2026-08-14
AI Technical Summary
[0004]针对相关技术中,高级计划排程因每次出队操作需搬移剩余元素导致内存拷贝开销随任务规模线性增长,在高并发大规模场景下形成性能瓶颈的问题
[0015]本申请实施例提供的技术方案带来的有益效果包括:
Smart Images

Figure CN122570128A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of intelligent manufacturing technology, specifically to a candidate task polling method, apparatus, and equipment based on logical offset pointers. Background Technology
[0002] In advanced planning, scheduling, and task scheduling systems, the candidate task set is typically maintained based on linear data structures such as arrays or lists. The system needs to retrieve tasks from the candidate set sequentially according to a predetermined strategy for processing. Existing task polling mechanisms commonly use the method of directly removing the head element of the linear structure to dequeue tasks; that is, after processing the current task, it is physically deleted from the storage structure so that the next task in the queue can be retrieved in the next polling.
[0003] However, this implementation based on physical deletion of the head element has inherent flaws in its data processing mechanism. When the head element of an array or list is removed, in order to maintain the continuity of data storage and the validity of the index, all remaining elements in the storage structure must be moved forward to fill the vacant position. This means that a single dequeue operation involves not only reading data but also a large number of memory moves of subsequent elements. As the size of the candidate tasks increases, the overhead caused by the above memory moves increases linearly, resulting in excessively high time complexity for a single dequeue operation and excessively high cumulative complexity for N consecutive rounds of polling. In concurrency scenarios with hundreds of thousands or more tasks, frequent memory copies will consume a large amount of CPU resources and form a significant performance bottleneck, severely restricting the system response speed and making it difficult to meet the requirements of high-performance scheduling scenarios. Summary of the Invention
[0004] In related technologies, advanced scheduling suffers from a performance bottleneck in high-concurrency, large-scale scenarios because the memory copy overhead increases linearly with the task size due to the need to move remaining elements with each dequeue operation.
[0005] In a first aspect, embodiments of this application provide a candidate task polling method based on logical offset pointers, the candidate task polling method comprising: Obtain a set of candidate tasks and maintain a logical offset pointer, and make the logical offset pointer point to the physical storage location of the currently polling task in the set of candidate tasks; In response to a task polling request, the task to be polled is read from the candidate task set as a dequeue task based on the logical offset pointer; Update the logical offset pointer so that it points to the physical storage location of the next task to be polled, without changing the physical storage location of the remaining candidate tasks in the candidate task set. The polling operation continues based on the updated logical offset pointer until the polling termination condition is met.
[0006] In conjunction with the first aspect, in one implementation, after obtaining the candidate task set and maintaining the logical offset pointer, and setting the logical offset pointer to point to the physical storage location of the currently polling task in the candidate task set, the method further includes: If a request to sort the candidate task set or insert a new task is received, the current valid task range is determined based on the logical offset pointer and the total length of the candidate task set. Perform sorting operations or insert new tasks within the current valid task range.
[0007] In conjunction with the first aspect, in one implementation, determining the current valid task range based on the logical offset pointer and the total length of the candidate task set includes: The starting boundary of the valid task interval is the position pointed to by the logical offset pointer, and the ending boundary of the valid task interval is the position pointed to by the total length.
[0008] In conjunction with the first aspect, in one implementation, the step of performing the insert new task operation within the current valid task interval includes: Within the current effective task range, locate the insertion position of the new task based on the binary search method; Move the candidate tasks after the insertion position to the right; Write the new task to the insertion position and update the total length of the candidate task set.
[0009] In conjunction with the first aspect, in one implementation, the step of reading the currently polled task as a dequeue task from the candidate task set according to the logical offset pointer includes: Receive a logical index request for the candidate task set; Mapping logical indexes to physical indexes based on logical offset pointers; The corresponding candidate task is read from the candidate task set based on the physical index.
[0010] In conjunction with the first aspect, in one implementation, obtaining the candidate task set and maintaining the logical offset pointer includes: The index value of the logical offset pointer is initialized, and the total length of the candidate task set is recorded; The effective task range of the candidate task set is defined based on the logical offset pointer and the total length of the candidate task set.
[0011] In conjunction with the first aspect, in one implementation, the polling termination condition includes: the index value of the logical offset pointer is equal to the total length of the candidate task set.
[0012] In conjunction with the first aspect, in one implementation, updating the logical offset pointer without changing the physical storage location of the remaining candidate tasks in the candidate task set includes: The logical offset pointer can be updated using any of the following methods: single pointer increment, CAS atomic increment, or batch increment.
[0013] Secondly, embodiments of this application provide a candidate task polling apparatus for implementing the above-described candidate task polling method based on logical offset pointers, comprising: The maintenance module is used to obtain a set of candidate tasks and maintain a logical offset pointer, and to make the logical offset pointer point to the physical storage location of the currently polled task in the set of candidate tasks. The reading module is used to respond to a task polling request and read the currently polled task from the candidate task set as a dequeue task according to the logical offset pointer; The update module is used to update the logical offset pointer without changing the physical storage location of the remaining candidate tasks in the candidate task set, so that the logical offset pointer points to the physical storage location of the next task to be polled. The control module is used to continue executing subsequent polling operations based on the updated logical offset pointer until the polling termination condition is met.
[0014] Thirdly, embodiments of this application provide a candidate task polling device, characterized in that the candidate task polling device includes a processor, a memory, and a candidate task polling program stored in the memory and executable by the processor, wherein when the candidate task polling program is executed by the processor, it implements the steps of the candidate task polling method as described in any of the preceding claims.
[0015] The beneficial effects of the technical solutions provided in this application include: This application fundamentally solves the problem of high memory relocation overhead caused by header deletion in traditional linear structures by introducing logical offset pointers to replace the physical deletion mechanism in conventional techniques. This method achieves constant-level dequeue efficiency while ensuring the correctness of the task polling logic, significantly reducing CPU and memory resource consumption, and effectively improving the overall throughput performance and stability of advanced scheduling systems in high-concurrency scenarios. Attached Figure Description
[0016] Figure 1 This is a flowchart illustrating an embodiment of the candidate task polling method of this application; Figure 2 This is a schematic diagram of the hardware structure of the candidate task polling device involved in the embodiments of this application. Detailed Implementation
[0017] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0018] In related technologies, advanced scheduling suffers from a performance bottleneck in high-concurrency, large-scale scenarios because the memory copy overhead increases linearly with the task size due to the need to move remaining elements with each dequeue operation.
[0019] In a first aspect, embodiments of this application provide a candidate task polling method based on logical offset pointers.
[0020] In one embodiment, reference is made to Figure 1 , Figure 1 This is a flowchart illustrating a first embodiment of a candidate task polling method based on logical offset pointers according to this application. Figure 1 As shown, the candidate task polling method includes: Step S1: Obtain the candidate task set and maintain the logical offset pointer, and make the logical offset pointer point to the physical storage location of the currently polled task in the candidate task set.
[0021] Specifically, step S1 includes: Step S1a: Initialize the index value of the logical offset pointer and record the total length of the candidate task set.
[0022] Understandably, in the initial steps, the system initializes a data storage container as a set of candidate tasks. This container can be an array, an array list, or any structure that supports random access. Simultaneously, the system maintains a logical offset pointer. This pointer points to the physical storage location (i.e., memory index) of the currently polling task in the candidate task set. During the initialization phase, the logical offset pointer index value is typically... Setting it to 0 indicates that the polling starts from the first element of the set. The total length (size) of the candidate task set is also recorded; this total length represents the number of tasks actually stored physically. In this case, the effective task range of the candidate task set is defined as the physical index. .
[0023] Step S1b: Define the effective task range of the candidate task set based on the logical offset pointer and the total length of the candidate task set.
[0024] It is worth noting that by initializing the logical offset pointer and the total length, and pre-defining the effective range, the polling mechanism is ensured to have a correct state view at the startup stage, laying a solid foundation for subsequent stable operation and reducing runtime risks caused by unclear initial state.
[0025] Step S2: In response to the task polling request, read the currently polled task from the candidate task set as the dequeue task according to the logical offset pointer.
[0026] It's important to note that when a task polling request is received (e.g., a scheduler request to retrieve the next executable step), the traditional deletion operation is no longer performed. Instead, data is directly read from the candidate task set based on the logical offset pointer. Specifically, the currently polling task is read. This task is the dequeue task for this poll. Since there is no need to move array elements, the time complexity of this read operation is greatly reduced.
[0027] Further, in one embodiment, step S2 includes: Step S2a: Receive a logical index request for the candidate task set.
[0028] Step S2b: Map the logical index to the physical index based on the logical offset pointer.
[0029] Step S2c: Read the corresponding candidate task from the candidate task set according to the physical index.
[0030] It is understandable that the above implementation establishes a mapping mechanism between logical indexes and physical indexes. This mechanism allows upper-layer services to continue using standard logical indexes for data access without being aware of the underlying logical offset implementation. This ensures the accuracy of data reading, maintains the compatibility and transparency of system interfaces, and reduces integration difficulty.
[0031] Step S3: Update the logical offset pointer without changing the physical storage location of the remaining candidate tasks in the candidate task set, so that the logical offset pointer points to the physical storage location of the next task to be polled.
[0032] In one specific implementation, after the task reading is completed, the system updates the logical offset pointer without changing the physical storage location of the remaining candidate tasks in the candidate task set. Specifically, the index value of the logical offset pointer is... Increment to .
[0033] It should be noted that it was originally located in The candidate task at the given position logically becomes the new head task, but in physical memory, its storage address remains unchanged. Previously located at... Although the task at a given position has been logically dequeued, it remains in physical memory until it is overwritten by subsequent new data or the array is resized. Compared to the traditional method, which requires shifting all elements after that task forward by one position (the memory copy overhead increases linearly with the number of remaining tasks N), this step only involves the addition of an integer variable, with a constant overhead.
[0034] In some preferred embodiments, the above-mentioned logical offset pointer can be updated by any of the following methods: single pointer increment, CAS (Compare-And-Swap) atomic increment, or batch increment.
[0035] It is worth noting that the CAS atomic increment method supports pointer updates in a multi-threaded environment, preventing data duplication or omission caused by race conditions. The batch increment method allows updating the offsets of multiple tasks at once, suitable for batch consumption scenarios, further reducing instruction overhead. This application provides multiple implementations for updating logical offset pointers. In particular, the introduction of the CAS atomic increment mechanism enables this method to be safely applied in multi-threaded concurrent environments, solving the data race problem during concurrent polling; at the same time, the batch increment option further optimizes processing efficiency in specific scenarios, enhancing the practical adaptability of the technical solution.
[0036] Furthermore, in one embodiment, the candidate task polling method further includes handling changes to the candidate task set (such as sorting or insertion) during the polling process. Specifically, this includes: Step A: If a request to perform a sorting operation on the candidate task set or a request to insert a new task is received, the current valid task range is determined based on the logical offset pointer and the total length of the candidate task set.
[0037] Specifically, as described in the preceding steps, the position pointed to by the logical offset pointer The starting boundary of the effective task range, with the total length The location it points to is the end boundary of the valid task range, meaning the valid task range is the physical index. The data within this interval represents real candidate tasks that have not yet been polled.
[0038] Understandably, in advanced scheduling scenarios, the candidate task set is not static and may need to be reordered based on priority during polling, or urgent tasks may need to be inserted. Directly operating on the entire array might interfere with logically dequeued data or cause index errors. Therefore, this embodiment introduces the concept of an "effective task range".
[0039] Step B: Perform a sorting operation or insert a new task within the current valid task range.
[0040] Scenario 1: Inserting a new task: Step a: Within the current valid task range, locate the insertion position of the new task based on the binary search method; Step b: Move the candidate tasks after the insertion position backward to make room.
[0041] It is understandable that the position located after the insertion position, at the end of the effective task interval (i.e., Previous candidate tasks are shifted one position to the right to make room. Note that this only moves data within the valid range and does not involve tasks that have already been dequeued.
[0042] Step c: Write the new task to the insertion position and update the total length of the candidate task set.
[0043] It is worth noting that the above implementation details the specific implementation of the insertion operation within the effective interval. By combining binary search and local element movement, this method achieves efficient insertion and dynamic expansion of new tasks while ensuring the order of the task set. This ensures that the system can flexibly respond to new task requests during polling, while maintaining the priority order required by the scheduling strategy.
[0044] Alternatively, in addition to the binary search insertion algorithm, the new task insertion operation can also be performed using batch insertion followed by unified sorting or skip list index insertion. Among these, batch insertion followed by unified sorting is suitable for scenarios with sudden appending tasks, while skip list index insertion is suitable for high-frequency small batch appending scenarios.
[0045] Scenario 2, Sorting operation: If a full / partial sort is about to be performed, the logical interval is first normalized (compressed or mapped by view) before the sorting operation is called.
[0046] Understandably, interval normalization (compression or view mapping) is performed before sorting to ensure that the sorting only applies to the valid task interval.
[0047] Preferably, the specific sorting method can be selected according to actual needs, such as effective interval view sorting or suffix subarray sorting.
[0048] Step S4: Continue to perform subsequent polling operations based on the updated logical offset pointer until the polling termination condition is met.
[0049] Specifically, the polling termination condition includes: the index value of the logical offset pointer is equal to the total length value of the candidate task set, that is, the effective length of the effective task interval is 0.
[0050] It should be noted that when this condition is met, it means that the effective task interval [po, size) is empty, all candidate tasks have been processed, and the polling ends. By comparing the logical offset pointer with the total length, this method can accurately determine whether all candidate tasks have been processed, which not only prevents the waste of resources caused by empty polling, but also avoids the risk of array out-of-bounds errors, ensuring the integrity and security of the polling process.
[0051] In summary, this invention constructs a polling mechanism based on logical offset pointers, replacing the traditional physical deletion of the queue head with pointer incrementing. This achieves constant-level dequeueing without moving remaining elements, completely eliminating memory copy overhead and CPU performance bottlenecks in large-scale data scenarios. Combined with an effective task range defined by offset pointers, it ensures that sorting and insertion operations only apply to unprocessed data, maintaining the consistency and priority order of business logic. Real-time mapping from logical indexes to physical indexes shields the underlying offset details, guaranteeing data access accuracy and interface compatibility. By combining various pointer update strategies such as CAS atomic increment, it achieves concurrency safety and batch processing efficiency in multi-threaded environments. Furthermore, explicit initialization and termination convergence conditions ensure system stability and security, thereby comprehensively improving the throughput, response speed, and resource utilization of advanced scheduling systems in high-concurrency, large-scale task scheduling scenarios.
[0052] Secondly, this application provides a candidate task polling apparatus for implementing the above-described candidate task polling method based on a logical offset pointer, comprising: a maintenance module, a reading module, an updating module, and a control module; the maintenance module is configured to acquire a candidate task set and maintain a logical offset pointer, and to make the logical offset pointer point to the physical storage location of the currently polled task in the candidate task set; the reading module is configured to, in response to a task polling request, read the currently polled task from the candidate task set as a dequeue task according to the logical offset pointer; the updating module is configured to update the logical offset pointer without changing the physical storage location of the remaining candidate tasks in the candidate task set, so that the logical offset pointer points to the physical storage location of the next polled task; the control module is configured to continue executing subsequent polling operations based on the updated logical offset pointer until the polling termination condition is met.
[0053] The functions of each module in the above-mentioned candidate task polling device correspond to the steps in the above-mentioned candidate task polling method embodiment, and their functions and implementation processes will not be described in detail here.
[0054] Thirdly, embodiments of this application provide a candidate task polling device, which can be a personal computer (PC), laptop computer, server, or other device with data processing capabilities.
[0055] Reference Figure 2 , Figure 2 This is a schematic diagram of the hardware structure of the candidate task polling device involved in the embodiments of this application. In the embodiments of this application, the candidate task polling device may include a processor, a memory, a communication interface, and a communication bus.
[0056] The communication bus can be of any type and is used to interconnect the processor, memory, and communication interface.
[0057] The communication interface includes input / output (I / O) interfaces, physical interfaces, and logical interfaces used for interconnecting devices within the candidate task polling device, as well as interfaces used for interconnecting the candidate task polling device with other devices (such as other computing devices or user equipment). Physical interfaces can be Ethernet interfaces, fiber optic interfaces, ATM interfaces, etc.; user equipment can be displays, keyboards, etc.
[0058] Memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.
[0059] The processor can be a general-purpose processor, which can call a candidate task polling program stored in memory and execute the candidate task polling method provided in the embodiments of this application. For example, the general-purpose processor can be a central processing unit (CPU). The method executed when the candidate task polling program is called can be referred to in various embodiments of the candidate task polling method of this application, and will not be repeated here.
[0060] Those skilled in the art will understand that Figure 2 The hardware structure shown does not constitute a limitation of this application and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0061] Fourthly, embodiments of this application also provide a computer-readable storage medium.
[0062] The present application provides a computer-readable storage medium storing a candidate task polling program, wherein when the candidate task polling program is executed by a processor, it implements the steps of the candidate task polling method described above.
[0063] The method implemented when the candidate task polling procedure is executed can be referred to in various embodiments of the candidate task polling method of this application, and will not be repeated here.
[0064] It should be noted that the sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0065] The terms "comprising" and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus. The terms "first," "second," and "third," etc., are used to distinguish different objects, etc., and do not indicate a sequence, nor do they limit "first," "second," and "third" to different types.
[0066] In the description of the embodiments of this application, terms such as "exemplary," "for example," or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplary," "for example," or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary," "for example," or "for instance" is intended to present the relevant concepts in a concrete manner.
[0067] In the description of the embodiments of this application, unless otherwise stated, " / " means "or". For example, A / B can mean A or B. The "and / or" in the text is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of this application, "multiple" means two or more.
[0068] In some processes described in the embodiments of this application, multiple operations or steps are included in a specific order. However, it should be understood that these operations or steps may not be executed in the order they appear in the embodiments of this application, or they may be executed in parallel. The sequence number of the operation is only used to distinguish different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed sequentially or in parallel, and these operations or steps may be combined.
[0069] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of this application.
[0070] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A candidate task polling method based on logical offset pointers, characterized in that, The candidate task polling method includes: Obtain a set of candidate tasks and maintain a logical offset pointer, and make the logical offset pointer point to the physical storage location of the currently polling task in the set of candidate tasks; In response to a task polling request, the task to be polled is read from the candidate task set as a dequeue task based on the logical offset pointer; Without changing the physical storage location of the remaining candidate tasks in the candidate task set, update the logical offset pointer so that the logical offset pointer points to the physical storage location of the next task to be polled; The polling operation continues based on the updated logical offset pointer until the polling termination condition is met.
2. The candidate task polling method based on logical offset pointers as described in claim 1, characterized in that, After obtaining the candidate task set and maintaining the logical offset pointer, and making the logical offset pointer point to the physical storage location of the currently polled task in the candidate task set, the method further includes: If a request to sort the candidate task set or insert a new task is received, the current valid task range is determined based on the logical offset pointer and the total length of the candidate task set. Perform sorting operations or insert new tasks within the current valid task range.
3. The candidate task polling method based on logical offset pointers as described in claim 2, characterized in that, The step of determining the current valid task range based on the logical offset pointer and the total length of the candidate task set includes: The starting boundary of the valid task interval is the position pointed to by the logical offset pointer, and the ending boundary of the valid task interval is the position pointed to by the total length.
4. The candidate task polling method based on logical offset pointers as described in claim 3, characterized in that, The operation of inserting a new task within the current valid task range includes: Within the current effective task range, locate the insertion position of the new task based on the binary search method; Move the candidate tasks after the insertion position to the right; Write the new task to the insertion position and update the total length of the candidate task set.
5. The candidate task polling method based on logical offset pointers as described in claim 1, characterized in that, The step of reading the currently polled task as a dequeue task from the candidate task set according to the logical offset pointer includes: Receive a logical index request for the candidate task set; Mapping logical indexes to physical indexes based on logical offset pointers; The corresponding candidate task is read from the candidate task set based on the physical index.
6. The candidate task polling method based on logical offset pointers as described in claim 1, characterized in that, The step of obtaining the candidate task set and maintaining the logical offset pointer includes: The index value of the logical offset pointer is initialized, and the total length of the candidate task set is recorded; The effective task range of the candidate task set is defined based on the logical offset pointer and the total length of the candidate task set.
7. The candidate task polling method based on logical offset pointers as described in claim 6, characterized in that, The polling termination condition includes: the index value of the logical offset pointer is equal to the total length of the candidate task set.
8. The candidate task polling method based on logical offset pointers as described in claim 1, characterized in that, The step of updating the logical offset pointer to point to the physical storage location of the next task to be polled, without changing the physical storage location of the remaining candidate tasks in the candidate task set, includes: The logical offset pointer can be updated using any of the following methods: single pointer increment, CAS atomic increment, or batch increment.
9. A candidate task polling apparatus for implementing the candidate task polling method based on logical offset pointers as described in claim 1, characterized in that, include: The maintenance module is used to obtain a set of candidate tasks and maintain a logical offset pointer, and to make the logical offset pointer point to the physical storage location of the currently polled task in the set of candidate tasks. The reading module is used to respond to a task polling request and read the currently polled task from the candidate task set as a dequeue task according to the logical offset pointer; The update module is used to update the logical offset pointer without changing the physical storage location of the remaining candidate tasks in the candidate task set, so that the logical offset pointer points to the physical storage location of the next task to be polled. The control module is used to continue executing subsequent polling operations based on the updated logical offset pointer until the polling termination condition is met.
10. A candidate task polling device, characterized in that, The candidate task polling device includes a processor, a memory, and a candidate task polling program stored in the memory and executable by the processor, wherein when the candidate task polling program is executed by the processor, it implements the steps of the candidate task polling method based on logical offset pointers as described in any one of claims 1 to 8.