A method and system for dynamic caching and scheduling of print data for a thermal printer

By employing multi-dimensional feature extraction and dynamic cache scheduling methods, the problem of data flow congestion and interruption in multi-threaded scenarios for thermal printers was solved, achieving efficient and stable printing output and improving resource utilization and user experience.

CN122470137BActive Publication Date: 2026-11-27XIAMEN PRINT FUTURE TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing thermal printers are prone to data flow congestion, printing interruptions, and output errors in multi-threaded, high-concurrency scenarios. Existing scheduling algorithms lack fine differentiation of task type, data complexity, and historical interruption conditions, resulting in high-priority task response delays, long-term waiting for low-priority tasks, or repeated resource occupation by faulty tasks, low cache resource utilization, and low recovery efficiency.

Method used

Multidimensional feature vectors are used to extract task features. A lightweight online learning model and a time series prediction model are used to predict task priority and congestion risk. Combined with a three-level cache structure and a dynamic priority function, dynamic caching and scheduling of tasks are realized, caching strategies and priorities are dynamically adjusted, and system status parameters are monitored and optimized in real time.

Benefits of technology

It significantly improves cache hit rate and resource utilization, achieving continuous, stable, and efficient printing output in multi-task scenarios, avoiding task starvation and fault interference, and improving printing efficiency and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122470137B_ABST
    Figure CN122470137B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of print task management, and discloses a kind of thermal printer print data dynamic cache and scheduling method and system, by determining the initial priority and congestion risk index of print task, the essence of the task is quantified, and by time series prediction to task arrival rate, make cache strategy can respond to load changes in advance, so as to upgrade passive scheduling to active adaptive scheduling.In addition, store by priority in the cache stage, and dynamically adjust the cache water line and data migration strategy combined with the prediction results, significantly improve the cache hit rate and resource utilization rate.At the same time, by using the composite dynamic priority function to consider the waiting time, congestion risk and retry number, effectively avoid task starvation and fault interference, realize the continuous, stable and efficient technical effect of print output in multi-task scenario.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of print job management technology, and more specifically to a method and system for dynamic caching and scheduling of print data for thermal printers. Background Technology

[0002] Thermal printers are widely used in industries such as retail, healthcare, and logistics for printing receipts and labels. With the increasing demand for multi-threaded, high-concurrency printing tasks, printers often experience data congestion, print interruptions, and output errors when processing multiple tasks simultaneously, severely impacting printing efficiency and user experience.

[0003] In existing technologies, print scheduling often employs fixed priority or first-come-first-served strategies, lacking fine-grained differentiation based on task type, data complexity, and historical interruption patterns, making it difficult to adapt to dynamically changing load environments. Some solutions introduce caching mechanisms, but these typically use a single queue cache or static memory allocation, lacking flexible adjustment capabilities. Furthermore, in the event of a print interruption, existing solutions often require retransmission of all print data, resulting in low recovery efficiency and wasted communication bandwidth. In addition, traditional scheduling algorithms are mostly reactive, adjusting only after congestion or conflicts occur, lacking foresight regarding future load changes. This leads to delayed responses from high-priority tasks, prolonged waiting times for low-priority tasks, or repeated resource consumption by faulty tasks. Therefore, the data flow scheduling efficiency, cache resource utilization, and intelligent interruption recovery capabilities of existing thermal printers in multi-task printing scenarios need improvement. Summary of the Invention

[0004] In view of this, the purpose of this invention is to provide a method and system for dynamic caching and scheduling of print data in thermal printers, so as to solve the technical problems of data flow congestion, print interruption, and output disorder in existing thermal printers.

[0005] The first aspect of this invention discloses a method for dynamic caching and scheduling of thermal printer printing data, including acquiring and extracting a multi-dimensional feature vector of a task, inputting the multi-dimensional feature vector into a first calculation model, and outputting the initial priority and congestion risk index of the task through the first calculation model; Collect historical task arrival data and input it into the second prediction model to predict the task arrival rate in the future time period. The data of each task is divided into multiple data blocks. Based on the initial priority, the multiple data blocks of each task are allocated as a whole to the corresponding level in the three-level cache structure, and the caching strategy of each level of cache is dynamically adjusted according to the task arrival rate. The dynamic priority function determines the dynamic priority of a task based on the initial priority, congestion risk index, waiting time, and number of retries. Tasks to be processed are placed into a multi-level priority circular queue according to their dynamic priority. The scheduling thread retrieves the target printing tasks in the queue order and reads the corresponding data blocks from the cache level where the target printing task is located to schedule printing resources.

[0006] Furthermore, the first computational model is a lightweight online learning model, including a multi-task structure with a shared hidden layer and two independent output heads. The first output head outputs a normalized initial priority using the Sigmoid function, and the second output head outputs a congestion risk index using the ReLU function. The model weights are updated in real time using an online gradient descent algorithm, and a penalty term for the frequency of historical interruptions is introduced into the loss function.

[0007] Furthermore, the second prediction model is a time series prediction model; Input features include the timestamp sequence of historical task arrivals, time period type features, and historical load features of the printer operating system; among them, time period type features include hourly time period identifiers and weekly periodic identifiers; The second prediction model outputs the task arrival rate for the future time period, including the predicted point value and the confidence interval of the prediction error.

[0008] Furthermore, the three-level cache structure specifically includes: The L1 cache uses a lock-free circular queue to store the data blocks currently being printed. Different data blocks of the same task are sequentially loaded into the L1 cache from the cache level where the task is located during the printing process. L2 cache uses a multi-size memory pre-allocation pool to store complete data blocks of high-priority tasks, and to accommodate some data blocks of medium-priority tasks when cache resources are sufficient; The L3 cache is used to store data blocks for low-priority tasks and adaptively selects the compression algorithm based on the task's priority.

[0009] Furthermore, the caching strategy of dynamically adjusting the caching levels based on the task arrival rate specifically includes: When the L2 cache occupancy exceeds a preset threshold, based on the point prediction value, some data blocks of medium-priority tasks in the L2 cache are downgraded to the L3 cache, and the compression ratio of the L3 cache is increased. The number of downgraded data blocks is also dynamically adjusted based on the confidence interval width of the prediction error. When the predicted point value indicates that the future will be an idle period, the task data in the L3 cache is preloaded into the L2 cache, and the amount of preloaded data is adjusted according to the confidence interval width.

[0010] Furthermore, the specific form of the dynamic priority function is as follows: Dynamic priority = Initial priority × (1 + α × number of seconds waited) × (1 + β × congestion risk index) / (1 + γ × number of retries), where α, β, and γ are all adjustable parameters with positive real values, representing the waiting time weight coefficient, congestion risk weight coefficient, and retry penalty coefficient, respectively.

[0011] Furthermore, when an interruption occurs during printing, the method further includes: Record the identifier of the last successfully printed data block, and determine the retention time of the incomplete data block in the cache based on the priority of the current task and the printing progress; the retention time represents the longest time that the incomplete data block in the cache can be retained after the interruption occurs, which is positively correlated with the task priority and negatively correlated with the printing progress.

[0012] Furthermore, during the printing process, the method also includes: The system monitors the operating status of the printer system in real time, adjusts the adjustable parameters in the dynamic priority function and the threshold parameters of the caching strategy online based on the monitoring results, and feeds back the actual prediction error to the second prediction model to optimize the prediction accuracy.

[0013] Furthermore, the adjustable parameters and the threshold parameters of the caching strategy are adjusted online using a Bayesian optimization algorithm, with the optimization objective being to minimize the average waiting time and interrupt recovery time of the task.

[0014] The second aspect of this invention discloses a dynamic caching and scheduling system for thermal printer print data, the system comprising: The data acquisition module is used to acquire and extract multidimensional feature vectors of tasks, as well as collect historical task arrival data; The model building module is used to build a first computational model and a second prediction model; wherein, the multidimensional feature vector is input into the first computational model, and the initial priority and congestion risk index of the task are output through the first computational model; and the collected historical task arrival data is input into the second prediction model, and the task arrival rate in the future time period is predicted through the second prediction model. The data caching module is used to divide the data of each task into multiple data blocks, allocate the multiple data blocks of each task to the corresponding level in the three-level cache structure based on the initial priority, and dynamically adjust the caching strategy of each level of cache according to the task arrival rate. The resource scheduling module is used to determine the dynamic priority of a task based on the initial priority, congestion risk index, waiting time, and number of retries using a dynamic priority function. The tasks to be processed are placed into a multi-level priority circular queue according to the dynamic priority order. The scheduling thread retrieves the target printing tasks in the queue order and reads the corresponding data blocks from the cache level where the target printing task is located to schedule printing resources.

[0015] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention achieves refined quantification of the essential attributes of printing tasks by determining their initial priority and congestion risk index. Furthermore, by predicting task arrival rates over time, the caching strategy can respond proactively to load changes, thus upgrading passive scheduling to proactive adaptive scheduling. In addition, prioritizing data during the caching phase and dynamically adjusting the cache watermark and data migration strategy based on prediction results significantly improves cache hit rate and resource utilization. Simultaneously, by utilizing a composite dynamic priority function that comprehensively considers waiting time, congestion risk, and retries, task starvation and fault interference are effectively avoided, achieving continuous, stable, and efficient printing output in multi-tasking scenarios. Attached Figure Description

[0016] The accompanying drawings, which are included to provide a further understanding of embodiments of the invention and form part of this application, do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart illustrating a method for dynamic caching and scheduling of print data for a thermal printer, as disclosed in an embodiment of the present invention. Detailed Implementation

[0017] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.

[0018] Example 1 The first aspect of this invention discloses a method for dynamic caching and scheduling of print data in a thermal printer, which belongs to the field of print task management technology. Please refer to... Figure 1 , Figure 1 This is a flowchart illustrating a method for dynamic caching and scheduling of print data for a thermal printer, as disclosed in an embodiment of the present invention. The method includes: The multidimensional feature vector of the task is obtained and extracted, and the multidimensional feature vector is input into the first calculation model. The initial priority and congestion risk index of the task are output through the first calculation model. Collect historical task arrival data and input it into the second prediction model to predict the task arrival rate in the future time period. The data of each task is divided into multiple data blocks. Based on the initial priority, the multiple data blocks of each task are allocated as a whole to the corresponding level in the three-level cache structure, and the caching strategy of each level of cache is dynamically adjusted according to the task arrival rate. The dynamic priority function determines the dynamic priority of a task based on the initial priority, congestion risk index, waiting time, and number of retries. Tasks to be processed are placed into a multi-level priority circular queue according to their dynamic priority. The scheduling thread retrieves the target printing tasks in the queue order and reads the corresponding data blocks from the cache level where the target printing task is located to schedule printing resources.

[0019] Furthermore, the first computational model is a lightweight online learning model, including a multi-task structure with a shared hidden layer and two independent output heads. The first output head outputs a normalized initial priority using the Sigmoid function, and the second output head outputs a congestion risk index using the ReLU function. The model weights are updated in real time using an online gradient descent algorithm, and a penalty term for the frequency of historical interruptions is introduced into the loss function.

[0020] Specifically, in this embodiment of the invention, the first computational model is implemented based on a lightweight online learning model. Its core structure is a multi-task network consisting of a shared hidden layer and two independent output heads. The shared hidden layer consists of two fully connected layers, each containing 32 neurons, and uses the ReLU activation function to extract common features from the input multidimensional feature vector. The input multidimensional feature vector specifically includes, but is not limited to, task source type (e.g., front-end reporting, back-end batch processing, timed triggering), data volume (expressed in bytes or printed pages), user-defined urgency labels (e.g., high, medium, low), data complexity (processing time weighted value calculated based on image density, font type, etc.), and historical interruption frequency (the statistical ratio of interruptions of this type of task in the past period). All of the above features are normalized before being input into the model.

[0021] After sharing the hidden layer, the network branches into two independent output heads. The first output head uses the Sigmoid activation function to compress the output values ​​to between 0 and 1, serving as the initial priority for normalization; a higher value indicates that the task should be processed first. The second output head uses the ReLU activation function to output a non-negative congestion risk index; a larger value indicates that the task is more likely to cause data flow congestion in subsequent executions. The model is trained in real-time using an online gradient descent algorithm. After each task is completed, the loss is calculated based on the actual execution result of the task (whether it was successful, whether a retry occurred, etc.), and the network weights are updated via backpropagation.

[0022] The loss function consists of a weighted sum of two parts: the first part is the mean squared error of priority prediction, and the second part is the binary cross-entropy of congestion risk index prediction, using the actual occurrence of congestion as the label. Specifically, in this embodiment, the loss function also incorporates a penalty term based on historical interruption frequency. For tasks with a high historical interruption frequency, an additional loss value is added if the model predicts a high initial priority or a low congestion risk index. This penalty term causes the model to tend to assign lower initial priorities and higher congestion risk indices to tasks with high interruption frequencies during training, thereby reducing the likelihood of them preempting resources and preventing frequently failing tasks from repeatedly interfering with the printing process.

[0023] Furthermore, preferably, in the feature weighting of the model, data complexity and historical interruption frequency are given higher weight coefficients than other features, so that the model pays more attention to the execution cost and historical reliability of the task, rather than simply relying on the urgency or data volume set by the user.

[0024] Through the above operations, on the one hand, the multi-task output structure enables a single model to output two key scheduling parameters simultaneously, reducing computational redundancy; on the other hand, through online learning and penalty term mechanisms, the first computational model can adaptively track changes in task patterns and transform historical failure records into conservative assessments of future tasks, thereby effectively suppressing resource consumption by high-failure-rate tasks and improving the overall stability of the printing queue.

[0025] Furthermore, the second prediction model is a time series prediction model; Input features include the timestamp sequence of historical task arrivals, time period type features, and historical load features of the printer operating system; among them, time period type features include hourly time period identifiers and weekly periodic identifiers; The second prediction model outputs the task arrival rate for the future time period, including the predicted point value and the confidence interval of the prediction error.

[0026] Specifically, in this embodiment of the invention, the second prediction model preferably employs a Long Short-Term Memory (LSTM) network to predict the arrival rate of print jobs within a future time period (e.g., the next 5 minutes). The second prediction model is configured to consist of an input layer, two LSTM hidden layers, and a fully connected output layer. The model's input features include three parts: the first part is a sequence of timestamps of historical print job arrivals, i.e., the specific times when jobs arrived within the past few minutes (e.g., the past 30 minutes), which is converted into an arrival interval sequence or an arrival count within a fixed time window. The second part is a time period type feature, specifically an hourly time period identifier (i.e., dividing the day into 24 time periods, each represented by a one-hot encoding) and a weekday periodic identifier (i.e., assigning an encoding for each weekday). These feature settings help the model capture the differences in users' printing habits at different times of the day and on different workdays within a week. The third part is the historical load features of the printer's operating system, including but not limited to the average CPU utilization, memory utilization, and printhead temperature within the past few time windows. This is because system load conditions are often potentially related to job arrival patterns. For example, when a user submits multiple complex print jobs consecutively, the CPU load will increase significantly, and the probability of subsequent jobs arriving is also higher. All input features are normalized before being fed into the LSTM.

[0027] The output of the first prediction model also includes two parts. The first part is the point prediction value, which is the predicted arrival rate of tasks within the future time period (such as the number of tasks arriving per minute). This value is output by the fully connected layer through a linear activation function. The second part is the confidence interval of the prediction error, which is calculated based on the residual distribution retained during training and is used to quantify the uncertainty of the prediction.

[0028] During the training phase, historical data of the printer during actual operation for at least one month was collected, including task arrival timestamps, corresponding time period types, printer operating system load, and actual arrival rate. The dataset was divided into training and validation sets in chronological order, and the mean squared error was used as the loss function. The Adam optimizer was used to train the LSTM model.

[0029] To adapt to non-stationary changes in printing task arrival patterns (e.g., the peak printing times in shopping malls from Monday to Friday differ significantly from weekends, or sudden promotional activities cause a short-term surge in tasks), preferably, in this embodiment of the invention, a sliding window online update mechanism is employed. Specifically, a fixed-length historical time window (e.g., data from the last 7 days) is maintained. Whenever an actual task arrives for a given time period, new data is added to the window, and the LSTM model is updated several times using incremental learning, without needing to retrain from scratch. This reduces computational overhead and enables rapid response to pattern changes.

[0030] Based on this, the task arrival rate output by the second prediction model is not only used to dynamically adjust the caching strategy of the L3 cache, but is also fed back to the first calculation model to reversely correct the congestion risk index of the current task. Specifically, when the predicted future task arrival rate is high and the confidence interval is narrow, i.e., the prediction confidence is high, even if the congestion risk index calculated from the characteristics of the current task itself is low, the weighting value of this risk is appropriately increased, so that the scheduler can more conservatively handle potential high load shocks in advance. Conversely, if the predicted arrival rate is low or the confidence interval is wide, the original congestion risk index is maintained. Through this setting, cache management and priority scheduling become predictive, and when facing peak loads, the L2 cache space can be shrunk in advance, low-priority tasks can be released, or the urgency of high-congestion-risk tasks can be increased in dynamic priority. By incorporating time-period periodicity and system load characteristics, the LSTM model can automatically learn the time dependence and periodicity of task arrival, significantly improving prediction accuracy. Simultaneously, the sliding window online update operation ensures that the model can adapt to changes in the working environment during long-term operation without requiring manual intervention or retraining.

[0031] Furthermore, the three-level cache structure specifically includes: The L1 cache uses a lock-free circular queue to store the data blocks currently being printed. Different data blocks of the same task are sequentially loaded into the L1 cache from the cache level where the task is located during the printing process. L2 cache uses a multi-size memory pre-allocation pool to store complete data blocks of high-priority tasks, and to accommodate some data blocks of medium-priority tasks when cache resources are sufficient; The L3 cache is used to store data blocks for low-priority tasks and adaptively selects the compression algorithm based on the task's priority.

[0032] Specifically, this invention sets up a three-level cache structure during the caching phase, and designs the three-level cache structure according to the hierarchical principle of fast to slow and small to large. The L1 cache is the smallest in capacity but the fastest in access speed, and is implemented using a lock-free circular queue. The lock-free circular queue maintains the read and write pointers of producers and consumers through atomic operations, avoiding the context switching overhead and priority inversion risk brought by traditional mutex locks, so that the data block currently being printed can be read by the scheduled thread with zero latency. When different data blocks of the same printing task are executed, they are sequentially loaded into L1 from the resident cache level (L2 or L3) to which the task belongs, and the printing thread directly consumes them from L1, thereby ensuring continuous and uninterrupted printing output.

[0033] The L2 cache is configured as a real-time task pool, employing a multi-size pre-allocated memory pool. Multi-size refers to the system pre-allocating several memory block pools of different sizes, such as 4KB, 16KB, 64KB, and 256KB, with each pool containing a fixed number of free blocks. When a complete data block needs to be stored for a high-priority task (and some medium-priority tasks when resources are plentiful), a memory block is quickly allocated from the most suitable size pool based on the actual size of the data block, and reclaimed from the corresponding pool upon release. This pre-allocation strategy avoids fragmentation and time consumption caused by dynamic memory allocation, while ensuring that high-priority task data resides in high-speed memory. The L2 cache is dedicated to storing complete data blocks for high-priority tasks, and also accommodates some data blocks for medium-priority tasks when cache resources are plentiful, thus maximizing the use of limited cache resources while ensuring fast response times for critical tasks.

[0034] The L3 cache is configured as an elastic storage area, preferably using large-capacity external storage to store complete data blocks for low-priority tasks. Due to the slow access speed and limited capacity of storage media, an adaptive compression algorithm is introduced into the L3 cache in this invention. Specifically, the compression method is determined based on the task's priority level. For low-priority and less important tasks (such as background batch log printing), lossy compression with a high compression ratio is used. For slightly higher-priority tasks, lossless compression is used. For extremely low-priority tasks or tasks with a very high historical interruption frequency, even more aggressive compression ratios can be adopted to save space. During execution, the adaptive compression algorithm sends the task's print data blocks to the compressor. The compressor maintains a scoring matrix for different algorithms and dynamically selects the most suitable compression parameters based on the task priority and the remaining capacity of the real-time cache. The compressed data blocks are stored in L3 and decompressed when needed, and may be migrated to L2.

[0035] This operation can significantly reduce the storage space occupied by the L3 cache, thereby accommodating more tasks or extending the retention time of cached data. At the same time, by differentiating compression strategies by priority, it also ensures that high-priority tasks will not incur additional access latency due to decompression, while low-priority tasks sacrifice a small amount of processing time to gain cache capacity, thus achieving a balance between resource utilization and service quality.

[0036] Furthermore, the caching strategy of dynamically adjusting the caching levels based on the task arrival rate specifically includes: When the L2 cache occupancy exceeds a preset threshold, based on the point prediction value, some data blocks of medium-priority tasks in the L2 cache are downgraded to the L3 cache, and the compression ratio of the L3 cache is increased. The number of downgraded data blocks is also dynamically adjusted based on the confidence interval width of the prediction error. When the predicted point value indicates that the future will be an idle period, the task data in the L3 cache is preloaded into the L2 cache, and the amount of preloaded data is adjusted according to the confidence interval width.

[0037] Specifically, when the L2 cache occupancy rate exceeds a preset threshold (e.g., 80%), it indicates that cache resources are strained. If the point prediction value shows that the task arrival rate will remain high or even increase further in the near future, a degradation operation is triggered. This involves migrating some data blocks of medium-priority tasks from the L2 cache to the L3 cache, and simultaneously increasing the compression ratio of the L3 cache to save storage space. In this way, the L2 cache can release space in advance to cope with upcoming high-priority tasks or a large number of new tasks. Meanwhile, considering the inherent uncertainty of prediction, this invention uses the confidence interval width of the prediction error to dynamically adjust the number of downgraded data blocks. That is, when the confidence interval is narrow, the prediction reliability is high, and a larger number of downgrades can be performed to maximize space release; when the confidence interval is wide, the prediction uncertainty is high, so the number of downgrades is reduced, adopting a conservative strategy to avoid unnecessary cache migration and performance loss due to prediction deviations.

[0038] On the other hand, when the point prediction indicates that the system will enter an idle period (i.e., the task arrival rate will decrease significantly), the system proactively preloads high-priority task data blocks from the L3 cache into the L2 cache to ensure a rapid response to new tasks after the idle period ends. Similarly, the amount of preloaded data is adaptively adjusted according to the confidence interval width. More data can be preloaded under high confidence, while only a small amount of necessary data is loaded under low confidence to prevent scarce L2 resources from being occupied due to incorrect predictions.

[0039] By implementing the above operations, cache management shifts from a passive response to a proactive adaptation, freeing up space before peak loads and pre-planning before off-peak periods, significantly reducing temporary printing interruptions caused by insufficient cache. Simultaneously, by calibrating the aggressiveness of degradation and preloading using confidence intervals, a balance is struck between prediction risk and performance gains, improving cache resource utilization while reducing the overhead of invalid migrations caused by incorrect predictions.

[0040] Furthermore, the specific form of the dynamic priority function is as follows: Dynamic priority = Initial priority × (1 + α × number of seconds waited) × (1 + β × congestion risk index) / (1 + γ × number of retries), where α, β, and γ are all adjustable parameters with positive real values, representing the waiting time weight coefficient, congestion risk weight coefficient, and retry penalty coefficient, respectively.

[0041] In this embodiment of the invention, the purpose of setting the dynamic priority function is to comprehensively reflect the multi-dimensional scheduling requirements of printing tasks in a multi-threaded concurrent environment. Specifically, the initial priority in the formula represents the inherent importance of the task itself, and the number of seconds already waited reflects the time the task has been in the queue. As the waiting time increases, the coefficient (1 + α × number of seconds already waited) increases linearly, allowing tasks that have not been executed for a long time to gradually obtain higher dynamic priorities, thereby avoiding starvation of low-priority tasks. The congestion risk index characterizes the probability that the task may cause data flow congestion or interruption during execution. The coefficient (1 + β × congestion risk index) allows high-risk tasks to obtain scheduling resources in advance, preventing them from becoming system bottlenecks. The number of retries records the number of times the task has been resubmitted due to interruption or error. The denominator (1 + γ × number of retries) lowers the priority of tasks that have failed multiple times, preventing a repeatedly erroneous task from endlessly occupying printing resources and blocking other normal tasks.

[0042] The three adjustable parameters α, β, and γ are all positive real numbers, controlling the impact of waiting time, congestion risk, and retry penalty on dynamic priority, respectively. After extensive experimental optimization, the optimal range is α from 0.01 to 0.1, with a typical value of 0.05, ensuring that the priority increases to a maximum of twice its original value after a 100-second wait. β ranges from 0.5 to 2, with a typical value of 1, ensuring that the priority doubles under high congestion risk (exponent close to 1). γ ranges from 0.1 to 0.5, with a typical value of 0.3, ensuring that the priority drops to approximately half its original value after three retries. When the queue is long and the load is heavy, the dynamic priority of each task calculated by the dynamic priority function changes in real time, inserting all pending tasks into a multi-level priority circular queue according to their dynamic priority values ​​from high to low.

[0043] The circular queue described above is internally divided into at least 256 priority levels, with higher levels indicating higher priority. The circular queue itself is implemented using a lock-free circular array, with each queue node storing a pointer to a task control block. The scheduling thread continuously polls from the highest non-empty level. Once a task is found at a level, the task pointed to by the head node is immediately retrieved, and the corresponding print data block is read from the cache level where that task resides, then handed over to the printing engine for execution. Because dynamic priorities change over time (due to increased waiting seconds or changes in the number of retries), the dynamic priorities of all tasks still in the queue that have not yet been executed are recalculated at fixed intervals and moved to the new priority level.

[0044] This invention employs a multi-level priority circular queue, with a fine-grained division of 256 levels, ensuring a clear order among tasks with similar priorities and avoiding the disorderly competition caused by coarse-grained priorities. Furthermore, the circular structure, combined with a lock-free access mode, guarantees high throughput and low latency for the scheduling thread; even in high-concurrency printing task scenarios, scheduling overhead remains at the microsecond level. Simultaneously, through real-time adjustment of the dynamic priority function, it adaptively balances the fairness of short-term waiting, the predictability of long-term congestion, and the isolation of faulty tasks.

[0045] Furthermore, when an interruption occurs during printing, the method further includes: Record the identifier of the last successfully printed data block, and determine the retention time of the incomplete data block in the cache based on the priority of the current task and the printing progress; the retention time represents the longest time that the incomplete data block in the cache can be retained after the interruption occurs, which is positively correlated with the task priority and negatively correlated with the printing progress.

[0046] As a further preferred embodiment, upon interruption recovery, if the retention period has not been exceeded, the remaining data blocks are read from the cache and printing continues from the breakpoint. Each data block is stored independently and accompanied by a checksum. During recovery, the integrity of the cached data is verified by the checksum; if the verification fails, the data block is retrieved again.

[0047] In this embodiment of the invention, by recording the identifier of the last successfully printed data block and dynamically determining the retention time of incomplete data blocks in the cache based on the priority of the current task and the printing progress, the invention can implement a differentiated cache resource release strategy after a printing interruption. Specifically, tasks with higher priority or lower printing progress receive a longer retention time, allowing for rapid recovery of high-value tasks interrupted by brief failures (such as temporary paper shortages or paper jams) without the need to retransmit large amounts of data. Meanwhile, low-priority tasks or those nearing completion release cache space promptly, preventing resources from being ineffectively occupied.

[0048] In addition, each printed data block is stored independently and includes a checksum. During recovery, the checksum is first verified to ensure the integrity of the cached data. If the checksum passes, the remaining data block is read directly from the cache and printing continues from the breakpoint. If the checksum fails, the data block is retrieved again. This setting ensures the reliability of resumed printing and effectively avoids printing anomalies or output errors caused by corrupted cached data.

[0049] Furthermore, during the printing process, the method also includes: The system monitors the operating status of the printer system in real time, adjusts the adjustable parameters in the dynamic priority function and the threshold parameters of the caching strategy online based on the monitoring results, and feeds back the actual prediction error to the second prediction model to optimize the prediction accuracy.

[0050] Furthermore, the adjustable parameters and the threshold parameters of the caching strategy are adjusted online using a Bayesian optimization algorithm, with the optimization objective being to minimize the average waiting time and interrupt recovery time of the task.

[0051] In this embodiment of the invention, by monitoring the operating status of the printer system in real time and adjusting the adjustable parameters (i.e., α, β, γ) in the dynamic priority function and the threshold parameters of the caching strategy online based on the monitoring results, the scheduling process of printing tasks is made capable of adaptive evolution. Specifically, by continuously collecting performance indicators such as the average waiting time of tasks, interruption recovery time, and cache hit rate, a parameter optimization process is automatically triggered when performance degradation or load mode drift is detected.

[0052] Furthermore, a Bayesian optimization algorithm is adopted, with the joint optimization objective of minimizing the average waiting time and interruption recovery time of the task. It efficiently searches for the optimal combination in the parameter space, avoiding the tediousness and lag of traditional parameter tuning.

[0053] Furthermore, by feeding the actual prediction error back to the second prediction model, the model can continuously correct the prediction accuracy of future task arrival rates, forming a closed-loop learning mechanism.

[0054] Based on the above operations, the present invention can significantly improve long-term stability in dynamically changing working environments, and the prediction error of the second prediction model can gradually decrease, achieving an adaptive continuous optimization effect and ensuring that the printer always works under the best scheduling strategy.

[0055] Example 2 The second aspect of this invention discloses a dynamic caching and scheduling system for thermal printer print data, the system comprising: The data acquisition module is used to acquire and extract multidimensional feature vectors of tasks, as well as collect historical task arrival data; The model building module is used to build a first computational model and a second prediction model; wherein, the multidimensional feature vector is input into the first computational model, and the initial priority and congestion risk index of the task are output through the first computational model; and the collected historical task arrival data is input into the second prediction model, and the task arrival rate in the future time period is predicted through the second prediction model. The data caching module is used to divide the data of each task into multiple data blocks, allocate the multiple data blocks of each task to the corresponding level in the three-level cache structure based on the initial priority, and dynamically adjust the caching strategy of each level of cache according to the task arrival rate. The resource scheduling module is used to determine the dynamic priority of a task based on the initial priority, congestion risk index, waiting time, and number of retries using a dynamic priority function. The tasks to be processed are placed into a multi-level priority circular queue according to the dynamic priority order. The scheduling thread retrieves the target printing tasks in the queue order and reads the corresponding data blocks from the cache level where the target printing task is located to schedule printing resources.

[0056] It should be noted that the specific implementation process of Example 2 is similar to that of Example 1, and will not be repeated in Example 2.

[0057] Finally, it should be noted that the above-described embodiments include multiple parallel implementations of the present invention. Deleting or otherwise adjusting one or more implementations will not affect the implementation of the solution. Furthermore, the method and system for dynamic caching and scheduling of thermal printer printing data disclosed in the embodiments of the present invention are merely preferred embodiments of the present invention and are only used to illustrate the technical solutions of the present invention, not to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for dynamic caching and scheduling of print data in a thermal printer, characterized in that, The method includes: The multidimensional feature vector of the task is acquired and extracted, and the multidimensional feature vector is input into the first calculation model. The first calculation model outputs the initial priority and congestion risk index of the task. The multidimensional feature vector includes the task source type, data volume, user-defined urgency label, data complexity, and historical interruption frequency. Collect historical task arrival data and input it into the second prediction model to predict the task arrival rate in the future time period. The data of each task is divided into multiple data blocks. Based on the initial priority, the multiple data blocks of each task are allocated as a whole to the corresponding level in the three-level cache structure, and the caching strategy of each level of cache is dynamically adjusted according to the task arrival rate. The dynamic priority of a task is determined by a dynamic priority function based on the initial priority, congestion risk index, waiting time, and number of retries. Tasks to be processed are placed into a multi-level priority circular queue according to their dynamic priority. The scheduling thread retrieves the target printing tasks in the queue order and reads the corresponding data blocks from the cache level where the target printing task is located to schedule printing resources. The task arrival rate is also fed back to the first calculation model to reverse the congestion risk index.

2. The method for dynamic caching and scheduling of thermal printer printing data according to claim 1, characterized in that, The first computational model is a lightweight online learning model, which includes a multi-task structure with a shared hidden layer and two independent output heads. The first output head outputs the normalized initial priority using the Sigmoid function, and the second output head outputs the congestion risk index using the ReLU function. The model weights are updated in real time using an online gradient descent algorithm, and a penalty term for the frequency of historical interruptions is introduced into the loss function.

3. The method for dynamic caching and scheduling of thermal printer printing data according to claim 1, characterized in that, The second prediction model is a time series prediction model; Input features include the timestamp sequence of historical task arrivals, time period type features, and historical load features of the printer operating system; among them, time period type features include hourly time period identifiers and weekly periodic identifiers; The second prediction model outputs the task arrival rate for the future time period, including the predicted point value and the confidence interval of the prediction error.

4. The method for dynamic caching and scheduling of thermal printer printing data according to claim 3, characterized in that, The three-level cache structure specifically includes: The L1 cache uses a lock-free circular queue to store the data blocks currently being printed. Different data blocks of the same task are sequentially loaded into the L1 cache from the cache level where the task is located during the printing process. L2 cache uses a multi-size memory pre-allocation pool to store complete data blocks of high-priority tasks, and to accommodate some data blocks of medium-priority tasks when cache resources are sufficient; The L3 cache is used to store data blocks for low-priority tasks and adaptively selects the compression algorithm based on the task's priority.

5. The method for dynamic caching and scheduling of thermal printer printing data according to claim 4, characterized in that, The caching strategy of dynamically adjusting the cache levels based on the task arrival rate specifically includes: When the L2 cache occupancy exceeds a preset threshold, based on the point prediction value, some data blocks of medium-priority tasks in the L2 cache are downgraded to the L3 cache, and the compression ratio of the L3 cache is increased. The number of downgraded data blocks is also dynamically adjusted based on the confidence interval width of the prediction error. When the predicted point value indicates that the future will be an idle period, the task data in the L3 cache is preloaded into the L2 cache, and the amount of preloaded data is adjusted according to the confidence interval width.

6. The method for dynamic caching and scheduling of thermal printer printing data according to claim 1, characterized in that, The specific form of the dynamic priority function is as follows: Dynamic priority = Initial priority × (1 + α × number of seconds waited) × (1 + β × congestion risk index) / (1 + γ × number of retries), where α, β, and γ are all adjustable parameters with positive real values, representing the waiting time weight coefficient, congestion risk weight coefficient, and retry penalty coefficient, respectively.

7. The method for dynamic caching and scheduling of thermal printer printing data according to claim 1, characterized in that, When a printing interruption occurs, the method further includes: Record the identifier of the last successfully printed data block, and determine the retention time of the incomplete data block in the cache based on the priority of the current task and the printing progress; the retention time represents the longest time that the incomplete data block in the cache can be retained after the interruption occurs, which is positively correlated with the task priority and negatively correlated with the printing progress.

8. The method for dynamic caching and scheduling of thermal printer printing data according to claim 1, characterized in that, During the printing process, the method further includes: The system monitors the operating status of the printer system in real time, adjusts the adjustable parameters in the dynamic priority function and the threshold parameters of the caching strategy online based on the monitoring results, and feeds back the actual prediction error to the second prediction model to optimize the prediction accuracy.

9. The method for dynamic caching and scheduling of thermal printer printing data according to claim 8, characterized in that, The adjustable parameters and the threshold parameters of the caching strategy are adjusted online using a Bayesian optimization algorithm, with the optimization objective being to minimize the average waiting time and interrupt recovery time of the task.

10. A dynamic caching and scheduling system for thermal printer print data, the system being implemented based on the method described in any one of claims 1-9, characterized in that, The system includes: The data acquisition module is used to acquire and extract multidimensional feature vectors of tasks, as well as collect historical task arrival data; The model building module is used to build a first computational model and a second prediction model. The multidimensional feature vector is input into the first computational model, which outputs the initial priority and congestion risk index of the task. Collected historical task arrival data is input into the second prediction model, which predicts the task arrival rate within a future time period. The multidimensional feature vector includes task source type, data volume, user-defined urgency label, data complexity, and historical interruption frequency. The data caching module is used to divide the data of each task into multiple data blocks, allocate the multiple data blocks of each task to the corresponding level in the three-level cache structure based on the initial priority, and dynamically adjust the caching strategy of each level of cache according to the task arrival rate. The resource scheduling module is used to determine the dynamic priority of a task based on the initial priority, congestion risk index, waiting time, and number of retries using a dynamic priority function. The tasks to be processed are placed into a multi-level priority circular queue according to the dynamic priority order. The scheduling thread retrieves the target printing tasks in the queue order and reads the corresponding data blocks from the cache level where the target printing task is located to schedule printing resources. The task arrival rate is also fed back to the first calculation model to reverse the congestion risk index.

Citation Information

Patent Citations

  • Real-time image printing task scheduling method and system based on dynamic queue management

    CN121742781A