Skip to content

admission: integrate SQL work to CPU Time Token AC #166749

@wenyihu6

Description

@wenyihu6

Problem

When CTT (CPU Time Token) admission control is enabled, KV work is properly routed to the CTT WorkQueue via CPUGrantCoordinators.GetKVWorkQueue. However, SQL CPU admission is completely bypassed since serverless runs multi-process (kv pods do not need sql cpu admission). For resource manager work, they cannot be bypassed. The old slot-based system will not work here. It continues running for SQL work - SQLKVResponseAdmissionQ and sqlSQLResponseAdmissionQ still use tokenGranter with grant chains, and the old GrantCoordinator continues its CPULoad callback even though KV work is no longer
flowing through it.

Why the old system already has problems

The slot-based system uses three WorkKind queues with a hard-wired priority ordering (KVWork > SQLKVResponseWork > SQLSQLResponseWork) connected via grant chains. This has three drawbacks:

  1. Priority inversion. Lower-importance KVWork (e.g., background ops) is always served before user-facing SQLKVResponseWork. See admission: priority inversion caused by SQLKVResponseWork and SQLSQLResponseWork #85471.
  2. Complexity. Grant chains are subtle. The tokenGranter for SQL response work uses cpuOverloadIndicator (backed by kvSlotAdjuster) as an additional gate, linking SQL admission to KV slot availability in a non-obvious way.
  3. Indirect control. SQL CPU is only throttled indirectly by gating KV/DistSQL response processing, rather than directly measuring and controlling SQL CPU consumption.

Proposal

  • Integrate SQL CPU admission into the CTT system so that when CTT is enabled, SQL CPU consumption is admitted through the same CPU time token budget as KV work.
  • This uses the SQLCPUHandle/SQLCPUProvider infrastructure (sql_cpu_handle.go), which tracks per-goroutine CPU time via grunning.Time(). GoroutineCPUHandle.MeasureAndAdmit is called at regular intervals during SQL execution and, when CTT is enabled, blocks to acquire CPU time tokens from the CTT WorkQueue.

Jira issue: CRDB-62076

Epic CRDB-59016

Metadata

Metadata

Assignees

Labels

A-admission-controlC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-admission-controlAdmission Control

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions