Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
136941: rpc: avoid allocation of `TracingInternalClient` when tracing disabled r=nvanbenschoten a=nvanbenschoten

Small performance improvement in the common case where tracing is disabled.

```
name                                            old time/op    new time/op    delta
Sysbench/SQL/1node_remote/oltp_read_only-30       6.84ms ± 2%    6.86ms ± 3%    ~     (p=0.912 n=10+10)
Sysbench/SQL/1node_remote/oltp_write_only-30      4.16ms ± 2%    4.17ms ± 2%    ~     (p=0.529 n=10+10)
Sysbench/SQL/1node_remote/oltp_read_write-30      11.2ms ± 2%    11.2ms ± 2%    ~     (p=0.912 n=10+10)
Sysbench/SQL/1node_remote/oltp_point_select-30     458µs ± 2%     459µs ± 3%    ~     (p=0.971 n=10+10)
Sysbench/SQL/3node/oltp_read_only-30              7.02ms ± 2%    7.06ms ± 2%    ~     (p=0.529 n=10+10)
Sysbench/SQL/3node/oltp_write_only-30             4.42ms ± 2%    4.41ms ± 2%    ~     (p=0.604 n=10+9)
Sysbench/SQL/3node/oltp_read_write-30             11.7ms ± 2%    11.7ms ± 2%    ~     (p=0.684 n=10+10)
Sysbench/SQL/3node/oltp_point_select-30            473µs ± 2%     474µs ± 2%    ~     (p=0.796 n=10+10)
Sysbench/KV/1node_remote/oltp_read_only-30        2.67ms ± 2%    2.68ms ± 2%    ~     (p=0.243 n=9+10)
Sysbench/KV/1node_remote/oltp_write_only-30       2.20ms ± 3%    2.19ms ± 2%    ~     (p=0.739 n=10+10)
Sysbench/KV/1node_remote/oltp_read_write-30       5.04ms ± 2%    5.05ms ± 2%    ~     (p=0.853 n=10+10)
Sysbench/KV/1node_remote/oltp_point_select-30      125µs ± 2%     125µs ± 1%    ~     (p=0.278 n=10+9)
Sysbench/KV/3node/oltp_read_only-30               2.79ms ± 2%    2.79ms ± 2%    ~     (p=0.579 n=10+10)
Sysbench/KV/3node/oltp_write_only-30              2.51ms ± 2%    2.50ms ± 1%    ~     (p=0.762 n=10+8)
Sysbench/KV/3node/oltp_read_write-30              5.57ms ± 2%    5.55ms ± 1%    ~     (p=0.968 n=10+9)
Sysbench/KV/3node/oltp_point_select-30             131µs ± 4%     132µs ± 3%    ~     (p=0.481 n=10+10)

name                                            old alloc/op   new alloc/op   delta
Sysbench/SQL/1node_remote/oltp_read_only-30       1.35MB ± 0%    1.35MB ± 0%    ~     (p=0.063 n=10+10)
Sysbench/SQL/1node_remote/oltp_write_only-30       670kB ± 0%     670kB ± 0%    ~     (p=0.739 n=10+10)
Sysbench/SQL/1node_remote/oltp_read_write-30      2.11MB ± 0%    2.11MB ± 0%    ~     (p=0.063 n=10+10)
Sysbench/SQL/1node_remote/oltp_point_select-30    42.2kB ± 0%    42.2kB ± 0%    ~     (p=0.540 n=10+10)
Sysbench/SQL/3node/oltp_read_only-30              1.42MB ± 4%    1.40MB ± 1%    ~     (p=0.965 n=10+8)
Sysbench/SQL/3node/oltp_write_only-30             1.15MB ± 3%    1.13MB ± 8%    ~     (p=0.165 n=10+10)
Sysbench/SQL/3node/oltp_read_write-30             2.77MB ± 1%    2.76MB ± 1%    ~     (p=0.190 n=10+10)
Sysbench/SQL/3node/oltp_point_select-30           44.9kB ± 1%    47.2kB ±12%    ~     (p=0.101 n=8+10)
Sysbench/KV/1node_remote/oltp_read_only-30         791kB ± 0%     790kB ± 0%    ~     (p=0.280 n=10+10)
Sysbench/KV/1node_remote/oltp_write_only-30        334kB ± 2%     334kB ± 2%    ~     (p=0.971 n=10+10)
Sysbench/KV/1node_remote/oltp_read_write-30       1.12MB ± 0%    1.12MB ± 0%    ~     (p=0.447 n=10+9)
Sysbench/KV/1node_remote/oltp_point_select-30     16.4kB ± 0%    16.4kB ± 0%    ~     (p=0.956 n=10+10)
Sysbench/KV/3node/oltp_read_only-30                808kB ± 1%     809kB ± 0%    ~     (p=0.211 n=10+9)
Sysbench/KV/3node/oltp_write_only-30               618kB ± 1%     621kB ± 1%    ~     (p=0.075 n=10+10)
Sysbench/KV/3node/oltp_read_write-30              1.45MB ± 1%    1.45MB ± 0%    ~     (p=0.315 n=10+8)
Sysbench/KV/3node/oltp_point_select-30            17.1kB ± 1%    17.0kB ± 1%    ~     (p=0.382 n=10+10)

name                                            old allocs/op  new allocs/op  delta
Sysbench/KV/1node_remote/oltp_point_select-30        211 ± 0%       210 ± 0%  -0.47%  (p=0.000 n=10+10)
Sysbench/KV/3node/oltp_point_select-30               213 ± 0%       212 ± 0%  -0.47%  (p=0.000 n=10+10)
Sysbench/SQL/3node/oltp_read_write-30              17.5k ± 1%     17.4k ± 1%  -0.46%  (p=0.029 n=10+10)
Sysbench/KV/1node_remote/oltp_read_only-30         3.99k ± 0%     3.97k ± 0%  -0.35%  (p=0.000 n=10+10)
Sysbench/KV/3node/oltp_read_only-30                4.02k ± 0%     4.01k ± 0%  -0.34%  (p=0.000 n=10+10)
Sysbench/KV/1node_remote/oltp_write_only-30        3.15k ± 0%     3.14k ± 0%  -0.32%  (p=0.000 n=10+10)
Sysbench/KV/3node/oltp_read_write-30               8.63k ± 0%     8.61k ± 0%  -0.31%  (p=0.000 n=10+9)
Sysbench/KV/1node_remote/oltp_read_write-30        7.20k ± 0%     7.18k ± 0%  -0.29%  (p=0.000 n=10+10)
Sysbench/SQL/1node_remote/oltp_read_only-30        7.70k ± 0%     7.67k ± 0%  -0.27%  (p=0.000 n=10+10)
Sysbench/SQL/3node/oltp_point_select-30              459 ± 0%       458 ± 0%  -0.27%  (p=0.013 n=9+9)
Sysbench/SQL/1node_remote/oltp_point_select-30       440 ± 0%       439 ± 0%  -0.23%  (p=0.000 n=10+9)
Sysbench/SQL/1node_remote/oltp_write_only-30       6.97k ± 0%     6.95k ± 0%  -0.20%  (p=0.000 n=10+9)
Sysbench/KV/3node/oltp_write_only-30               4.41k ± 0%     4.40k ± 0%  -0.18%  (p=0.000 n=9+10)
Sysbench/SQL/1node_remote/oltp_read_write-30       14.7k ± 0%     14.7k ± 0%  -0.16%  (p=0.002 n=10+9)
Sysbench/SQL/3node/oltp_read_only-30               7.96k ± 1%     7.98k ± 1%    ~     (p=0.618 n=9+10)
Sysbench/SQL/3node/oltp_write_only-30              9.32k ± 1%     9.24k ± 2%    ~     (p=0.211 n=9+10)
```

Epic: None
Release note: None

Co-authored-by: Nathan VanBenschoten <[email protected]>
  • Loading branch information
craig[bot] and nvanbenschoten committed Dec 10, 2024
2 parents 4c1602e + f1c04dd commit de3b122
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/rpc/nodedialer/nodedialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ func (n *Dialer) DialInternalClient(
if err != nil {
return nil, err
}
return TracingInternalClient{InternalClient: kvpb.NewInternalClient(conn)}, nil
client := kvpb.NewInternalClient(conn)
client = maybeWrapInTracingClient(ctx, client)
return client, nil
}

// dial performs the dialing of the remote connection. If checkBreaker
Expand Down Expand Up @@ -282,8 +284,16 @@ type TracingInternalClient struct {
kvpb.InternalClient
}

func maybeWrapInTracingClient(ctx context.Context, client kvpb.InternalClient) kvpb.InternalClient {
sp := tracing.SpanFromContext(ctx)
if sp != nil && !sp.IsNoop() {
client = &TracingInternalClient{InternalClient: client}
}
return client
}

// Batch overrides the Batch RPC client method and fills in tracing information.
func (tic TracingInternalClient) Batch(
func (tic *TracingInternalClient) Batch(
ctx context.Context, ba *kvpb.BatchRequest, opts ...grpc.CallOption,
) (*kvpb.BatchResponse, error) {
sp := tracing.SpanFromContext(ctx)
Expand Down

0 comments on commit de3b122

Please sign in to comment.