Skip to content
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

The metric tidb_tikvclient_batch_recv_latency is not reasonable #539

Open
you06 opened this issue Jul 5, 2022 · 1 comment
Open

The metric tidb_tikvclient_batch_recv_latency is not reasonable #539

you06 opened this issue Jul 5, 2022 · 1 comment

Comments

@you06
Copy link
Contributor

you06 commented Jul 5, 2022

Found by @zyguan

Start a cluster and wait a while, then run some workload, we got "Batch Receive Average Duration" panel like this.

image

The way we observe the receiving time is not reasonable. In an idle cluster, this function is waiting for responses a long time while there are no in-fly requests, so the receiving time is high. In a busy cluster, the responses are pending in the client's buffer and we just loop reading them from memory, so the receiving time is extremely low(avg 547us).

func (s *batchCommandsStream) recv() (resp *tikvpb.BatchCommandsResponse, err error) {
now := time.Now()
defer func() {
if r := recover(); r != nil {
metrics.TiKVPanicCounter.WithLabelValues(metrics.LabelBatchRecvLoop).Inc()
logutil.BgLogger().Error("batchCommandsClient.recv panic",
zap.Reflect("r", r),
zap.Stack("stack"))
err = errors.New("batch conn recv paniced")
}
if err == nil {
metrics.BatchRecvHistogramOK.Observe(float64(time.Since(now)))
} else {
metrics.BatchRecvHistogramError.Observe(float64(time.Since(now)))
}
}()
if _, err := util.EvalFailpoint("gotErrorInRecvLoop"); err == nil {
return nil, errors.New("injected error in batchRecvLoop")
}
// When `conn.Close()` is called, `client.Recv()` will return an error.
resp, err = s.Recv()
return
}

@disksing
Copy link
Collaborator

maybe change it to another title? such as 'Batch Wait for response duration'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants