-
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
tikv: log slow coprocessor task in detail #6344
Changes from 2 commits
ccb19e8
7242695
247010b
b17e451
376357a
9774a6d
0ef4180
df0f5a3
b0203b1
c6cc7d8
96e22f2
f9829fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -611,14 +611,14 @@ func (worker *copIteratorWorker) handleTaskOnce(bo *Backoffer, task *copTask, ch | |
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
// Set task.storeAddr field so its task.String() method have the store address information. | ||
task.storeAddr = sender.storeAddr | ||
costTime := time.Since(startTime) | ||
if costTime > minLogCopTaskTime { | ||
log.Infof("[TIME_COP_TASK] %s%s %s", costTime, bo, task) | ||
worker.logTimeCopTask(costTime, task, bo, resp) | ||
} | ||
metrics.TiKVCoprocessorCounter.WithLabelValues("handle_task").Inc() | ||
metrics.TiKVCoprocessorHistogram.Observe(costTime.Seconds()) | ||
// Set task.storeAddr field so its task.String() method have the store address information. | ||
task.storeAddr = sender.storeAddr | ||
|
||
if task.cmdType == tikvrpc.CmdCopStream { | ||
return worker.handleCopStreamResult(bo, resp.CopStream, task, ch) | ||
|
@@ -628,6 +628,57 @@ func (worker *copIteratorWorker) handleTaskOnce(bo *Backoffer, task *copTask, ch | |
return worker.handleCopResponse(bo, resp.Cop, task, ch, nil) | ||
} | ||
|
||
const ( | ||
minLogBackoffTime = 100 | ||
minLogKVProcessTime = 100 | ||
minLogKVWaitTime = 200 | ||
minLogScanProcessedInfo = 100000 | ||
minLogScanTotalInfo = 200000 | ||
) | ||
|
||
func (worker *copIteratorWorker) logTimeCopTask(costTime time.Duration, task *copTask, bo *Backoffer, resp *tikvrpc.Response) { | ||
logStr := fmt.Sprintf("[TIME_COP_TASK] cop_resp_time:%s, cop_start_ts:%d, cop_region_id:%d, cop_store_addr:%s", costTime, worker.req.StartTs, task.region.id, task.storeAddr) | ||
if bo.totalSleep > minLogBackoffTime { | ||
logStr += fmt.Sprintf(", cop_backoff_ms:%d", bo.totalSleep) | ||
} | ||
var detail *kvrpcpb.ExecDetails | ||
if task.cmdType == tikvrpc.CmdCopStream { | ||
detail = resp.CopStream.ExecDetails | ||
} else { | ||
detail = resp.Cop.ExecDetails | ||
} | ||
if detail != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are so many There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think defer is used for release resource. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with Yuxing. |
||
if detail.HandleTime != nil { | ||
processMs := detail.HandleTime.ProcessMs | ||
waitMs := detail.HandleTime.WaitMs | ||
if processMs > minLogKVProcessTime { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AndreMouche Does coprocessor also has a threshold to fill There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. YES There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coocood Maybe we just need to print There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After we set the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When will we set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ScanDetail is not set to true now. it's set only when the duration exceeds the threshold(1s) in TiKV. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think we should remove these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TiDB should control what to log, without depending on TiKV's implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zz-jason If we log everything, the most important ones will be obscure. |
||
logStr += fmt.Sprintf(", cop_kv_process_ms:%d", processMs) | ||
} | ||
if waitMs > minLogKVWaitTime { | ||
logStr += fmt.Sprintf(", cop_kv_wait_ms:%d", waitMs) | ||
} | ||
} | ||
if detail.ScanDetail != nil { | ||
logStr = appendScanDetail(logStr, "write", detail.ScanDetail.Write) | ||
logStr = appendScanDetail(logStr, "data", detail.ScanDetail.Data) | ||
logStr = appendScanDetail(logStr, "lock", detail.ScanDetail.Lock) | ||
} | ||
} | ||
log.Info(logStr) | ||
} | ||
|
||
func appendScanDetail(logStr string, columnFamily string, scanInfo *kvrpcpb.ScanInfo) string { | ||
if scanInfo != nil { | ||
if scanInfo.Total > minLogScanTotalInfo { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we need to check this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should not log messages that is not interesting. |
||
logStr += fmt.Sprintf(", cop_scan_total_%s:%d", columnFamily, scanInfo.Total) | ||
} | ||
if scanInfo.Processed > minLogScanProcessedInfo { | ||
logStr += fmt.Sprintf(", cop_scan_processed_%s:%d", columnFamily, scanInfo.Processed) | ||
} | ||
} | ||
return logStr | ||
} | ||
|
||
func (worker *copIteratorWorker) handleCopStreamResult(bo *Backoffer, stream *tikvrpc.CopStreamResponse, task *copTask, ch chan<- copResponse) ([]*copTask, error) { | ||
defer stream.Close() | ||
var resp *coprocessor.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.
Add time unit for the cop_resp_time.
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.
It's
time.Duration
type, which unit is included.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.
s/cop_start_ts/txnID/ ?
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.
I think we don't need to print the 'cop_' prefix