[WIP] Optimize K8s Operator LLAP scaling - #6723
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Hive Kubernetes Operator autoscaling model and LLAP scaling logic to better distinguish scale-up vs scale-down signals, using additional TezAM/LLAP metrics and a new scaleDownThreshold configuration surfaced through the CRD and Helm chart.
Changes:
- Introduces
scaleDownThresholdtoAutoscalingSpec, wires it through CRD + Helm templates/values, and updates component default specs accordingly. - Extends JMX exporter configuration to expose new LLAP/TezAM metrics used for scaling decisions.
- Refactors LLAP scaling strategy to use TezAM pending-task load + LLAP capacity/load signals, and adds a TezAM-metrics cache accessor to the autoscaler.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/util/HiveConfigBuilder.java | Adjusts Tez config when LLAP autoscaling is enabled (locality delay override behavior). |
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/util/ConfigUtils.java | Adds config key constant for LLAP task scheduler locality delay. |
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/model/spec/TezAmSpec.java | Updates default AutoscalingSpec construction to include the new field. |
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/model/spec/MetastoreSpec.java | Updates default AutoscalingSpec construction to include the new field. |
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/model/spec/LlapSpec.java | Updates LLAP + LLAP TezAM autoscaling defaults (including scale-down threshold for LLAP). |
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/model/spec/HiveServer2Spec.java | Updates default AutoscalingSpec construction to include the new field. |
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/model/spec/AutoscalingSpec.java | Adds scaleDownThreshold with schema/docs and defaulting in the compact constructor. |
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/dependent/HiveDependentResource.java | Exposes additional LLAP + TezAM metrics via JMX exporter config for autoscaling. |
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/autoscaling/LlapScalingStrategy.java | Reworks LLAP desired-replica computation using Tez pending tasks and LLAP capacity/load signals. |
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/autoscaling/HiveClusterAutoscaler.java | Adds cached TezAM-metrics accessor used by LLAP scaling strategy. |
| packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/autoscaling/ComponentAutoscaler.java | Modifies stabilization-window selection logic for LLAP scale-up decisions. |
| packaging/src/kubernetes/helm/hive-operator/values.yaml | Updates LLAP autoscaling defaults (including new scale-down threshold). |
| packaging/src/kubernetes/helm/hive-operator/templates/hivecluster.yaml | Emits scaleDownThreshold into rendered HiveCluster spec. |
| packaging/src/kubernetes/helm/hive-operator/crds/hiveclusters.hive.apache.org-v1.yml | Adds scaleDownThreshold to the CRD schema and updates scaleUpThreshold description text. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if (component.startsWith(ConfigUtils.COMPONENT_LLAP + "-")) { | ||
| // HS2 sessions activation gate scales up the LLAP pods to atleast 1 | ||
| // in presence of sessions. Avoid stabilizedMin in this start-up case. | ||
| target = currentReplicas == 0 ? clamped : scaleUpWindow.stabilizedMin(); |
There was a problem hiding this comment.
Llap scale-up has been intentionally changed to use StabilizedMin to prevent over scaling in case of momentary reducer burst.
| double queued = pm.metrics().getOrDefault(METRIC_QUEUED, 0.0); | ||
| double configured = pm.metrics().getOrDefault(METRIC_CONFIGURED, 0.0); | ||
| double available = pm.metrics().getOrDefault(METRIC_AVAILABLE, 0.0); | ||
| double busy = queued + configured - available; | ||
| totalBusy += busy; | ||
| podCount++; | ||
| totalLLAPCapacity += pm.metrics().getOrDefault(METRIC_MAX_FREE_SLOTS_CONFIGURED, 0.0); | ||
| totalLLAPLoad += queued + configured - available; |
| * desired = ceil(totalClusterLoad / capacityPerDaemon) | ||
| * <p> | ||
| * Activation gate: only scale if HS2 has open sessions (prevents zombie scaling). | ||
| * Activation gate: only scale if HS2 has open sessions & TezAMs are running DAGs (prevents zombie scaling). |
…nt & Update the ReadMe accordingly
|



What changes were proposed in this pull request?
Optimize the LLAP Scaling Strategy in K8s Operator to include Tez AM pending tasks Load
Why are the changes needed?
To enhance the LLAP Scaling Strategy
Does this PR introduce any user-facing change?
No
How was this patch tested?
Manual Testing

State on Cluster start-up:
State when sessions were opened, but no queries were triggered yet:

State upon increased load triggering LLAP scale-up:

State after queries completed & cool down period:
