Cache the default mdelem for client authority.

We create a mdelem based on the default authority value
for every call in `authority_start_transport_stream_op_batch()`.
Since the key and value are identical for all calls on channels of
a given process, they all map to the same shard of interned mdelem,
creating a signficant contention on the mutex of that shard.

This is observable in the profiles we have 1000s of connections
between two hosts, exchanging a high rate of RPCs.

Instead create the default mdelem and cache it in channel_data.
Simply ref this mdelem in `authority_start_transport_stream_op_batch()`.

This commit eliminates a signficant contention (2s in a 30s
profile) on client side.
pull/17776/head
Soheil Hassas Yeganeh 6 years ago
parent 3278bdceda
commit eb40dafe41
  1. 7
      src/core/ext/filters/http/client_authority_filter.cc

@ -45,6 +45,7 @@ struct call_data {
struct channel_data {
grpc_slice default_authority;
grpc_mdelem default_authority_mdelem;
};
void authority_start_transport_stream_op_batch(
@ -59,8 +60,7 @@ void authority_start_transport_stream_op_batch(
initial_metadata->idx.named.authority == nullptr) {
grpc_error* error = grpc_metadata_batch_add_head(
initial_metadata, &calld->authority_storage,
grpc_mdelem_create(GRPC_MDSTR_AUTHORITY, chand->default_authority,
nullptr));
GRPC_MDELEM_REF(chand->default_authority_mdelem));
if (error != GRPC_ERROR_NONE) {
grpc_transport_stream_op_batch_finish_with_failure(batch, error,
calld->call_combiner);
@ -103,6 +103,8 @@ grpc_error* init_channel_elem(grpc_channel_element* elem,
}
chand->default_authority =
grpc_slice_intern(grpc_slice_from_static_string(default_authority_str));
chand->default_authority_mdelem = grpc_mdelem_create(
GRPC_MDSTR_AUTHORITY, chand->default_authority, nullptr);
GPR_ASSERT(!args->is_last);
return GRPC_ERROR_NONE;
}
@ -111,6 +113,7 @@ grpc_error* init_channel_elem(grpc_channel_element* elem,
void destroy_channel_elem(grpc_channel_element* elem) {
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
grpc_slice_unref_internal(chand->default_authority);
GRPC_MDELEM_UNREF(chand->default_authority_mdelem);
}
} // namespace

Loading…
Cancel
Save