Application-level throttling with a priority queue
In task scheduling, you can use two strategies to implement application-level throttling: enabling flow control with a specified queue size, or configuring a preemptive priority queue. These methods help ensure the stability of your scheduling system and the timely execution of critical tasks. This topic describes how to effectively manage application-level resources and task priority scheduling.
Use cases
Your system can face immense pressure when dealing with sudden spikes in task scheduling. For example, if many daily tasks are scheduled to start at the same time, the concurrent load can overwhelm your backend services, risking system failure. To prevent this, you can use a queueing mechanism in task scheduling to limit the number of concurrent tasks within an application. By dispatching tasks incrementally, you ensure the efficient use of system resources and maintain stable operations.
Procedure
Enable flow control and set queue size
-
When you create or edit an application group, you can enable the flow control switch in the advanced configuration section. This feature is disabled by default. For more information about how to create an application group, see Create an application group.
After you enable the switch, you can configure the number of concurrent task instances. This setting defines the maximum number of task instances that can run at the same time for the application. Tasks that exceed this limit are not discarded. Instead, they are placed in a queue to await execution.
-
In this application group, create three tasks and click Run Once for each in the Actions column.
-
In the left-side navigation pane, go to the Execution List page and select the Task Instance List tab. The first triggered task, hello_jobA, is running, while hello_jobB and hello_jobC are waiting in the pool.
-
After hello_jobA succeeds, hello_jobB is dispatched from the queue for execution.
At this point, the status of hello_jobB in the instance list changes to running, while hello_jobC remains in the pool.
Configure a preemptive priority queue
For example, YARN uses priority queues to isolate resources for tasks with different priorities.
The Application Queues panel in the YARN ResourceManager shows the capacity usage for the root, research, and default queues. The root queue is at 100.0% capacity, the research sub-queue is at 93.8%, and the default sub-queue is at 101.6%, which has exceeded its allocated capacity. This shows how resources are isolated and how tasks with different priorities compete for them.
The following procedure describes how SchedulerX combines application-level throttling and task priority to implement a preemptive priority queue.
-
Tasks can be assigned priorities. Within the same application, if multiple tasks are scheduled at the same time, higher-priority tasks are dispatched first.
During task creation, in the Basic Configuration step, the Priority drop-down list provides four options: low, medium, high, and very high.
-
Enable flow control for the sample application dts-all.hxm, and set the number of concurrent task instances to 1 for easier observation. Then, create three tasks with high, medium, and low priorities. Trigger each task once in the following order: medium priority, low priority, and then high priority.
The task list on the console's Task Management page shows the three created tasks. The Priority column is marked as high, medium, and low respectively, and each task has a Run once button in the Actions column.
-
In the left-side navigation pane, go to the Execution List page and select the Task Instance List tab. When the medium-priority task is triggered, it runs immediately because the queue is empty.
At this time, the status of both the high-priority task and the low-priority task is pool, while the status of the medium-priority task is running.
-
After the medium-priority task completes, an execution slot becomes available in the queue. The high-priority task then preempts the low-priority task and begins to run.
At this point in the task list, the status of the medium-priority task is succeeded, the status of the high-priority task is running, and the low-priority task remains in the pool, waiting to be scheduled.
FAQ
-
If I set the priority for all my tasks to very high, does it guarantee they will be scheduled before tasks from other users?
No. Task priority is scoped to the application level. It only affects the scheduling order of tasks within that specific application and does not affect other applications.
-
Can I use queue-based flow control for tasks that run every minute?
This feature is designed for scenarios with sudden traffic spikes. It is not recommended for high-volume, minute-level schedules, as this can cause the queue to grow indefinitely. For such cases, consider implementing client-side throttling or scaling up your clients to handle the load.