Skip to content

resourcecontrol: add PredictedReadBytes hint to RequestInfo#1944

Draft
YuhaoZhang00 wants to merge 4 commits intotikv:masterfrom
YuhaoZhang00:demo/ema-precharge
Draft

resourcecontrol: add PredictedReadBytes hint to RequestInfo#1944
YuhaoZhang00 wants to merge 4 commits intotikv:masterfrom
YuhaoZhang00:demo/ema-precharge

Conversation

@YuhaoZhang00
Copy link
Copy Markdown

Summary

Add a client-go-internal PredictedReadBytes field on tikvrpc.Request so
the caller (e.g. TiDB, maintaining a per-logical-scan EMA across paging cop
RPCs) can supply a learned estimate of how many bytes the request will
read. MakeRequestInfo propagates this into RequestInfo, and the new
RequestInfo.PredictedReadBytes() getter satisfies the optional
predictedReadBytesProvider interface that PD's resource_group/controller
checks via type assertion.

The field is kept out of kvproto because it is purely a client-side
estimate consumed before the RPC is sent — TiKV neither needs nor reads it.

Why

This hint lets PD replace the current fixed 4 MiB paging pre-charge with a
learned estimate, without changing kvproto or TiKV behavior. See the PD
companion PR for the consumer-side logic.

Status

Draft. Part of a stacked change:

  • tikv/pd #10599: consumes the hint in BeforeKVRequest / AfterKVRequest
  • pingcap/tidb: produces the hint from a per-scan TAEMA maintained on copTask

Not yet ready for review; e2e validation on the simulation cluster is pending.

Test plan

  • Unit test internal/resourcecontrol/resource_control_test.go
  • e2e via simulation cluster (pending)

JmPotato and others added 4 commits April 2, 2026 11:02
Extract PagingSizeBytes from coprocessor requests and expose it via the
RequestInfo interface. This enables the PD resource controller to
pre-charge byte-budget RU in Phase 1 for RC paging.

Also adds RU v2 TiKV-side weight calculation, TiFlash RU tracking,
stale bucket metrics, and region cache improvements.

Signed-off-by: JmPotato <github@ipotato.me>
Signed-off-by: JmPotato <github@ipotato.me>
Signed-off-by: JmPotato <github@ipotato.me>
Add a client-go-internal PredictedReadBytes field on tikvrpc.Request so
the caller (e.g. TiDB, maintaining a per-logical-scan EMA across paging
cop RPCs) can supply a learned estimate of how many bytes the request
will read. MakeRequestInfo propagates this into RequestInfo, and the new
RequestInfo.PredictedReadBytes() getter satisfies the optional
predictedReadBytesProvider interface that PD's resource_group/controller
checks via type assertion.

When the hint is > 0, PD uses it as the byte basis for RC paging
pre-charge, overriding PagingSizeBytes (which remains the worst-case cap
and the fallback for cold-start / unset hint cases).

The field is kept out of the proto because it is purely a client-side
estimate consumed before the RPC is sent - TiKV neither needs nor reads
it.

Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has signed the dco. labels Apr 14, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Apr 14, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign pingyu for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e8a61151-ea9d-475b-a096-51b0874887b3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ti-chi-bot ti-chi-bot bot added contribution This PR is from a community contributor. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants