Skip to content

Commit

Permalink
metrics: improve handle cop task duration metric accuracy (pingcap#5925)
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood authored and jackysp committed Mar 7, 2018
1 parent 86af180 commit dca897d
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions store/tikv/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,7 @@ func (it *copIterator) work(ctx context.Context, taskCh <-chan *copTask) {
}

bo := NewBackoffer(ctx1, copNextMaxBackoff)
startTime := time.Now()
it.handleTask(bo, task, ch)
costTime := time.Since(startTime)
if costTime > minLogCopTaskTime {
log.Infof("[TIME_COP_TASK] %s%s %s", costTime, bo, task)
}
metrics.TiKVCoprocessorCounter.WithLabelValues("handle_task").Inc()
metrics.TiKVCoprocessorHistogram.Observe(costTime.Seconds())
if bo.totalSleep > 0 {
metrics.TiKVBackoffHistogram.Observe(float64(bo.totalSleep) / 1000)
}
Expand Down Expand Up @@ -598,10 +591,17 @@ func (it *copIterator) handleTaskOnce(bo *Backoffer, task *copTask, ch chan copR
// The resp is a stream and killed by cancel operation immediately.
timeout = 0
}
startTime := time.Now()
resp, err := sender.SendReq(bo, req, task.region, timeout)
if err != nil {
return nil, errors.Trace(err)
}
costTime := time.Since(startTime)
if costTime > minLogCopTaskTime {
log.Infof("[TIME_COP_TASK] %s%s %s", costTime, bo, task)
}
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

Expand All @@ -621,7 +621,6 @@ func (it *copIterator) handleCopStreamResult(bo *Backoffer, stream *tikvrpc.CopS
if err != nil || len(remainedTasks) != 0 {
return remainedTasks, errors.Trace(err)
}

resp, err = stream.Recv()
if err != nil {
if err == io.EOF {
Expand All @@ -641,7 +640,6 @@ func (it *copIterator) handleCopResponse(bo *Backoffer, resp *coprocessor.Respon
}
// We may meet RegionError at the first packet, but not during visiting the stream.
metrics.TiKVCoprocessorCounter.WithLabelValues("rebuild_task").Inc()

return buildCopTasks(bo, it.store.regionCache, task.ranges, it.req.Desc, it.req.Streaming)
}
if lockErr := resp.GetLocked(); lockErr != nil {
Expand Down

0 comments on commit dca897d

Please sign in to comment.