Assigning Tasks to Workers
The scheduler assigns each inbound task to a worker. That worker alone processes the task message in a data callback function.
Worker Weight
Relative worker weights assist the scheduler in assigning tasks. When the scheduler receives a task, it assigns the task to the available worker with the greatest worker weight. The default worker weight is 1.
The scheduler applies a round-robin ordering to distribute tasks among several workers equivalent with equal weight.
Availability
When the scheduler receives a task, it assigns the task to an available worker with the greatest worker weight.
A worker is considered available unless either of these conditions are true:
• | The pending tasks assigned to the worker exceed its task capacity. |
• | The worker is also the scheduler. (The scheduler assigns tasks to its own worker only when all other workers are busy.) |
Task Capacity
Task capacity is the maximum number of tasks that a worker can accept. When the number of accepted tasks reaches this maximum, the worker cannot accept additional tasks until it completes one or more of them.
When the scheduler receives a task, it assigns the task to the worker with the greatest worker weight—unless the pending tasks assigned to that worker exceed its task capacity. When the preferred worker has too many tasks, the scheduler assigns the new inbound task to the worker with the next greatest worker weight.
The main task of a scheduler is to distribute tasks to workers. Therefore its task capacity should be either 1 (it can assign itself only one task) or zero (it is a dedicated scheduler—that is, it never accepts tasks).
The default worker task capacity is 1. Programmers can tune task capacity based on two factors:
• | Multi-tasking program on multiprocessing hardware. |
• | Communication time lag. |
Tuning for Multiprocessing Hardware
Multiprocessing can raise the task capacity of a worker program.
On a multi-processing computer, a multi-threaded program that devotes n threads on n processors to inbound tasks can have task capacity n.
When programming a multi-threaded worker, ensure that the listener object that receives the tasks is set for explicit confirmation of certified messages, and that each thread explicitly confirms each task message when it finishes processing the task.
Tuning for Communication Time Lag
In most distributed queue applications, the communication time is an insignificant fraction of the task turnaround time. That is, the time required to assign a task and signal its completion is very small compared to the time required to process the task. For example, when average task turnaround time is 2 seconds, of which communication time contributes only 10 milliseconds to the total, then task capacity is the same as the number of processors or threads.
However, in some situations communication time can be significant—for example, when the group members are distributed at distant sites connected by a WAN. When communication time is significant, the meaning of task capacity changes; instead of signifying the number of tasks that a worker can process concurrently, it signifies the number of tasks that can fill the worker’s capacity despite the communication time lag.
In most situations, a simple procedure computes a reasonable task capacity. For each worker, do these steps:
Procedure
1. | Measure the average round-trip communication time between scheduler and worker—that is, the time to send an assignment message and return a result message, without any task processing time intervening. |
2. | Measure the average task processing time, without any communication time. |
3. | Divide the average round-trip communication time by the average task processing time; round up to the nearest integer; add 1. The result is the theoretical task capacity that minimizes idle time for the worker. |
For example, when the average round-trip time is 500 milliseconds, and the average task processing time is 1 second, then setting the task capacity to 2 minimizes the worker’s idle time between tasks.
When tuning task capacity to compensate for communication time lag, balance is critical. Underloading a worker (by setting its tasks capacity too low) can cause the worker to remain idle while it waits for the scheduler to assign its next task. Conversely, overloading a worker (by setting its task capacity too high) can cause some assigned tasks to wait, while other workers that might have accepted those tasks remain idle. Tune performance by empirical testing.
Task Capacity
Warning |
Tuning task capacity to compensate for communication time lag is more complicated than it might seem. For this purpose, use caution when setting task capacities greater than 1. |