Skip to content

[hotfix][Optimizer] Cache group thread counts for quota sorting - #4323

Draft
czy006 wants to merge 2 commits into
apache:masterfrom
czy006:codex/hotfix-optimizer-thread-count-cache
Draft

[hotfix][Optimizer] Cache group thread counts for quota sorting#4323
czy006 wants to merge 2 commits into
apache:masterfrom
czy006:codex/hotfix-optimizer-thread-count-cache

Conversation

@czy006

@czy006 czy006 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Brief change log

Cache each optimizer group thread-count query for five seconds while calculating quota ordering. This avoids repeated external lookups without changing the refresh behavior after the cache interval.

How was this patch tested?

  • Add test coverage for the thread-count cache and its refresh behavior.
  • Add screenshots for manual tests if appropriate (not applicable: backend-only change).
  • Run TestDefaultTableRuntimeThreadCountCache locally with JDK 11 before creating this pull request.

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • no
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
  • not applicable

@github-actions github-actions Bot added the module:ams-server Ams server module label Aug 17, 2026
…s TTL)

getThreadCount() ran SELECT * FROM optimizer (including the mediumtext
properties column) on every calculateQuotaOccupy call. QuotaOccupySorter
invokes it for each pending table on every poll-driven sort, and all
tables of a queue share one group: N identical full-table scans per
sort, multiplied by optimizer poll frequency - the largest steady-state
DB load in the scheduler hot path.

Add a per-group cache with a 5s TTL (CAS-guarded expiry; races only
cause a rare extra query). Staleness is harmless for the heuristic
quota weighting since group thread counts only change on optimizer
register/unregister. No signature changes.

Regression test TestDefaultTableRuntimeThreadCountCache (red without
cache: second read immediately reflected the new optimizer).
Also documents the targetQuota=0 -> Infinity division surfaced while
testing (to be fixed at config parsing).
Fix record: docs/fix-records/2026-08-15-fix-10-quota-sorter-thread-count-cache.md
@czy006
czy006 force-pushed the codex/hotfix-optimizer-thread-count-cache branch from e7a92c5 to 4b0a451 Compare August 18, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:ams-server Ams server module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant