Skip to content

Commit

Permalink
store/tikv: tiny optimize when opentracing is not enabled (pingcap#6494)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and jackysp committed May 8, 2018
1 parent e6c720a commit 6c94805
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 11 additions & 5 deletions store/tikv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,21 @@ func (a *connArray) Init(addr string, security config.Security) error {
opt = grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))
}

for i := range a.v {
unaryInterceptor := grpc_middleware.ChainUnaryClient(
grpc_prometheus.UnaryClientInterceptor,
unaryInterceptor := grpc_prometheus.UnaryClientInterceptor
streamInterceptor := grpc_prometheus.StreamClientInterceptor
cfg := config.GetGlobalConfig()
if cfg.OpenTracing.Enable {
unaryInterceptor = grpc_middleware.ChainUnaryClient(
unaryInterceptor,
grpc_opentracing.UnaryClientInterceptor(),
)
streamInterceptor := grpc_middleware.ChainStreamClient(
grpc_prometheus.StreamClientInterceptor,
streamInterceptor = grpc_middleware.ChainStreamClient(
streamInterceptor,
grpc_opentracing.StreamClientInterceptor(),
)
}

for i := range a.v {

ctx, cancel := context.WithTimeout(context.Background(), dialTimeout)
conn, err := grpc.DialContext(
Expand Down
8 changes: 5 additions & 3 deletions store/tikv/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ const minLogCopTaskTime = 300 * time.Millisecond
// run is a worker function that get a copTask from channel, handle it and
// send the result back.
func (worker *copIteratorWorker) run(ctx context.Context) {
span, ctx1 := opentracing.StartSpanFromContext(ctx, "copIteratorWorker.run")
defer span.Finish()
if span := opentracing.SpanFromContext(ctx); span != nil {
span, ctx = opentracing.StartSpanFromContext(ctx, "copIteratorWorker.run")
defer span.Finish()
}

defer worker.wg.Done()
for task := range worker.taskCh {
Expand All @@ -404,7 +406,7 @@ func (worker *copIteratorWorker) run(ctx context.Context) {
respCh = task.respChan
}

bo := NewBackoffer(ctx1, copNextMaxBackoff).WithVars(worker.vars)
bo := NewBackoffer(ctx, copNextMaxBackoff).WithVars(worker.vars)
worker.handleTask(bo, task, respCh)
if bo.totalSleep > 0 {
metrics.TiKVBackoffHistogram.Observe(float64(bo.totalSleep) / 1000)
Expand Down

0 comments on commit 6c94805

Please sign in to comment.