Time-based fairshare is a feature in KAI Scheduler that uses historical resource usage by queues for making allocation and reclaim decisions.
- Historical Usage Consideration: All else being equal, queues with higher past usage will get to run jobs after queues with lower usage.
- Usage-Based Reclaim: Queues that are starved over time will reclaim resources from queues that used a lot of resources.
Note: This does not affect in-quota allocation—deserved quota still takes precedence over time-based fairshare.
Resource usage data is collected and persisted in Prometheus. The scheduler uses this data to make resource fairness calculations: the more resources consumed by a queue, the less over-quota resources it will receive compared to other queues.
If configured, the scheduler applies an exponential time decay formula controlled by a half-life period. For example, with a half-life of one hour, a GPU-second consumed an hour ago will be considered half as significant as a GPU-second consumed just now.
| File | Description |
|---|---|
| scheduling-shard-minimal.yaml | Minimal configuration to enable time-based fairshare |
| scheduling-shard-managed-prometheus.yaml | Full configuration using KAI-managed Prometheus |
| scheduling-shard-external-prometheus.yaml | Configuration for using an external Prometheus instance |
| two-queue-oscillation/ | Complete example demonstrating fair resource oscillation between two queues |
Note: If you already have Prometheus and kube-state-metrics installed, skip to Step 1.
If you don't already have Prometheus installed in your cluster, you can install it using the kube-prometheus-stack Helm chart. This chart includes the Prometheus Operator and kube-state-metrics.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack \
--namespace monitoring \
--create-namespace Wait for the pods to be ready:
kubectl wait --for=condition=Ready pods --all -n monitoring --timeout=300sFirst, enable Prometheus via the KAI operator:
kubectl patch config kai-config --type merge -p '{"spec":{"prometheus":{"enabled":true}}}'Wait for the Prometheus pod to be ready:
watch kubectl get pod -n kai-scheduler prometheus-prometheus-0Apply the minimal scheduling shard configuration:
kubectl apply -f scheduling-shard-minimal.yamlOr patch the existing shard:
kubectl patch schedulingshard default --type merge -p '{"spec":{"usageDBConfig":{"clientType":"prometheus"}}}'The scheduler will restart and connect to Prometheus.
| Parameter | Default | Description |
|---|---|---|
windowSize |
1w (1 week) |
Time period considered for fairness calculations |
windowType |
sliding |
Window type: sliding, tumbling, or cron |
halfLifePeriod |
disabled | Half-life for exponential decay (e.g., 10m, 1h) |
fetchInterval |
1m |
How often to fetch usage data from Prometheus |
stalenessPeriod |
5m |
Maximum age of usage data before considered stale |
The kValue parameter controls the impact of historical usage on fairness calculations:
- Higher values = more aggressive correction based on historical usage
- Lower values = more weight on over-quota weights, less on history
- Default:
1.0
- Sliding: Considers usage from the last
windowSizeduration (rolling window) - Tumbling: Non-overlapping fixed windows that reset at
tumblingWindowStartTime - Cron: Windows defined by a cron expression
If you have an existing Prometheus instance, configure it in the KAI config:
kubectl patch config kai-config --type merge -p '{
"spec": {
"prometheus": {
"enabled": true,
"externalPrometheusUrl": "http://prometheus.monitoring.svc.cluster.local:9090"
}
}
}'See scheduling-shard-external-prometheus.yaml for a complete example.
Ensure the Prometheus Operator is installed:
kubectl get crd prometheuses.monitoring.coreos.comFor cluster capacity metrics, kube-state-metrics must also be installed.
If the scheduler cannot fetch usage metrics:
kubectl logs -n kai-scheduler deployment/kai-scheduler-default | grep -i usageCheck if the scheduler can reach Prometheus:
kubectl exec -n kai-scheduler deployment/kai-scheduler-default -- wget -q -O- http://prometheus-operated.kai-scheduler.svc.cluster.local:9090/api/v1/status/config