# Patent

## Title
Method for prioritizing tasks queued at a server system

## Abstract

An algorithm for assigning priorities to tasks queued for processing by users based on how heavily each task's user used the system resources in the past, including the number of tasks queued by the user in the past, the volume of these tasks, and the amount of processor time used. In the OCR context, the tasks are graphic files placed on servers and chosen for processing in accordance with the assigned priorities.

## Background
CROSS REFERENCE TO RELATED APPLICATIONS
The present application is a Continuation of U.S. patent application Ser. No. 14/571,832, filed Dec. 16, 2014, which will issue as U.S. Pat. No. 9,378,061 on Jun. 28, 2016, which claims the benefit of priority to Russian Patent Application No. 2014125148, filed Jun. 23, 2014; disclosures of the priority applications are incorporated herein by reference in their entirety for all purposes.


FIELD OF THE INVENTION
The present invention relates to prioritizing tasks in a queue performed by a local or a cloud-based server system.
BACKGROUND OF THE INVENTION
In a variety of situations, when several queued tasks have to be performed on one or several computers or processors for several users, it is necessary for a given available processor to decide which of the available pending tasks to perform first. Systems processing large numbers of tasks queued by users may experience issues related to load buffering. When a task takes a long time to process users may queue work items faster than they can be processed.
One approach is to put new tasks into a queue upon arrival to be processed in the first-in-first-out (FIFO) manner by the processor. This principle is straightforward one user. However, for multiple users queuing tasks at random times, when all users expect reasonably fast processing, this approach might be unsatisfactory.
For example, suppose every task takes 10 seconds to be processed. A user A comes first and quickly puts one hundred tasks into the queue so that it will take 17 minutes to process all of them. One minute after user A had put his tasks into the queue, a user B queues a single task. If the system follows the FIFO rule, the single task from user B would not be processed until all tasks of user A are processed about 16 minutes later. User B has to wait about 16 minutes to just have a single task processed in 10 seconds.
Another common approach is to assign to each task a number so that the processor can choose a task with a highest priority.
When several users provide tasks for the processors, care must be taken to prioritize tasks in accordance with users' expectations, for example, by dividing processor time and other resources equitably between the users. The equitability in this context may imply equitable sharing of processor time, of how frequently tasks are provided by the users, and how large the user's tasks are. The new tasks of a user who recently used more processor time, posted more tasks and more cumulative task volume should have comparatively smaller priority than a new task from a less demanding user.
One example of such tasks is optical character recognition (OCR) processing of images (in any graphic format, such as pdf, tiff, jpeg, etc.) containing text. In this case the size or volume of each task is measured in pages. The processing time of a task is not necessarily directly related to the number of pages in the task, at least because of the amount of text on different pages within different tasks may vary.
SUMMARY OF THE INVENTION
The tasks may reside on a cloud server system, on a remote or local network server, or on the same computer that is responsible for processing the tasks (this computer then functions as the server) as long as the users are able to upload the tasks onto the system. Each computer or processor, upon completing one task, requests the task with the highest priority available from the server. The processor then beings processing the task and, while doing it, does not process any other task, or interrupts for processing any other task.
According to the present invention, each task queued in the system is assigned a priority selected from the priority range, for example, from 0 to 255, with number 0 being the highest priority that can be assigned to a task. Different tasks belonging to the same user may be assigned different priorities depending on the usage patterns. Normally, the priority of a task remains unchanged for the lifetime of the task.
Upon a new task's arrival the system looks at how intensively the user was submitting new items in the nearest past and assigns the new task a priority so that the tasks from users who infrequently queue small number of tasks get better priority, and tasks from users who intensively submit large numbers of tasks get worse priorities. The system further deviates from the FIFO approach in that the tasks are first selected by priority—tasks with higher priority are handled first—and the tasks with the same priority are ordered by their arrival time.
In the OCR context the tasks are typically image files or PDF files that can contain more than one page. The system uses the number of pages in addition to the number of tasks to analyze the usage pattern because the time needed to process a task is often approximately proportional to the number of pages in the task and so the priority of the future tasks of the same user should be affected by the number of pages, not only by the number of tasks queued by the user.
In order to characterize used processor time used, number of tasks, and task volume (e.g. number of pages to be OCRed) a variety of monotonic metrics may be used. Monotonic metrics are functions (with arguments, such as time or number of pages or tasks) that depend on their arguments monotonically, i.e., entirely non-increasing or entirely non-decreasing on its entire relevant domain. Monotonic dependency is a dependency that is expressed by a monotonic function.
Embodiments of this invention include methods for prioritizing for at least one processor a plurality of tasks of a plurality of users, comprising, for an unprocessed task provided by a user from the plurality of users, assigning a numerical priority to the user; calculating a monotonic metric M1 for cumulative processor time used by prior tasks provided by the user on the at least one processor within a prior time period T1; calculating a monotonic metric M2 for time interval between the unprocessed task and a preceding task provided by the user for the at least one processor within a prior time period T2; calculating a monotonic metric M3 for cumulative task volume provided by the user for the at least one processor within a prior time period T3; reducing the user's numerical priority monotonically depending on M1, M2, and M3; and assigning the user's numerical priority to the unprocessed task; wherein unprocessed tasks with higher priorities are selected for processing on the at least one processor before unprocessed tasks with lower priorities; and wherein the at least one processor sequentially executes only one task at a time
Embodiments of this invention also include system comprising a computer server or a cloud server storing tasks and storing software capable of executing instructions for prioritizing for at least one processor a plurality of tasks of a plurality of users, comprising, for an unprocessed task provided by a user from the plurality of users, assigning a numerical priority to the user; calculating a monotonic metric M1 for cumulative processor time used by prior tasks provided by the user on the at least one processor within a prior time period T1; calculating a monotonic metric M2 for time interval between the unprocessed task and a preceding task provided by the user for the at least one processor within a prior time period T2; calculating a monotonic metric M3 for cumulative task volume provided by the user for the at least one processor within a prior time period T3; reducing the user's numerical priority monotonically depending on M1, M2, and M3; and assigning the user's numerical priority to the unprocessed task; wherein unprocessed tasks with higher priorities are selected for processing on the at least one processor before unprocessed tasks with lower priorities; and wherein the at least one processor sequentially executes only one task at a time.
Embodiments of this invention also include a physical, non-transitory computer storage medium having stored thereon a program which when executed by a processor, performs instructions for prioritizing for at least one processor a plurality of tasks of a plurality of users, comprising, for an unprocessed task provided by a user from the plurality of users, assigning a numerical priority to the user; calculating a monotonic metric M1 for cumulative processor time used by prior tasks provided by the user on the at least one processor within a prior time period T1; calculating a monotonic metric M2 for time interval between the unprocessed task and a preceding task provided by the user for the at least one processor within a prior time period T2; calculating a monotonic metric M3 for cumulative task volume provided by the user for the at least one processor within a prior time period T3; reducing the user's numerical priority monotonically depending on M1, M2, and M3; and assigning the user's numerical priority to the unprocessed task; wherein unprocessed tasks with higher priorities are selected for processing on the at least one processor before unprocessed tasks with lower priorities; and wherein the at least one processor sequentially executes only one task at a time.
Embodiments of the present invention may also include calculating a monotonic metric M4 for cumulative task volume provided by the user for the at least one processor within an earlier time period T4; and reducing the user's numerical priority monotonically depending on M1, M2, M3, and M4.
In embodiments of the present invention, at least one processor may execute any of the plurality of tasks entirely without interrupting for any other task of the plurality of tasks or simultaneously processing any other task of the plurality of tasks.
In embodiments of the present invention, the user's numerical priority may be an integer within an interval.
In embodiments of the present invention, among unprocessed tasks with equal priorities the task provided for processing at an earlier moment may be selected for processing on the at least one processor before other unprocessed tasks with equal priorities.
The above and other features of the invention including various novel details of construction and combinations of parts, and other advantages, will now be more particularly described with reference to the accompanying drawings and pointed out in the claims. It will be understood that the particular method and device embodying the invention are shown by way of illustration and not as a limitation of the invention. The principles and features of this invention may be employed in various and numerous embodiments without departing from the scope of the invention.



BRIEF DESCRIPTION OF THE DRAWINGS
In the accompanying drawings, reference characters refer to the same parts throughout the different views. The drawings are not necessarily to scale; emphasis has instead been placed upon illustrating the principles of the invention. Of the drawings:
FIG. 1 is a flow chart of first several steps in one particular embodiment of the invention. Element A shows how the flowchart of FIG. 1 connects to the flowchart of FIG. 2.
FIG. 2 is a flow chart of several steps in the particular embodiment of the invention subsequent to the steps shown in FIG. 1. Element B shows how the flowchart of FIG. 2 connects to the flowchart of FIG. 3.
FIG. 3 is a flow chart of final several steps in the particular embodiment of the invention subsequent to the steps shown in FIG. 2.
FIG. 4 is a schematic illustration of a system implementing the present invention for several users and several processors using a cloud server.
FIG. 5 is a schematic illustration of a system implementing the present invention for several users and several processors using a computer server.



DETAILED DESCRIPTION OF THE INVENTION
The system stores five variables for each user: user priority (not to be confused with a task's priority), number of pages last hour, number of pages last minute, last hour end, and last minute end. The latter two variables are stored so that the system is not required to constantly update all the data every time a user posts a task.
Each new task is characterized by the number of pages in the task (or, more generally, the task's size or volume), by the user, who placed the task in the queue, by whether the task is ready for processing, and by priority of the task (which is initially undefined). They are stored with the task in the task's local memory as variables in addition to other variables needed for the algorithm.
The purpose of the algorithm described below is to assign a priority to the task. In this embodiment, the priority is an integer number between 0 and 255.
As shown in FIG. 1, when the task is placed on a server, the task is ready for processing variable is set to false (flowchart element 1). Then the variables associated with the user are fetched (flowchart element 2).
The task priority by load in local memory is set to zero. The user last hour end time is copied into the local memory as the local last hour end, and the user number of pages last hour is copied into the local memory as the local number of pages last hour (flowchart element 3).
If (flowchart element 4) the local last hour end time is undefined (i.e. has no value) or less than 30 minutes before the current time (otherwise, the next steps are shown in FIG. 2):
The system scans the tasks queued by the user within an hour before the current time and sets the local number of pages last hour to the total number of pages in all these tasks (sum of numbers of pages over the tasks queued by the user over the last hour). The local last hour end is set to current time (flowchart element 5).
The system scans the tasks queued by the user and sets the local number of seconds last hour to the total number of milliseconds each task took to process over the last hour divided by one thousand (flowchart element 6).
The local number of seconds last hour obtained in the previous step is used to compute the task priority by load according to the following rule which approximates logarithmic function (flowchart element 7):

    
    
        if the local number of seconds last hour is less than 100, the task priority by load is 0, otherwise
        if the local number of seconds last hour is less than 300, the task priority by load is 3, otherwise
        if the local number of seconds last hour is less than 700, the task priority by load is 5, otherwise
        if the local number of seconds last hour is less than 1500, the task priority by load is 8, otherwise
        if the local number of seconds last hour is less than 4000, the task priority by load is 11, otherwise the task priority by load is 15.
    
    


The task priority by load and the local number of pages last hour being obtained, the subsequent steps are shown in FIG. 2.
The user priority is copied into the task old priority. The task new priority is set to the task old priority. The user last minute end time is copied into the local last minute end, and the user number of pages last minute is copied into the local number of pages last minute (flowchart element 8).
If (flowchart element 9) the local last minute end time is undefined (i.e. has no value) or is smaller than one minute ago (otherwise, skip the next three paragraphs):
If (flowchart element 10) the local when the last minute end is not undefined (has value), the whole minutes variable is set to the current time rounded to the whole number of minutes, and the stored whole minutes variable is set to the local last minute rounded to the whole number of minutes (flowchart element 11). Otherwise, skip the next paragraph.
If (flowchart element 12) the stored whole minutes variable integer divided by 20 is smaller than the whole minutes variable integer divided by 20 (so that this step is executed at most once per 20 minutes), the task new priority is set to the task local old priority minus one minus (the whole minutes minus the stored whole minutes) integer divided by 20 (flowchart element 13).
The local last minute end is set to current time. The local number of pages last minute is set to zero (flowchart element 14).
The local number of pages last minute is increased by the number of pages in the new task (flowchart element 15).
The local number of pages last minute being obtained, the subsequent steps are shown in FIG. 3.
If the local number of pages last hour is less than 5, the task hour priority is set to 0 and the minute pages limit is set to 3, otherwise

    
    
        if the local number of pages last hour is less than 10, the task hour priority is set to 1 and the minute pages limit is set to 3, otherwise
        if the local number of pages last hour is less than 50, the task hour priority is set to 2 and the minute pages limit is set to 5, otherwise
        if the local number of pages last hour is less than 100, the task hour priority is set to 3 and the minute pages limit is set to 10, otherwise
        if the local number of pages last hour is less than 250, the task hour priority is set to 4 and the minute pages limit is set to 15, otherwise
        if the local number of pages last hour is less than 512, the task hour priority is set to 5 and the minute pages limit is set to 22, otherwise
        if the local number of pages last hour is less than 1024, the task hour priority is set to 6 and the minute pages limit is set to 32,
        otherwise, the task hour priority is set to the integer part of the natural logarithm of the local number of pages last hour less 2, and the minute pages limit is set to the integer part of the square root of the local number of pages last hour (flowchart element 16).
    
    


The task minute priority is set to zero (flowchart element 17).
If (flowchart element 18) the local number of pages last minute is greater than the minute pages limit:

    
    
        if the local number of pages last minute is less than 4, the task minute priority is set to 0, otherwise
        if the local number of pages last minute is less than 16, the task minute priority is set to 5, otherwise
        if the local number of pages last minute is less than 23, the task minute priority is set to 7, otherwise
        if the local number of pages last minute is less than 91, the task minute priority is set to 10, otherwise
        if the local number of pages last minute is less than 180, the task minute priority is set to 12,
        otherwise, the task minute priority is set to the integer part of the natural logarithm of (the local number of pages last minute multiplied by 60) less 2 (flowchart element 19).
    
    


The task new priority by number of pages is set to the greater of the task hour priority and the task minute priority (flowchart element 20).
The task new priority is set to the lesser of the task new priority by number of pages and the task new priority. If the task new priority is larger than 255, the task new priority is set to 255; if the task new priority is less than zero then the task new priority is set to zero (flowchart element 21).
The task new priority is set to the lesser of the task priority by load and the task new priority (flowchart element 21).
The user last hour end is set to the local last hour end. The user last minute end is set to the local last minute end. The user number of pages last hour is set to the local number of pages last hour. The user number of pages last minute is set to the local number of pages last minute. The user priority is set to the task new priority (flowchart element 22).
The priority of the new task is set to the task new priority; the task is ready for processing variable is set to true (flowchart element 23).
Now the new task on the server is ready to be fetched by the processor when appropriate according to the new task's priority set as described hereinabove.
FIG. 4 shows a system implementing, for several users and several processors, using a cloud server, a method for prioritizing tasks comprising, for an unprocessed task provided by a user assigning a numerical priority to the user; calculating a monotonic metric M1 for cumulative processor time used by prior tasks provided by the user on the at least one processor within a prior time period T1; calculating a monotonic metric M2 for time interval between the unprocessed task and a preceding task provided by the user for the at least one processor within a prior time period T2; calculating a monotonic metric M3 for cumulative task volume provided by the user for the at least one processor within a prior time period T3; reducing the user's numerical priority monotonically depending on M1, M2, and M3; and assigning the user's numerical priority to the unprocessed task; wherein unprocessed tasks with higher priorities are selected for processing on the at least one processor before unprocessed tasks with lower priorities; and wherein the at least one processor sequentially executes only one task at a time. Users 1001, 1002, and 1003, upload tasks (for example, OCR tasks) onto the cloud server 1011, where a priority is set for each task in accordance with a method embodying this invention. The tasks fetched from the cloud server and processed (for example, by OCR processing) by the processors 1021, 1022, and 1023. The users and processors connect with the cloud server via Internet, another network, wirelessly, or directly.
FIG. 5 shows a system implementing for several users and several processors using a computer server, a method for prioritizing tasks comprising, for an unprocessed task provided by a user assigning a numerical priority to the user; calculating a monotonic metric M1 for cumulative processor time used by prior tasks provided by the user on the at least one processor within a prior time period T1; calculating a monotonic metric M2 for time interval between the unprocessed task and a preceding task provided by the user for the at least one processor within a prior time period T2; calculating a monotonic metric M3 for cumulative task volume provided by the user for the at least one processor within a prior time period T3; reducing the user's numerical priority monotonically depending on M1, M2, and M3; and assigning the user's numerical priority to the unprocessed task; wherein unprocessed tasks with higher priorities are selected for processing on the at least one processor before unprocessed tasks with lower priorities; and wherein the at least one processor sequentially executes only one task at a time. Users 2001 and 2002, upload tasks (for example, OCR tasks) onto the computer server 2011, where a priority is set for each task in accordance with a method embodying this invention. The tasks fetched from the computer server and processed (for example, by OCR processing) by the processors 2021 and 2022. The users and processors connect with the computer server via Internet, another network wirelessly, or directly.
While this invention has been particularly shown and described with references to preferred embodiments thereof, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the scope of the invention encompassed by the appended claims.

## Claims

1. A method for prioritizing tasks using a computer server, comprising:
identifying, by the computer server, a first task to be executed by a processor, the first task provided by a user at a first time;
determining, by the computer server, a cumulative processor time for an execution of a set of tasks by the processor during a first prior time interval, wherein the first prior time interval ends before the first time, and wherein each task of the set of tasks is provided by the user;
computing, by the computer server, a first metric based on the cumulative processor time;
identifying, by the computer server, a second task provided by the user at a second time that is before the first time;
computing, by the computer server, a second metric based on a time difference between the first time and the second time;
determining, by the computer server, a cumulative task volume for one or more tasks provided by the user during a second prior time interval, wherein the second prior time interval ends before the first time;
computing, by the computer server, a third metric based on the cumulative task volume;
determining, by the computer server, a priority for the user based on at least one of the first metric, the second metric, or the third metric;
assigning, by the computer server, the priority to the first task; and
scheduling, in view of the priority, an execution of the first task to be performed by the processor.

2. The method of claim 1 wherein the determining of the priority is in view of a prior priority for the user.

3. The method of claim 2 wherein the determining of the priority comprises reducing the prior priority.

4. The method of claim 1 wherein the first metric is a monotonic function of the cumulative processor time.

5. The method of claim 1 wherein the second metric is a monotonic function of the time difference between the first time and the second time.

6. The method of claim 1 wherein the third metric is a monotonic function of the cumulative task volume.

7. The method of claim 1 wherein the processor executes at most one task at a time.

8. An apparatus comprising:
a network interface device; and
a processor, operatively coupled to the network interface device, to:
receive, via the network interface device, a first task to be executed, wherein the first task is provided by a user at a first time;
determine a cumulative processor time for an execution of a set of tasks during a first prior time interval, wherein the first prior time interval ends before the first time, and wherein each task of the set of tasks is provided by the user;
compute a first metric based on the cumulative processor time;
identify a second task provided by the user at a second time that is before the first time;
compute a second metric based on a time difference between the first time and the second time;
determine a cumulative task volume for one or more tasks provided by the user during a second prior time interval, wherein the second prior time interval ends before the first time;
compute a third metric based on the cumulative task volume;
determine a priority for the user based on at least one of the first metric, the second metric, or the third metric;
assign the priority to the first task; and
schedule an execution of the first task in view of the priority.

9. The apparatus of claim 8 wherein the determining of the priority is in view of a prior priority for the user.

10. The apparatus of claim 9 wherein the determining of the priority comprises reducing the prior priority.

11. The apparatus of claim 8 wherein the first metric is a monotonic function of the cumulative processor time.

12. The apparatus of claim 8 wherein the second metric is a monotonic function of the time difference between the first time and the second time.

13. The apparatus of claim 8 wherein the third metric is a monotonic function of the cumulative task volume.

14. A non-transitory computer-readable storage medium comprising instructions that when executed by a processor, cause the processor to:
identify a first task to be executed, the first task provided by a user at a first time;
determine a cumulative processor time for an execution of a set of tasks during a first prior time interval, wherein the first prior time interval ends before the first time, and wherein each task of the set of tasks is provided by the user;
compute a first metric based on the cumulative processor time;
identify a second task provided by the user at a second time that is before the first time;
compute a second metric based on a time difference between the first time and the second time;
determine a cumulative task volume for one or more tasks provided by the user during a second prior time interval, wherein the second prior time interval ends before the first time;
compute a third metric based on the cumulative task volume;
determine a priority for the user based on at least one of the first metric, the second metric, or the third metric;
assign the priority to the first task; and
schedule an execution of the first task in view of the priority.

15. The non-transitory computer-readable storage medium of claim 14 wherein the determining of the priority is in view of a prior priority for the user.

16. The non-transitory computer-readable storage medium of claim 15 wherein the determining of the priority comprises reducing the prior priority.

17. The non-transitory computer-readable storage medium of claim 14 wherein the first metric is a monotonic function of the cumulative processor time.

18. The non-transitory computer-readable storage medium of claim 14 wherein the second metric is a monotonic function of the time difference between the first time and the second time.

19. The non-transitory computer-readable storage medium of claim 14 wherein the third metric is a monotonic function of the cumulative task volume.

20. The non-transitory computer-readable storage medium of claim 14 wherein the processor executes at most one task at a time.