-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
executor,metrics: add a metric for observing execution phases #35906
Conversation
Signed-off-by: zyguan <zhongyangguan@gmail.com>
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/1b25036ca36befb45e6588ee168b4cebefa10f4a |
Signed-off-by: zyguan <zhongyangguan@gmail.com>
Signed-off-by: zyguan <zhongyangguan@gmail.com>
Signed-off-by: zyguan <zhongyangguan@gmail.com>
Signed-off-by: zyguan <zhongyangguan@gmail.com>
executor/adapter.go
Outdated
func (a *ExecStmt) observePhaseDurations(internal bool, commitDetails *util.CommitDetails) { | ||
if d := a.phaseBuildDurations[0]; d > 0 { | ||
if internal { | ||
metrics.ExecPhaseDuration.WithLabelValues("build:final", "1").Observe(d.Seconds()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could abstract the label constants and pre-define the related metrics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
executor/adapter.go
Outdated
execBuildFinal = metrics.ExecPhaseDuration.WithLabelValues("build:final", "0") | ||
execOpenFinal = metrics.ExecPhaseDuration.WithLabelValues("open:final", "0") | ||
execNextFinal = metrics.ExecPhaseDuration.WithLabelValues("next:final", "0") | ||
execLockFinal = metrics.ExecPhaseDuration.WithLabelValues("lock:final", "0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the next
operation maybe we need to integrate more with the kv client metrics in the future.
Signed-off-by: zyguan <zhongyangguan@gmail.com>
Signed-off-by: zyguan <zhongyangguan@gmail.com>
@@ -724,6 +736,7 @@ func (a *ExecStmt) handlePessimisticDML(ctx context.Context, e Executor) error { | |||
ctx = context.WithValue(ctx, util.LockKeysDetailCtxKey, &lockKeyStats) | |||
startLocking := time.Now() | |||
err = txn.LockKeys(ctx, lockCtx, keys...) | |||
a.phaseLockDurations[0] += time.Since(startLocking) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point get and batch point get will lock keys internally, that duration will not be observed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, here the lock phase is only for pessimistic DMLs that have extra keys to lock. The internal lock key duration (of point-get, point-update, etc) is counted in next phase.
Signed-off-by: zyguan <zhongyangguan@gmail.com>
phaseBuildLocking = "build:locking" | ||
phaseOpenLocking = "open:locking" | ||
phaseNextLocking = "next:locking" | ||
phaseLockLocking = "lock:locking" | ||
phaseBuildFinal = "build:final" | ||
phaseOpenFinal = "open:final" | ||
phaseNextFinal = "next:final" | ||
phaseLockFinal = "lock:final" | ||
phaseCommitPrewrite = "commit:prewrite" | ||
phaseCommitCommit = "commit:commit" | ||
phaseCommitWaitCommitTS = "commit:wait:commit-ts" | ||
phaseCommitWaitLatestTS = "commit:wait:latest-ts" | ||
phaseCommitWaitLatch = "commit:wait:local-latch" | ||
phaseCommitWaitBinlog = "commit:wait:prewrite-binlog" | ||
phaseWriteResponse = "write-response" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cfzjywxk @you06 @sticnarf @longfangsong Any suggestion about naming? eg. build:locking
and locking:build
, which is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build:locking
IMO, it's better to put the related metrics together in the alphabetic order.
Seems the workload does not return much data to the client? |
@zyguan |
@@ -46,4 +46,13 @@ var ( | |||
Name: "statement_db_total", | |||
Help: "Counter of StmtNode by Database.", | |||
}, []string{LblDb, LblType}) | |||
|
|||
// ExecPhaseDuration records the duration of each execution phase. | |||
ExecPhaseDuration = prometheus.NewSummaryVec( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why summary is used here? I have never seen summary type metrics used in TiDB before and histogram is always used....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To reduce the size of metrics data (histogram = summary + buckets). IMO, we won't care too much about sth like "what's the p99 latency of next phase". There are too many kinds of executors (as well as their combinations), some may be fast and other may be extremely slow, a higher or lower p99 latency may not provide more info (we do not known about the distribution of each kind of executors). Besides, it's hard to decide buckets here, some phases (like open) take very little time, but phases like lock may cost a few seconds.
Yes, we need to figure out a way to show these durations in wall time, since kv client / executors may run concurrently. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: zyguan <zhongyangguan@gmail.com>
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 9e97b78
|
/run-all-tests |
TiDB MergeCI notify🔴 Bad News! New failing [1] after this pr merged.
|
…ip-init * upstream/master: (125 commits) infoschema: fix PromQL for `tidb_distsql_copr_cache` (pingcap#36450) test: stabilize TestTopSQLCPUProfile (pingcap#36468) parser: add support of 'ADMIN SHOW DDL JOB QUERIES LIMIT m OFFSET n' transferring to AST (pingcap#36285) *: enable flaky test for all test (pingcap#36385) expression: fix return type of agg func `bit_or` when handling varbinary column (pingcap#36415) executor: fix aggregating enum zero value gets different results from mysql (pingcap#36208) server: skip check tiflash version (pingcap#36451) *: Minor update to SECURITY.md to improved clarity (pingcap#36346) table partition: add telemetry for partition table (pingcap#36204) ddl: invalid multiple MAXVALUE partitions (pingcap#36329) (pingcap#36345) planner: Fixed `Merge` hint in nested CTE (pingcap#36432) metric: impove concurrency ddl metrics (pingcap#36405) planner: add more test cases for leading outer join (pingcap#36409) ddl: only set concurrent variable if no error (pingcap#36437) ddl: fix update panic in the middle of multi-schema change (pingcap#36421) session: Mising OptimizeWithPlanAndThenWarmUp in prepare-execute path (pingcap#36347) executor,metrics: add a metric for observing execution phases (pingcap#35906) br: unified docker image align with tidb (pingcap#36016) ddl: skip to close nil sessPool (pingcap#36425) log-backup: remove the timezone from log-date (pingcap#36369) ...
* upstream/master: (280 commits) infoschema: fix PromQL for `tidb_distsql_copr_cache` (pingcap#36450) test: stabilize TestTopSQLCPUProfile (pingcap#36468) parser: add support of 'ADMIN SHOW DDL JOB QUERIES LIMIT m OFFSET n' transferring to AST (pingcap#36285) *: enable flaky test for all test (pingcap#36385) expression: fix return type of agg func `bit_or` when handling varbinary column (pingcap#36415) executor: fix aggregating enum zero value gets different results from mysql (pingcap#36208) server: skip check tiflash version (pingcap#36451) *: Minor update to SECURITY.md to improved clarity (pingcap#36346) table partition: add telemetry for partition table (pingcap#36204) ddl: invalid multiple MAXVALUE partitions (pingcap#36329) (pingcap#36345) planner: Fixed `Merge` hint in nested CTE (pingcap#36432) metric: impove concurrency ddl metrics (pingcap#36405) planner: add more test cases for leading outer join (pingcap#36409) ddl: only set concurrent variable if no error (pingcap#36437) ddl: fix update panic in the middle of multi-schema change (pingcap#36421) session: Mising OptimizeWithPlanAndThenWarmUp in prepare-execute path (pingcap#36347) executor,metrics: add a metric for observing execution phases (pingcap#35906) br: unified docker image align with tidb (pingcap#36016) ddl: skip to close nil sessPool (pingcap#36425) log-backup: remove the timezone from log-date (pingcap#36369) ...
…rimary-key * upstream/master: (104 commits) br: fix compatibility issue with concurrent ddl (pingcap#36474) infoschema: fix PromQL for `tidb_distsql_copr_cache` (pingcap#36450) test: stabilize TestTopSQLCPUProfile (pingcap#36468) parser: add support of 'ADMIN SHOW DDL JOB QUERIES LIMIT m OFFSET n' transferring to AST (pingcap#36285) *: enable flaky test for all test (pingcap#36385) expression: fix return type of agg func `bit_or` when handling varbinary column (pingcap#36415) executor: fix aggregating enum zero value gets different results from mysql (pingcap#36208) server: skip check tiflash version (pingcap#36451) *: Minor update to SECURITY.md to improved clarity (pingcap#36346) table partition: add telemetry for partition table (pingcap#36204) ddl: invalid multiple MAXVALUE partitions (pingcap#36329) (pingcap#36345) planner: Fixed `Merge` hint in nested CTE (pingcap#36432) metric: impove concurrency ddl metrics (pingcap#36405) planner: add more test cases for leading outer join (pingcap#36409) ddl: only set concurrent variable if no error (pingcap#36437) ddl: fix update panic in the middle of multi-schema change (pingcap#36421) session: Mising OptimizeWithPlanAndThenWarmUp in prepare-execute path (pingcap#36347) executor,metrics: add a metric for observing execution phases (pingcap#35906) br: unified docker image align with tidb (pingcap#36016) ddl: skip to close nil sessPool (pingcap#36425) ...
…pingcap#35906)" This reverts commit 23f25af.
Signed-off-by: zyguan zhongyangguan@gmail.com
What problem does this PR solve?
Issue Number: ref #34106
Problem Summary:
The execution duraition is the main part of the database time, however it cannot be broken down (in wall time) by current metrics.
What is changed and how it works?
The execution process can be described as the following.
The main parts are
build
,open
,next
,lock
andcommit
and we may retrybuild -> open -> next [-> lock]
when a pessimistic lock error returned. Thus these phases (except forcommit
) can be further split into two parts:By observing durations of these phases, we can identify some typical issues easily, eg:
too much time spent on building executor (typically caused by waiting tso)

lock contention

Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.