Configure job throttling in Cratis Chronicle Server
Chronicle Server’s job system can be configured to limit the number of parallel job steps to prevent excessive CPU usage.
Configuration
Section titled “Configuration”The maximum number of parallel job steps can be configured using the MaxParallelSteps option in chronicle.json:
{ "Jobs": { "MaxParallelSteps": 4 }}| Property | Type | Default | Description |
|---|---|---|---|
| MaxParallelSteps | number | Environment.ProcessorCount - 1 | Maximum number of parallel job steps (minimum 1) |
| MaxActiveStepsPerJob | number | 4 × the effective maximum parallel steps, at least 32 | Maximum number of steps a single job keeps active at once (minimum 1) |
| DeadJobThreshold | timespan | 01:00:00 |
Age after which a job that is still preparing and has no steps is treated as dead and becomes a candidate for cleanup. Lower it if failed starts leave jobs behind that you want removed sooner |
| CleanupCadence | timespan | 01:00:00 |
How often the scavenger checks for and removes dead jobs |
| StepCheckpointBatchInterval | number | 100 | Number of handled batches after which a replay or catch-up step makes its progress checkpoint durable. A larger value means fewer writes and a longer re-scan after a crash. See Step checkpoints |
| StepCheckpointFlushInterval | timespan | 00:00:05 |
Longest time a step holds an unpersisted checkpoint, however few batches it has reported. Zero or less turns the timed flush off |
The limit that applies is the smaller of Jobs:MaxParallelSteps and Observers:MaxConcurrentPartitions (default 32, see Observers). With the defaults, Jobs:MaxParallelSteps only has an effect below 32, so raising it above 32 needs Observers:MaxConcurrentPartitions raised as well.
Alternatively, you can use environment variables:
Cratis__Chronicle__Jobs__MaxParallelSteps=4Step checkpoints
Section titled “Step checkpoints”A replay or catch-up step reports progress after every batch it hands off. Writing the whole step document each time is costly, so the write is debounced: the checkpoint becomes durable after StepCheckpointBatchInterval batches, after StepCheckpointFlushInterval of idle time, and on any other state write such as completion, failure or stop. A step resumes from its last durable checkpoint, so a crash between writes re-delivers the batches handled since then.
That re-delivery is harmless for read models keyed by event source id, because readModels.guardSinkWritesOnWatermark (default true, see Read models) makes the repeated writes no-ops. A projection that collapses several event sources onto one document checkpoints after every batch instead. Keep the defaults unless a replay is write-bound and you accept a longer re-scan after a crash.
Active steps per job
Section titled “Active steps per job”A job with thousands of steps, such as the catch-up of an observer with thousands of partitions, does not activate a
grain for every step at once. It keeps Jobs:MaxActiveStepsPerJob steps active and starts the next one each time a
step reaches an outcome; the steps not yet started stay in storage. Only MaxParallelSteps of the active steps run at
a time, so the limit only needs to keep those slots fed. Lower it to hold less memory during a large catch-up, or
raise it if steps are short and the slots sit idle between them.
Cratis__Chronicle__Jobs__MaxActiveStepsPerJob=64Default Behavior
Section titled “Default Behavior”If MaxParallelSteps is not configured, Chronicle uses a sensible default:
- Default value:
Environment.ProcessorCount - 1 - Minimum value:
1(even on single-core systems)
For example, on an 8-core system, the default would be 7 parallel steps.
How It Works
Section titled “How It Works”- Each job step attempts to acquire a slot before executing.
- If all slots are in use, the step waits in a queue.
- When a step completes (successfully or with an error), it releases its slot.
- The next waiting step can then acquire the released slot.
This ensures that the job system never uses more than the configured number of CPU cores simultaneously.
Use Cases
Section titled “Use Cases”High-throughput systems: Limit parallel steps to leave CPU resources for other operations:
{ "Jobs": { "MaxParallelSteps": 2 }}Dedicated job processing: Use more CPU cores for job processing:
{ "Jobs": { "MaxParallelSteps": 16 }}Testing environments: Reduce resource usage:
{ "Jobs": { "MaxParallelSteps": 1 }}