Skip to content

Commit

Permalink
client: add trace to distinguish tso_wait and tso_rpc latency (tikv#6856
Browse files Browse the repository at this point in the history
)

close tikv#4399

Signed-off-by: tiancaiamao <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
tiancaiamao and ti-chi-bot[bot] authored Aug 1, 2023
1 parent 7cab1e9 commit 0c537bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math/rand"
"runtime/trace"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -823,6 +824,7 @@ func (c *client) GetTSAsync(ctx context.Context) TSFuture {
}

func (c *client) GetLocalTSAsync(ctx context.Context, dcLocation string) TSFuture {
defer trace.StartRegion(ctx, "GetLocalTSAsync").End()
if span := opentracing.SpanFromContext(ctx); span != nil {
span = opentracing.StartSpan("GetLocalTSAsync", opentracing.ChildOf(span.Context()))
ctx = opentracing.ContextWithSpan(ctx, span)
Expand Down
8 changes: 8 additions & 0 deletions client/tso_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math/rand"
"runtime/trace"
"sync"
"time"

Expand Down Expand Up @@ -79,6 +80,8 @@ func (c *tsoClient) dispatchRequest(dcLocation string, request *tsoRequest) erro
c.svcDiscovery.ScheduleCheckMemberChanged()
return err
}

defer trace.StartRegion(request.requestCtx, "tsoReqEnqueue").End()
dispatcher.(*tsoDispatcher).tsoBatchController.tsoRequestCh <- request
return nil
}
Expand All @@ -96,6 +99,7 @@ func (req *tsoRequest) Wait() (physical int64, logical int64, err error) {
cmdDurationTSOAsyncWait.Observe(start.Sub(req.start).Seconds())
select {
case err = <-req.done:
defer trace.StartRegion(req.requestCtx, "tsoReqDone").End()
err = errors.WithStack(err)
defer tsoReqPool.Put(req)
if err != nil {
Expand Down Expand Up @@ -741,6 +745,9 @@ func (c *tsoClient) processRequests(
}

requests := tbc.getCollectedRequests()
for _, req := range requests {
defer trace.StartRegion(req.requestCtx, "tsoReqSend").End()
}
count := int64(len(requests))
reqKeyspaceGroupID := c.svcDiscovery.GetKeyspaceGroupID()
respKeyspaceGroupID, physical, logical, suffixBits, err := stream.processRequests(
Expand Down Expand Up @@ -830,6 +837,7 @@ func (c *tsoClient) finishRequest(requests []*tsoRequest, physical, firstLogical
span.Finish()
}
requests[i].physical, requests[i].logical = physical, tsoutil.AddLogical(firstLogical, int64(i), suffixBits)
defer trace.StartRegion(requests[i].requestCtx, "tsoReqDequeue").End()
requests[i].done <- err
}
}

0 comments on commit 0c537bb

Please sign in to comment.