Skip to content

Weighted laning: configurable per-threshold weights#19665

Open
mshahid6 wants to merge 1 commit into
apache:masterfrom
mshahid6:weighted-laning-threshold-costs
Open

Weighted laning: configurable per-threshold weights#19665
mshahid6 wants to merge 1 commit into
apache:masterfrom
mshahid6:weighted-laning-threshold-costs

Conversation

@mshahid6

@mshahid6 mshahid6 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Follow-up to the weighted query laning strategy (#19225).

Configurable per-threshold weights (WeightedQueryLaningStrategy)

Previously every breached threshold added exactly 1 to a query's cost. This adds optional per-threshold weights so a breach on one dimension can count for more than another (e.g. a huge segment scan should outweigh a slightly-old interval). Each weight defaults to 1, so existing configs are unchanged.

New optional properties (each an integer >= 1, default 1): periodWeight, durationWeight, segmentCountWeight, segmentRangeWeight.

a weight must be >= 1 and its corresponding threshold must be configured

Example. A segment-count breach counts double, so a query breaching only segmentCount still reaches a cost-2 lane:

{
  "strategy": "weighted",
  "segmentCountThreshold": 1000,
  "durationThreshold": "P1D",
  "segmentCountWeight": 2,
  "lanes": {
    "low":      { "minCost": 1, "maxPercent": 30 },
    "very-low": { "minCost": 2, "maxPercent": 10 }
  }
}

id dimension on the query/priority metric (QueryScheduler)

Also adds the query id dimension for easily finding a query's priority.

Key changed classes

  • WeightedQueryLaningStrategy — optional per-threshold weight fields + validation
  • QuerySchedulerid dimension on the query/priority metric

Release note

The weighted query laning strategy now supports optional per-threshold cost weights (periodWeight, durationWeight, segmentCountWeight, segmentRangeWeight; default 1), and the query/priority metric now includes a id dimension.

This PR has:

  • been self-reviewed.
  • using the concurrency checklist (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
  • 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 is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1

Reviewed 4 of 4 changed files.

Found 1 weighted-laning cost calculation issue.


This is an automated review by Codex GPT-5.5


if (durationThreshold != null && query.getDuration().isLongerThan(durationThreshold)) {
cost++;
cost += weightOrDefault(durationWeight);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Prevent weighted cost overflow from bypassing lanes

The new weight fields are only validated as >= 1, but computeCost accumulates them in an int. A valid config such as durationWeight=1 and segmentCountWeight=Integer.MAX_VALUE overflows when both thresholds are breached; the wrapped negative cost does not satisfy any positive lane minCost, so the query falls back to the default pool instead of being throttled. Please accumulate in long or checked arithmetic, or reject configs whose maximum possible cost exceeds Integer.MAX_VALUE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants