Krang Scheduler Technical Design

This documents the design of the Krang scheduler daemon. Krang's scheduler is responsible for running scheduled jobs at their appointed time. Things like publishing, alerts and expiration can all be scheduled through the user interface.

Goals

The scheduler must:

  1. Run jobs as close to on-time as is feasible.

  2. Run time-sensitive jobs, like alerts, before less sensitive ones, like daily publish runs.

  3. Be memory efficient. Since the scheduler will run indefinitely even a small leak will eventually become a big problem.

Modules

The scheduler will be constructed using the following modules:

Scheduler Logic

Each time the scheduler wakes up to run it performs the following steps:

  1. Collect a list of jobs ready to run, sorted by priority and lateness.

  2. Partition jobs into chunks where chunk size is chosen to limit potential memory usage and improve performance on multi-processing systems.

  3. Fork a child to run each chunk. The child will execute each job in order and then exit, freeing any memory used. The number of children forked to run simultaneously will be configurable (ScheduleParallel).

  4. Mark completed jobs finished.

  5. Check again for jobs ready to run, if found goto step 1. If not, sleep() for a configurable period (ScheduleInterval) and then goto step 1.