[release-nextgen-202603] client/resource_group: add client-side demand observability#10866
Conversation
Backport PR tikv#10604 to release-nextgen-202603. Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Hi @YuhaoZhang00. Thanks for your PR. I'm waiting for a tikv member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
| logControllerTrace("[resource group controller] update run state", zap.String("name", gc.name), zap.Any("request-unit-consumption", gc.run.consumption), zap.Bool("is-throttled", gc.isThrottled.Load())) | ||
| gc.run.now = newTime | ||
|
|
||
| gc.observeComponentConsumption(&trickleDelta) |
There was a problem hiding this comment.
This records the SQL CPU metric from the zeroed consumption baseline, so the first sample in single-group-by-keyspace mode includes all process CPU since startup. Can we subtract the initial SqlLayerCpuTimeMs baseline before observing this metric?
| gc.mu.Lock() | ||
| add(gc.mu.consumption, consumption) | ||
| gc.mu.Unlock() | ||
| gc.observeComponentConsumption(consumption) |
There was a problem hiding this comment.
ReportConsumption can include RRU/WRU, for example TiFlash MPP cost, but this path only records component metrics. Please also call observeConsumption here so consume_by_type does not undercount direct reports.
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
| requestSubsystem = "request" | ||
| tokenRequestSubsystem = "token_request" | ||
| resourceGroupSubsystem = "resource_group" | ||
| resourceUnitSubsystem = "resource_unit" |
There was a problem hiding this comment.
This constant is unused. Please remove it or wire it into a metric; otherwise staticcheck may fail with U1000.
| log.Warn("[resource group controller] waited for tokens", gc.logFields(waitDuration, nil)...) | ||
| } | ||
| } | ||
| gc.observeConsumption(delta) |
There was a problem hiding this comment.
This records write WRU/write bytes before the response is known. If the write later fails, the payback delta is negative but these counters cannot be decremented, so consume_by_type{type="wru"} and write_byte_sum can overcount failed writes. Can we observe actual charged consumption after the final response delta instead?
| counter.limiter.RemoveTokens(time.Now(), v) | ||
| } | ||
| } | ||
| gc.observeConsumption(delta) |
There was a problem hiding this comment.
This path observes response-side consumption, but demand_ru_per_sec is only updated inside acquireTokens. Callers using OnResponse will undercount read/CPU demand; can we sample demand here before removing tokens as well?
| } | ||
|
|
||
| func (gc *groupCostController) calcDemandAvg(counter *tokenCounter, delta float64) bool { | ||
| if delta <= 0 { |
There was a problem hiding this comment.
When traffic stops, this returns without updating the EMA, so the gauge can keep the last non-zero demand forever. Can the periodic state update refresh it with unchanged demandTotalRU so it decays toward zero?
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
| if v := getRUValueFromConsumption(delta); v > 0 { | ||
| gc.metrics.consumeTokenHistogram.Observe(v) | ||
| } | ||
| observeCounterDelta(gc.metrics.chargeTokenByTypeRRU, gc.metrics.refundTokenByTypeRRU, delta.RRU) |
There was a problem hiding this comment.
ReportConsumption can still pass a nil consumption here. The old add path ignored nil, but this now dereferences delta, so please guard observeConsumption with if delta == nil { return } like observeComponentConsumption.
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
|
/cc JMPotato |
| for _, calc := range gc.calculators { | ||
| calc.BeforeKVRequest(delta, info) | ||
| } | ||
| gc.observeDemand(delta) |
There was a problem hiding this comment.
This is on the per-request hot path before token acquisition. Since recordDemand takes avgMu for every request, can we verify the P99/P999 impact under a high-QPS single resource group, or consider sampling/aggregation if contention shows up?
There was a problem hiding this comment.
Moved demand accumulation off avgMu: the request path now uses a scaled atomic Add, while the periodic updater loads the accumulated demand and updates the EMA under avgMu.
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
| return | ||
| } | ||
| if v := getRUValueFromConsumption(delta); v > 0 { | ||
| gc.metrics.consumeTokenHistogram.Observe(v) |
There was a problem hiding this comment.
This histogram is updated on the client consumption hot path. Since histograms are heavier than counters/gauges, can we confirm the P99/P999 latency impact under high QPS, or consider sampling/periodic aggregation if the overhead is visible?
There was a problem hiding this comment.
Moved this histogram back under the original trace/debug gate (align with base behaviour). counters remain always collected
…ackport-10604-release-nextgen-202603
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## release-nextgen-202603 #10866 +/- ##
=========================================================
Coverage ? 78.99%
=========================================================
Files ? 531
Lines ? 71922
Branches ? 0
=========================================================
Hits ? 56815
Misses ? 11079
Partials ? 4028
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
Signed-off-by: Yuhao Zhang <yhzhang00@outlook.com>
|
/retest |
1 similar comment
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JmPotato, niubell, rleungx The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
491a11c
into
tikv:release-nextgen-202603
|
@YuhaoZhang00: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What problem does this PR solve?
Issue Number: ref #10488, ref #10581
Backport of #10604 to
release-nextgen-202603, plus some other metrics.Related dashboard PR: pingcap/tidb#69090
What is changed and how does it work?
This PR adds client-side Resource Control observability on the release-nextgen branch. The metrics are organized by the Resource Control diagnosis chain:
resource_manager_client_token_request_consumeRU Cost Distributionpanel.resource_manager_client_resource_group_consume_by_type{type="rru|wru", direction="charge|refund"}direction="refund"because Prometheus counters cannot decrease.RU Consumption By Typepanel shows net actual consumption asrate(charge) - rate(refund).resource_manager_client_resource_read_byte_sumresource_manager_client_resource_write_byte_sum{direction="charge|refund"}resource_manager_client_resource_kv_cpu_time_ms_sumresource_manager_client_resource_sql_cpu_time_ms_sumdirection="refund"onresource_manager_client_resource_write_byte_sum.Client Resource BytesandClient CPU Costpanels.resource_manager_client_resource_group_demand_ru_per_secOnRequestWait,OnResponse,OnResponseWait, andReportConsumption) rather than only fromacquireTokens, so burstable and response-side consumption paths are covered.RU Demand, Grant And Fill Ratepanel.resource_manager_client_resource_group_token_balanceresource_manager_client_resource_group_fill_rateresource_manager_client_resource_group_burst_limitresource_manager_client_resource_group_avg_ru_per_secresource_manager_client_resource_group_throttledRU Demand, Grant And Fill RateandToken Balance And Throttlepanels.resource_manager_client_resource_group_actual_grant_tokensRU Demand, Grant And Fill Ratepanel as a 1-minute actual grant rate curve.resource_manager_client_token_request_durationresource_manager_client_token_request_resource_groupresource_manager_client_token_request_low_token_notifiedclient_unique_id,resource_group,available_tokens,fill_rate,avg_ru_per_sec,demand_ru_per_sec,throttled, andwait_duration.Validation
make gotest GOTEST_ARGS='./resource_group/controller/... -count=1'fromclient/git diff --checkNotes
This PR provides the PD client metrics consumed by the appended Resource Control diagnosis panels in pingcap/tidb#69090.
This is intentionally draft. Additional release-nextgen-specific changes may be added before marking ready for review.
Release note