Fly-Style opened a new pull request, #18819:
URL: https://github.com/apache/druid/pull/18819
# Cost-Based Autoscaler for Seekable Stream Supervisors
## Overview
Implements a cost-based autoscaling algorithm for seekable stream supervisor
tasks that optimizes task count by balancing lag reduction against resource
efficiency.
## Algorithm Design
### Cost Function
The autoscaler uses a weighted cost function to evaluate different task
count configurations:
```
cost = lagWeight × normalizedLag + idleWeight × predictedIdleRatio
```
**Components of cost function:**
- **Lag component**: Measures how quickly the system processes "backlog"
- **Idle component**: Measures resource efficiency (tasks waiting for data
or busy)
### Key Features
**1. Predictive Cost Calculation**
- Predicts lag and idle ratio for candidate task counts using linear scaling
- Evaluates multiple task count options within ±2 positions of current count
- Selects configuration with minimum cost
- Tracks historical observed lag values, provides stable normalization even
with varying lag magnitudes
**2. Lag-Aware Idle Estimation**
- **High lag (>2M)**: Inverse relationship - more tasks = less idle
(processing backlog)
- **Low lag (<2M)**: Normal relationship - more tasks = more idle (waiting
for data)
##### Key files Changed
**Core Implementation:**
- `WeightedCostFunction.java` - Cost function and adaptive bounds
- `CostBasedAutoScaler.java` - Autoscaler orchestration
- `CostMetrics.java` - Metrics data class
**Tests:**
- `WeightedCostFunctionTest.java` - Comprehensive unit tests
- `CostBasedAutoScalerTest.java` - Integration tests
<hr>
This PR has:
- [ ] been self-reviewed.
- [ ] using the [concurrency
checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md)
(Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked
related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in
[licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code
wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths,
ensuring the threshold for [code
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]